Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4634
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
12 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5b50030
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+*.swp
+*.egg-info/
+*.pyc
+
+/build/
+/dist/
+/test/
+/old/
+
+/local
+
+__pycache__
+
diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 0000000..7a03c65
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,5 @@
+Copyright (C) 2022 LANNOCC (Shawn A. Wilson [lannocc@yahoo.com])
+@%@~LICENSE:MIT~@%@
+
+saw_072822_1 - Initial commit (just termio.py from my vipy project).
+
diff --git a/LICENSE b/LICENSE
index d7e26c3..a4bb45c 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,21 +1,21 @@
MIT License
-Copyright (c) 2022 Shawn A. Wilson
+Copyright (c) 2022 LANNOCC (Shawn A. Wilson [lannocc@yahoo.com])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
diff --git a/README.md b/README.md
index 18f1413..4774af2 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,19 @@
# appscii
-Application in ASCII for Python
+
+## Application in ASCII for Python
+
+## Installation
+
+The appscii library is easy to install using pip:
+```
+pip install appscii
+```
+
+## Usage
+
+Coming soon.
+
+## Author
+
+Created by Shawn A. Wilson [lannocc@yahoo.com] aka LANNOCC.
+
diff --git a/appscii/__init__.py b/appscii/__init__.py
new file mode 100644
index 0000000..baf6088
--- /dev/null
+++ b/appscii/__init__.py
@@ -0,0 +1,2 @@
+from .__version__ import __version__
+
diff --git a/appscii/__version__.py b/appscii/__version__.py
new file mode 100644
index 0000000..446d9fd
--- /dev/null
+++ b/appscii/__version__.py
@@ -0,0 +1,2 @@
+__version__ = '0.0.1'
+
diff --git a/appscii/termio.py b/appscii/termio.py
new file mode 100644
index 0000000..0825cbc
--- /dev/null
+++ b/appscii/termio.py
@@ -0,0 +1,349 @@
+import os
+import sys
+
+
+def clear_screen():
+ if os.name == 'nt':
+ os.system("cls")
+ else:
+ os.system("clear")
+
+
+def cprint_at(row, col, text='', color=None, on_color=None, attrs=None, end='\n'):
+ print_at(row, col, colored(text, color, on_color, attrs), end=end)
+
+
+'''
+keymode_settings_orig = None
+
+def key_enable():
+ fd = sys.stdin.fileno()
+ keymode_settings_orig = termios.tcgetattr(fd)
+
+ settings = keymode_settings_orig & ~termios.ICANON & ~termios.ECHO
+
+ termios.tcsetattr(fd, termios.TCSAFLUSH, settings)
+
+def key_disable():
+ fd = sys.stdin.fileno()
+ termios.tcsetattr(fd, termios.TCSAFLUSH, keymode_settings_orig)
+
+#def key_hit():
+# if os.name == 'nt':
+# return msvcrt.kbhit()
+
+def key_get():
+ pass
+'''
+
+
+
+#
+# The following code originally taken from:
+# https://stackoverflow.com/questions/5174810/how-to-turn-off-blinking-cursor-in-command-window/10455937#10455937
+#
+
+
+if os.name == 'nt':
+ import msvcrt
+ import ctypes
+
+ class _CursorInfo(ctypes.Structure):
+ _fields_ = [("size", ctypes.c_int),
+ ("visible", ctypes.c_byte)]
+
+def hide_cursor():
+ if os.name == 'nt':
+ ci = _CursorInfo()
+ handle = ctypes.windll.kernel32.GetStdHandle(-11)
+ ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci))
+ ci.visible = False
+ ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci))
+
+ else: # assume ANSI compatible
+ sys.stdout.write("\033[?25l")
+ sys.stdout.flush()
+
+def show_cursor():
+ if os.name == 'nt':
+ ci = _CursorInfo()
+ handle = ctypes.windll.kernel32.GetStdHandle(-11)
+ ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci))
+ ci.visible = True
+ ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci))
+
+ else: # assume ANSI compatible
+ sys.stdout.write("\033[?25h")
+ sys.stdout.flush()
+
+
+
+#
+# The following code originally taken from:
+# https://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user/21659588#21659588
+#
+
+def _read_char():
+ try:
+ import termios
+
+ except ImportError:
+ # Non-POSIX; assume Windows
+ import msvcrt
+ return msvcrt.getch
+
+ # POSIX
+ import tty
+
+ def getch():
+ fd = sys.stdin.fileno()
+ settings = termios.tcgetattr(fd)
+
+ try:
+ tty.setraw(fd)
+ char = sys.stdin.read(1)
+
+ finally:
+ termios.tcsetattr(fd, termios.TCSADRAIN, settings)
+
+ return char
+
+ return getch
+
+'''read_char() is our actual function for export, which has resolved the proper implementation'''
+read_char = _read_char()
+
+
+
+
+#
+# The following code originally taken from:
+# https://rosettacode.org/wiki/Terminal_control/Cursor_positioning#Python
+#
+
+def print_at(row, col, text='', end='\n'):
+ # use ANSI escape for positioning
+ print('\033[{};{}H{}'.format(row, col, text), end=end)
+
+
+if os.name == 'nt':
+ # Windows console does not support ANSI sequences
+
+ from ctypes import *
+
+ STD_OUTPUT_HANDLE = -11
+
+ class COORD(Structure):
+ pass
+
+ COORD._fields_ = [("X", c_short), ("Y", c_short)]
+
+ def win_print_at(row, col, text, end='\n'):
+ h = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
+ windll.kernel32.SetConsoleCursorPosition(h, COORD(col, row))
+
+ if end:
+ text += end
+
+ c = text.encode("windows-1252")
+ windll.kernel32.WriteConsoleA(h, c_char_p(c), len(c), None, None)
+
+ print_at = win_print_at
+
+
+
+
+
+#
+# The following code originally taken from:
+# https://gist.github.com/jtriley/1108174
+#
+
+import shlex
+import struct
+import platform
+import subprocess
+
+
+def get_terminal_size():
+ """ getTerminalSize()
+ - get width and height of console
+ - works on linux,os x,windows,cygwin(windows)
+ originally retrieved from:
+ http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python
+ """
+ current_os = platform.system()
+ tuple_xy = None
+ if current_os == 'Windows':
+ tuple_xy = _get_terminal_size_windows()
+ if tuple_xy is None:
+ tuple_xy = _get_terminal_size_tput()
+ # needed for window's python in cygwin's xterm!
+ if current_os in ['Linux', 'Darwin'] or current_os.startswith('CYGWIN'):
+ tuple_xy = _get_terminal_size_linux()
+ if tuple_xy is None:
+ print("default")
+ tuple_xy = (80, 25) # default value
+ return tuple_xy
+
+
+def _get_terminal_size_windows():
+ try:
+ from ctypes import windll, create_string_buffer
+ # stdin handle is -10
+ # stdout handle is -11
+ # stderr handle is -12
+ h = windll.kernel32.GetStdHandle(-12)
+ csbi = create_string_buffer(22)
+ res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
+ if res:
+ (bufx, bufy, curx, cury, wattr,
+ left, top, right, bottom,
+ maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
+ sizex = right - left + 1
+ sizey = bottom - top + 1
+ return sizex, sizey
+ except:
+ pass
+
+
+def _get_terminal_size_tput():
+ # get terminal width
+ # src: http://stackoverflow.com/questions/263890/how-do-i-find-the-width-height-of-a-terminal-window
+ try:
+ cols = int(subprocess.check_call(shlex.split('tput cols')))
+ rows = int(subprocess.check_call(shlex.split('tput lines')))
+ return (cols, rows)
+ except:
+ pass
+
+
+def _get_terminal_size_linux():
+ def ioctl_GWINSZ(fd):
+ try:
+ import fcntl
+ import termios
+ cr = struct.unpack('hh',
+ fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
+ return cr
+ except:
+ pass
+ cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
+ if not cr:
+ try:
+ fd = os.open(os.ctermid(), os.O_RDONLY)
+ cr = ioctl_GWINSZ(fd)
+ os.close(fd)
+ except:
+ pass
+ if not cr:
+ try:
+ cr = (os.environ['LINES'], os.environ['COLUMNS'])
+ except:
+ return None
+ return int(cr[1]), int(cr[0])
+
+
+
+
+#
+# The following code originally from termcolor pypi package:
+# (MIT License)
+# Copyright (c) 2008-2011 Volvox Development Team
+# Author: Konstantin Lepa <konstantin.lepa@gmail.com>
+#
+
+
+ATTRIBUTES = dict(
+ list(zip([
+ 'bold',
+ 'dark',
+ '',
+ 'underline',
+ 'blink',
+ '',
+ 'reverse',
+ 'concealed'
+ ],
+ list(range(1, 9))
+ ))
+ )
+del ATTRIBUTES['']
+
+
+HIGHLIGHTS = dict(
+ list(zip([
+ 'on_grey',
+ 'on_red',
+ 'on_green',
+ 'on_yellow',
+ 'on_blue',
+ 'on_magenta',
+ 'on_cyan',
+ 'on_white'
+ ],
+ list(range(40, 48))
+ ))
+ )
+
+
+COLORS = dict(
+ list(zip([
+ 'grey',
+ 'red',
+ 'green',
+ 'yellow',
+ 'blue',
+ 'magenta',
+ 'cyan',
+ 'white',
+ ],
+ list(range(30, 38))
+ ))
+ )
+
+
+RESET = '\033[0m'
+
+
+def colored(text, color=None, on_color=None, attrs=None):
+ """Colorize text.
+
+ Available text colors:
+ red, green, yellow, blue, magenta, cyan, white.
+
+ Available text highlights:
+ on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white.
+
+ Available attributes:
+ bold, dark, underline, blink, reverse, concealed.
+
+ Example:
+ colored('Hello, World!', 'red', 'on_grey', ['blue', 'blink'])
+ colored('Hello, World!', 'green')
+ """
+ if os.getenv('ANSI_COLORS_DISABLED') is None:
+ fmt_str = '\033[%dm%s'
+ if color is not None:
+ text = fmt_str % (COLORS[color], text)
+
+ if on_color is not None:
+ text = fmt_str % (HIGHLIGHTS[on_color], text)
+
+ if attrs is not None:
+ for attr in attrs:
+ text = fmt_str % (ATTRIBUTES[attr], text)
+
+ text += RESET
+ return text
+
+
+def cprint(text, color=None, on_color=None, attrs=None, **kwargs):
+ """Print colorize text.
+
+ It accepts arguments of print function.
+ """
+
+ print((colored(text, color, on_color, attrs)), **kwargs)
+
+
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..f634783
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,3 @@
+# The single dot below pulls in requirements from setup.py:
+.
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..0baa922
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,47 @@
+import setuptools
+
+
+def run():
+ setuptools.setup(
+ name='appscii',
+ version = findversion('.', 'appscii'),
+ author='LANNOCC (Shawn A. Wilson)',
+ author_email='lannocc@yahoo.com',
+ url='https://github.com/lannocc/appscii',
+ packages=setuptools.find_packages(),
+ description='Application in ASCII for Python',
+ long_description_content_type='text/markdown',
+ long_description=open('README.md').read(),
+ classifiers=[
+ "Programming Language :: Python :: 3",
+ "License :: OSI Approved :: MIT License",
+ "Operating System :: OS Independent",
+ ],
+ install_requires=[
+ ],
+ )
+
+
+def findversion(root, name):
+ '''versioning strategy taken from
+ http://stackoverflow.com/a/7071358/7203060'''
+
+ import re
+ from os.path import join
+
+ vfile = join(root, name, "__version__.py")
+ vmatch = re.search(r'^__version__ *= *["\']([^"\']*)["\']',
+ open(vfile, "rt").read(), re.M)
+
+ if vmatch:
+ version = vmatch.group(1)
+ print ("Found %s version %s" % (name, version))
+ return version
+
+ else:
+ raise RuntimeError("Expecting a version string in %s." % (vfile))
+
+
+if __name__ == '__main__':
+ run()
+
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Sep 20, 4:16 PM (1 d, 1 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3602
Default Alt Text
(12 KB)
Attached To
Mode
rAPPSCII Terminal Framework
Attached
Detach File
Event Timeline
Log In to Comment