Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Solve issue kodie#2 

jeffs@jeffs-desktop:/home/jeffs/python/ansiescapes/ansiescapes-master  (development) *  $ diff ansiescapes.py original_ansiescapes.py 
8,17c8
< def _(s):
< # A solution to issue 2, kodie#2
< # Because I don't know what the data type of s is going to be (it might
< # be a type that has a decode function such as byte array ), simple test
< # is s has a decode method.  If it does, great, call it, otherwise, just 
< # return s.
<   if hasattr(s, "decode"):
<     return s.decode('unicode_escape')
<   else:
<     return s
---
> def _(s): return s.decode('unicode_escape');
  • Loading branch information
jeffsilverm authored Dec 26, 2019
1 parent 25a4b90 commit 90bba93
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ansiescapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
ESC = '\u001B['
isTerminalApp = os.environ.get('TERM_PROGRAM') == 'Apple_Terminal'

def _(s): return s.decode('unicode_escape');
def _(s):
# A solution to issue 2, https://github.com/kodie/ansiescapes/issues/2
# Because I don't know what the data type of s is going to be (it might
# be a type that has a decode function such as byte array ), simple test
# is s has a decode method. If it does, great, call it, otherwise, just
# return s.
if hasattr(s, "decode"):
return s.decode('unicode_escape')
else:
return s

def cursorTo(x, y = None):
if (not isinstance(x, numbers.Number)):
Expand Down
31 changes: 31 additions & 0 deletions test_ansiescapes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
#
# The following 4 imports are to make the same code run on both python 2.6+ and
# python 3.3+
import future
import builtins
import past
import six
import time

import ansiescapes as ae
for q in range(40):
print(q*2*"{}")
for q in range(5):
print(q, end="", flush=True)
time.sleep(1)
print(ae.eraseLine, end="", flush=True)
print(ae.ESC+"2J", end="", flush=True)
print(ae.cursorTo(0,0) + "cursoTo(0,0) This should be in the upper left corner", end="", flush=True)
print(ae.cursorMove(0,10) + "cursoTo(0,10) This should be 10 lines down at the left margin", end="", flush=True)
print(ae.cursorDown(count = 1) + "Down one", end="", flush=True)
print(ae.cursorDown(count = 2) + "Down two", end="", flush=True)
print(ae.cursorForward(count = 4) + "Forward 4", flush=True)
print(ae.cursorTo(3,20) + "cursoTo(3,20) somewhere on the third line", end="", flush=True)
for w in range (50):
print(ae.cursorBackward(count = 4)+"w", end="", flush=True)
time.sleep(0.5)
print(ae.cursorTo(0,0) + "cursoTo(0,0) This should be in the upper left corner", end="", flush=True)
print(ae.eraseLines(count = 1), end="", flush=True)
# print(image(buf, opts = {}):
# def setCwd(cwd = os.getcwd()):

0 comments on commit 90bba93

Please sign in to comment.