aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2019-08-15 15:07:24 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2019-08-15 15:07:24 +0200
commit4a6e117c9425b4b7ec0875b654c20ea92d3d7ce0 (patch)
tree078f52f42b70649c73e4d8b1a9ed2a54708be103
downloadTermIO-python-package-4a6e117c9425b4b7ec0875b654c20ea92d3d7ce0.tar.gz
TermIO-python-package-4a6e117c9425b4b7ec0875b654c20ea92d3d7ce0.zip
:sparkles: Initial commit
-rw-r--r--.gitignore2
-rw-r--r--KeyCodes.py0
-rw-r--r--README.md85
-rw-r--r--TermIO.egg-info/PKG-INFO98
-rw-r--r--TermIO.egg-info/SOURCES.txt8
-rw-r--r--TermIO.egg-info/dependency_links.txt1
-rw-r--r--TermIO.egg-info/top_level.txt2
-rw-r--r--__init__.py6
-rw-r--r--build/lib/in/__init__.py35
-rw-r--r--build/lib/out/__init__.py64
-rw-r--r--dist/TermIO-0.1-py2-none-any.whlbin0 -> 2925 bytes
-rw-r--r--in/__init__.py35
-rw-r--r--out/__init__.py64
-rw-r--r--setup.py23
14 files changed, 423 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..366c1e2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+__pycache__
+.pyc
diff --git a/KeyCodes.py b/KeyCodes.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/KeyCodes.py
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..bd3f051
--- /dev/null
+++ b/README.md
@@ -0,0 +1,85 @@
+# TermIO
+Simple library that makes it easier to manipulate the terminal using escape
+sequences.
+
+It does not work in all terminal and terminal-emulators. But i have generally
+had good with bash.
+
+```
+import TermIO
+```
+
+## var `TermIO.rows`
+Rows in the terminal. Not updating as of now...
+
+## var `TermIO.columns`
+Number of columns in the terminal. Not updating either...
+
+## func `TermIO.Cursor.SetPos(col, row, flush=True)`
+Set cursor to a spesific column and row in the terminal.
+```
+col : The column number to put the cursor.
+row : The row number to put the cursor.
+flush : Wether or not to flush the codes printed (Default is true).
+```
+
+## func `TermIO.Cursor.Left(n, flush=True)`
+Move the cursor `n` characters to the left.
+```
+n : number
+flush : Wether or not to flush the codes printed (Default is true).
+```
+
+## func `TermIO.Cursor.Right(n, flush=True)`
+Move the cursor `n` characters to the right.
+```
+n : number
+flush : Wether or not to flush the codes printed (Default is true).
+```
+
+## func `TermIO.Cursor.Up(n, flush=True)`
+Move the cursor `n` characters up.
+```
+n : number
+flush : Wether or not to flush the codes printed (Default is true).
+```
+
+## func `TermIO.Cursor.Down(n, flush=True)`
+Move the cursor `n` characters to the down.
+```
+n : number
+flush : Wether or not to flush the codes printed (Default is true).
+```
+
+## func `TermIO.Screen.Clear(flush=True)`
+Clear the screen.
+```
+flush : Wether or not to flush the codes printed (Default is true).
+```
+
+## func `TermIO.Screen.Flush()`
+Flushes printed content to screen.
+
+## func `TermIO.Screen.Decorate(fg=None, bg=None, dec=None, flush=True)`
+Clear the screen
+```
+fg : Number between 0 and 255. No logical color math... [None]
+bg : Number between 0 and 255. No logical color math... [None]
+dec : Either a string or a list of strings. [None]
+ The three possible decorations is
+ reversed, underline, bold
+ eg:
+ TermIO.Screen.Decorate(dec="reversed")
+ or
+ TermIO.Screen.Decorate(dec=["bold", "reversed"])
+flush : Wether or not to flush the codes printed. [True]
+```
+
+If you want to print `ESC[0M`, to remove all decorations. Just call this function with `fg=bg=dec=None`.
+
+## func `TermIO.Screen.Write(outStr, flush=True)`
+Writes a string to stdout.
+```
+outStr : string to be printed
+flush : Wether or not to flush the codes printed (Default is true).
+```
diff --git a/TermIO.egg-info/PKG-INFO b/TermIO.egg-info/PKG-INFO
new file mode 100644
index 0000000..d73af34
--- /dev/null
+++ b/TermIO.egg-info/PKG-INFO
@@ -0,0 +1,98 @@
+Metadata-Version: 2.1
+Name: TermIO
+Version: 0.1
+Summary: Simple terminal manipulator
+Home-page: https://github.com/jakobst1n/TermIO-python-package
+Author: jakobst1n
+Author-email: jakob.stendahl@outlook.com
+License: UNKNOWN
+Description: # TermIO
+ Simple library that makes it easier to manipulate the terminal using escape
+ sequences.
+
+ It does not work in all terminal and terminal-emulators. But i have generally
+ had good with bash.
+
+ ```
+ import TermIO
+ ```
+
+ ## var `TermIO.rows`
+ Rows in the terminal. Not updating as of now...
+
+ ## var `TermIO.columns`
+ Number of columns in the terminal. Not updating either...
+
+ ## func `TermIO.Cursor.SetPos(col, row, flush=True)`
+ Set cursor to a spesific column and row in the terminal.
+ ```
+ col : The column number to put the cursor.
+ row : The row number to put the cursor.
+ flush : Wether or not to flush the codes printed (Default is true).
+ ```
+
+ ## func `TermIO.Cursor.Left(n, flush=True)`
+ Move the cursor `n` characters to the left.
+ ```
+ n : number
+ flush : Wether or not to flush the codes printed (Default is true).
+ ```
+
+ ## func `TermIO.Cursor.Right(n, flush=True)`
+ Move the cursor `n` characters to the right.
+ ```
+ n : number
+ flush : Wether or not to flush the codes printed (Default is true).
+ ```
+
+ ## func `TermIO.Cursor.Up(n, flush=True)`
+ Move the cursor `n` characters up.
+ ```
+ n : number
+ flush : Wether or not to flush the codes printed (Default is true).
+ ```
+
+ ## func `TermIO.Cursor.Down(n, flush=True)`
+ Move the cursor `n` characters to the down.
+ ```
+ n : number
+ flush : Wether or not to flush the codes printed (Default is true).
+ ```
+
+ ## func `TermIO.Screen.Clear(flush=True)`
+ Clear the screen.
+ ```
+ flush : Wether or not to flush the codes printed (Default is true).
+ ```
+
+ ## func `TermIO.Screen.Flush()`
+ Flushes printed content to screen.
+
+ ## func `TermIO.Screen.Decorate(fg=None, bg=None, dec=None, flush=True)`
+ Clear the screen
+ ```
+ fg : Number between 0 and 255. No logical color math... [None]
+ bg : Number between 0 and 255. No logical color math... [None]
+ dec : Either a string or a list of strings. [None]
+ The three possible decorations is
+ reversed, underline, bold
+ eg:
+ TermIO.Screen.Decorate(dec="reversed")
+ or
+ TermIO.Screen.Decorate(dec=["bold", "reversed"])
+ flush : Wether or not to flush the codes printed. [True]
+ ```
+
+ If you want to print `ESC[0M`, to remove all decorations. Just call this function with `fg=bg=dec=None`.
+
+ ## func `TermIO.Screen.Write(outStr, flush=True)`
+ Writes a string to stdout.
+ ```
+ outStr : string to be printed
+ flush : Wether or not to flush the codes printed (Default is true).
+ ```
+
+Platform: UNKNOWN
+Classifier: Programming Language :: Python :: 3
+Classifier: Operating System :: OS Independent
+Description-Content-Type: text/markdown
diff --git a/TermIO.egg-info/SOURCES.txt b/TermIO.egg-info/SOURCES.txt
new file mode 100644
index 0000000..a943b20
--- /dev/null
+++ b/TermIO.egg-info/SOURCES.txt
@@ -0,0 +1,8 @@
+README.md
+setup.py
+TermIO.egg-info/PKG-INFO
+TermIO.egg-info/SOURCES.txt
+TermIO.egg-info/dependency_links.txt
+TermIO.egg-info/top_level.txt
+in/__init__.py
+out/__init__.py \ No newline at end of file
diff --git a/TermIO.egg-info/dependency_links.txt b/TermIO.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/TermIO.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/TermIO.egg-info/top_level.txt b/TermIO.egg-info/top_level.txt
new file mode 100644
index 0000000..932d770
--- /dev/null
+++ b/TermIO.egg-info/top_level.txt
@@ -0,0 +1,2 @@
+in
+out
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..e01228a
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,6 @@
+from .out import *
+
+import os
+
+
+rows, columns = map(int, os.popen('stty size', 'r').read().split())
diff --git a/build/lib/in/__init__.py b/build/lib/in/__init__.py
new file mode 100644
index 0000000..b886141
--- /dev/null
+++ b/build/lib/in/__init__.py
@@ -0,0 +1,35 @@
+class _Getch:
+ """Gets a single character from standard input. Does not echo to the
+screen."""
+ def __init__(self):
+ try:
+ self.impl = _GetchWindows()
+ except ImportError:
+ self.impl = _GetchUnix()
+
+ def __call__(self): return self.impl()
+
+
+class _GetchUnix:
+ def __init__(self):
+ import tty, sys
+
+ def __call__(self):
+ import sys, tty, termios
+ fd = sys.stdin.fileno()
+ old_settings = termios.tcgetattr(fd)
+ try:
+ tty.setraw(sys.stdin.fileno())
+ ch = sys.stdin.read(1)
+ finally:
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+ return ch
+
+
+class _GetchWindows:
+ def __init__(self):
+ import msvcrt
+
+ def __call__(self):
+ import msvcrt
+ return msvcrt.getch()
diff --git a/build/lib/out/__init__.py b/build/lib/out/__init__.py
new file mode 100644
index 0000000..1a69021
--- /dev/null
+++ b/build/lib/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()
diff --git a/dist/TermIO-0.1-py2-none-any.whl b/dist/TermIO-0.1-py2-none-any.whl
new file mode 100644
index 0000000..8126cf1
--- /dev/null
+++ b/dist/TermIO-0.1-py2-none-any.whl
Binary files differ
diff --git a/in/__init__.py b/in/__init__.py
new file mode 100644
index 0000000..b886141
--- /dev/null
+++ b/in/__init__.py
@@ -0,0 +1,35 @@
+class _Getch:
+ """Gets a single character from standard input. Does not echo to the
+screen."""
+ def __init__(self):
+ try:
+ self.impl = _GetchWindows()
+ except ImportError:
+ self.impl = _GetchUnix()
+
+ def __call__(self): return self.impl()
+
+
+class _GetchUnix:
+ def __init__(self):
+ import tty, sys
+
+ def __call__(self):
+ import sys, tty, termios
+ fd = sys.stdin.fileno()
+ old_settings = termios.tcgetattr(fd)
+ try:
+ tty.setraw(sys.stdin.fileno())
+ ch = sys.stdin.read(1)
+ finally:
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+ return ch
+
+
+class _GetchWindows:
+ def __init__(self):
+ import msvcrt
+
+ def __call__(self):
+ import msvcrt
+ return msvcrt.getch()
diff --git a/out/__init__.py b/out/__init__.py
new file mode 100644
index 0000000..1a69021
--- /dev/null
+++ b/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()
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..bb784f7
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,23 @@
+import setuptools
+
+
+with open("README.md", "r") as fh:
+ long_description = fh.read()
+
+
+setuptools.setup(
+ name='TermIO',
+ version='0.1',
+ scripts=[],
+ author="jakobst1n",
+ author_email="jakob.stendahl@outlook.com",
+ description="Simple terminal manipulator",
+ long_description=long_description,
+ long_description_content_type="text/markdown",
+ url="https://github.com/jakobst1n/TermIO-python-package",
+ packages=setuptools.find_packages(),
+ classifiers=[
+ "Programming Language :: Python :: 3",
+ "Operating System :: OS Independent",
+ ],
+)