Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions picotui/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Screen:

@staticmethod
def wr(s):
# TODO: When Python is 3.5, update this to use only bytes
# TODO: Update this to use only bytes
if isinstance(s, str):
s = bytes(s, "utf-8")
os.write(1, s)
Expand All @@ -16,7 +16,7 @@ def wr_fixedw(s, width):
# Write string in a fixed-width field
s = s[:width]
Screen.wr(s)
Screen.wr(" " * (width - len(s)))
Screen.wr(b" " * (width - len(s)))
# Doesn't work here, as it doesn't advance cursor
#Screen.clear_num_pos(width - len(s))

Expand All @@ -26,8 +26,7 @@ def cls():

@staticmethod
def goto(x, y):
# TODO: When Python is 3.5, update this to use bytes
Screen.wr("\x1b[%d;%dH" % (y + 1, x + 1))
Screen.wr(b"\x1b[%d;%dH" % (y + 1, x + 1))

@staticmethod
def clear_to_eol():
Expand All @@ -37,25 +36,24 @@ def clear_to_eol():
@staticmethod
def clear_num_pos(num):
if num > 0:
Screen.wr("\x1b[%dX" % num)
Screen.wr(b"\x1b[%dX" % num)

@staticmethod
def attr_color(fg, bg=-1):
if bg == -1:
bg = fg >> 4
fg &= 0xf
# TODO: Switch to b"%d" % foo when py3.5 is everywhere
if bg is None:
if (fg > 8):
Screen.wr("\x1b[%d;1m" % (fg + 30 - 8))
Screen.wr(b"\x1b[%d;1m" % (fg + 30 - 8))
else:
Screen.wr("\x1b[%dm" % (fg + 30))
Screen.wr(b"\x1b[%dm" % (fg + 30))
else:
assert bg <= 8
if (fg > 8):
Screen.wr("\x1b[%d;%d;1m" % (fg + 30 - 8, bg + 40))
Screen.wr(b"\x1b[%d;%d;1m" % (fg + 30 - 8, bg + 40))
else:
Screen.wr("\x1b[0;%d;%dm" % (fg + 30, bg + 40))
Screen.wr(b"\x1b[0;%d;%dm" % (fg + 30, bg + 40))

@staticmethod
def attr_reset():
Expand Down Expand Up @@ -99,7 +97,7 @@ def draw_box(self, left, top, width, height):

def clear_box(self, left, top, width, height):
# doesn't work
#self.wr("\x1b[%s;%s;%s;%s$z" % (top + 1, left + 1, top + height, left + width))
# self.wr(b"\x1b[%s;%s;%s;%s$z" % (top + 1, left + 1, top + height, left + width))
s = b" " * width
bottom = top + height
while top < bottom:
Expand Down