aboutsummaryrefslogtreecommitdiff
path: root/TermIO/out/__init__.py
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2019-08-15 21:19:38 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2019-08-15 21:19:38 +0200
commite1cde9174a5ba42de8daccd7b74ea10093029220 (patch)
tree011046e4a766c7a5a13471788c7a5e6ebb03fbee /TermIO/out/__init__.py
parentd2379f3b162b598ec6fb0a0a2b995aa7dbf1f10c (diff)
downloadTermIO-python-package-e1cde9174a5ba42de8daccd7b74ea10093029220.tar.gz
TermIO-python-package-e1cde9174a5ba42de8daccd7b74ea10093029220.zip
:truck: Move package into folder
Diffstat (limited to 'TermIO/out/__init__.py')
-rw-r--r--TermIO/out/__init__.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/TermIO/out/__init__.py b/TermIO/out/__init__.py
new file mode 100644
index 0000000..1a69021
--- /dev/null
+++ b/TermIO/out/__init__.py
@@ -0,0 +1,64 @@
+import sys
+
+
+class Cursor():
+
+ def SetPos(col, row, flush=True):
+ sys.stdout.write(u"\u001b[{0};{1}H".format(int(row), int(col)))
+ if flush: sys.stdout.flush()
+
+ def Left(n, flush=True):
+ sys.stdout.write(u"\u001b[{0}D".format(str(n)))
+ if flush: sys.stdout.flush()
+
+ def Right(n, flush=True):
+ sys.stdout.write(u"\u001b[{0}C".format(str(n)))
+ if flush: sys.stdout.flush()
+
+ def Up(n, flush=True):
+ sys.stdout.write(u"\u001b[{0}A".format(str(n)))
+ if flush: sys.stdout.flush()
+
+ def Down(n, flush=True):
+ sys.stdout.write(u"\u001b[{0}B".format(str(n)))
+ if flush: sys.stdout.flush()
+
+
+class Screen():
+
+ def Clear(flush=True):
+ sys.stdout.write(u"\u001b[2J") # Clear screen
+ if flush: sys.stdout.flush()
+
+ def Flush():
+ sys.stdout.flush()
+
+ def Decorate(fg=None, bg=None, dec=None, flush=True):
+ if (fg is None) and (bg is None) and (dec is None):
+ sys.stdout.write(u"\u001b[0m")
+
+ if fg is not None:
+ sys.stdout.write(u"\u001b[38;5;{0}m".format(str(fg)))
+ if bg is not None:
+ sys.stdout.write(u"\u001b[48;5;{0}m".format(str(fg)))
+ if dec is not None:
+ if type(dec) == list:
+ for thing in dec:
+ if (thing == "reversed"): sys.stdout.write(u"\u001b[7m")
+ elif (thing == "underline"): sys.stdout.write(u"\u001b[4m")
+ elif (thing == "bold"): sys.stdout.write(u"\u001b[1m")
+ else:
+ raise ValueError('"{}" Not rekognized as a decoration'.format(thing))
+
+ elif type(dec) == str:
+ if (dec == "reversed"): sys.stdout.write(u"\u001b[7m")
+ elif (dec == "underline"): sys.stdout.write(u"\u001b[4m")
+ elif (dec == "bold"): sys.stdout.write(u"\u001b[1m")
+ else:
+ raise ValueError('"{}" Not rekognized as a decoration'.format(dec))
+
+ if flush: sys.stdout.flush()
+
+ def Write(outStr, flush=True):
+ sys.stdout.write(str(outStr))
+ if flush: sys.stdout.flush()