Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
a = [fmtstr(c*columns) for _ in range(1)]
elif c == "c":
w.write(w.t.move(w.t.height-1, 0))
w.scroll_down()
elif isinstance(c, events.WindowChangeEvent):
a = w.array_from_text("window just changed to %d rows and %d columns" % (c.rows, c.columns))
elif c == '\x0c': # ctrl-L
[w.write('\n') for _ in range(rows)]
continue
else:
a = w.array_from_text("unknown command")
w.render_to_terminal(a)
if __name__ == '__main__':
logging.basicConfig(filename='display.log',level=logging.DEBUG)
array_size_test(FullscreenWindow(sys.stdout))
from __future__ import unicode_literals # convenient for Python 2
import random
from curtsies import FullscreenWindow, Input, FSArray
from curtsies.fmtfuncs import red, bold, green, on_blue, yellow
print(yellow('this prints normally, not to the alternate screen'))
with FullscreenWindow() as window:
with Input() as input_generator:
msg = red(on_blue(bold('Press escape to exit')))
a = FSArray(window.height, window.width)
a[0:1, 0:msg.width] = [msg]
window.render_to_terminal(a)
for c in input_generator:
if c == '':
break
elif c == '':
a = FSArray(window.height, window.width)
else:
s = repr(c)
row = random.choice(range(window.height))
column = random.choice(range(window.width-len(s)))
color = random.choice([red, green, on_blue, yellow])
a[row, column:column+len(s)] = [color(s)]
def fullscreen_winch_with_input():
print('this should be just off-screen')
w = FullscreenWindow(sys.stdout)
def sigwinch_handler(signum, frame):
print('sigwinch! Changed from %r to %r' % ((rows, columns), (w.height, w.width)))
signal.signal(signal.SIGWINCH, sigwinch_handler)
with w:
with Cbreak(sys.stdin):
for e in input.Input():
rows, columns = w.height, w.width
a = [fmtstr((('.%sx%s.%r.' % (rows, columns, e)) * rows)[:columns]) for row in range(rows)]
w.render_to_terminal(a)
def main():
with FullscreenWindow(sys.stdout) as window:
with Input(sys.stdin) as input_generator:
world = World(width=window.width, height=window.height)
window.render_to_terminal(world.get_array())
for c in input_generator:
msg = world.process_event(c)
if msg:
break
window.render_to_terminal(world.get_array())
print(msg)
def main():
counter = FrameCounter()
with FullscreenWindow() as window:
print('Press escape to exit')
game = SnakeGame(window.height, window.width)
with Input() as input_generator:
c = None
last_c = ''
for framenum in itertools.count(0):
t0 = time.time()
while True:
t = time.time()
temp_c = input_generator.send(max(0, t - (t0 + time_per_frame)))
if temp_c is not None:
c = temp_c
if c is None:
pass
elif c == '':
return
try:
if len(argv) == 1:
pass
elif len(argv) == 2:
faceoff[1] = pool[argv[1]]
elif len(argv) == 3:
faceoff = [pool[argv[1]], pool[argv[2]]]
else:
raise KeyError
except KeyError:
print("Usage: %s [player] [player]" % argv[0])
print("where a player is one of:", ', '.join(sorted(pool)))
return 1
else:
with Input() as i:
with FullscreenWindow() as w:
tictactoe(w, i, *faceoff)
return 0
def refresh_window(self):
self.window = curtsies.FullscreenWindow(hide_cursor=True)
self.wheight = self.window.height
self.wwidth = self.window.width
self.screen_arr = None
# Divide the screen up into two, to keep it simple for now
self.wheight_top_end = int(self.wheight / 2)
self.wheight_bottom_start = int(self.wheight / 2)
self.wwidth_left_end = int(self.wwidth / 2)
self.wwidth_right_start = int(self.wwidth / 2)
assert self.wheight >= 24, 'Terminal not tall enough: ' + str(self.wheight) + ' < 24'
assert self.wwidth >= 80, 'Terminal not wide enough: ' + str(self.wwidth) + ' < 80'
def main(host, port):
client = socket.socket()
client.connect((host, port))
client.setblocking(False)
conn = Connection(client)
keypresses = []
with FullscreenWindow() as window:
with Input() as input_generator:
while True:
a = FSArray(10, 80)
in_text = ''.join(keypresses)[:80]
a[9:10, 0:len(in_text)] = [red(in_text)]
for i, line in zip(reversed(range(2,7)), reversed(conn.render())):
a[i:i+1, 0:len(line)] = [line]
text = 'connected to %s:%d' % (host if len(host) < 50 else host[:50]+'...', port)
a[0:1, 0:len(text)] = [blue(text)]
window.render_to_terminal(a)
ready_to_read, _, _ = select.select([conn, input_generator], [], [])
for r in ready_to_read:
if r is conn:
r.on_read()
else:
def main():
counter = FrameCounter()
with FullscreenWindow() as window:
print('Press escape to exit')
with Input() as input_generator:
a = FSArray(window.height, window.width)
c = None
for framenum in itertools.count(0):
t0 = time.time()
while True:
t = time.time()
temp_c = input_generator.send(max(0, t - (t0 + time_per_frame)))
if temp_c is not None:
c = temp_c
if c is None:
pass
elif c == '':