6 class AbortOnGetkey(Exception):
15 self.do_refresh = True
16 self.store_widechar = False
17 curses.wrapper(self.run_loop)
19 def addstr(self, y, x, line, attr=0):
20 if y < self.size.y - 1 or x + len(line) < self.size.x:
21 self.stdscr.addstr(y, x, line, attr)
22 else: # workaround to <https://stackoverflow.com/q/7063128>
23 cut_i = self.size.x - x - 1
25 last_char = line[cut_i]
26 self.stdscr.addstr(y, self.size.x - 2, last_char, attr)
27 self.stdscr.insstr(y, self.size.x - 2, ' ')
28 self.stdscr.addstr(y, x, cut, attr)
31 from plomrogue.mapping import YX
32 self.size = YX(*self.stdscr.getmaxyx())
33 self.size = self.size - YX(self.size.y % 4, 0)
34 self.size = self.size - YX(0, self.size.x % 4)
38 self.do_refresh = True
41 curses.curs_set(0) # hide cursor
42 self.stdscr.timeout(10)
45 def draw_screen(self):
48 def get_key_and_keycode(self):
50 key = self.stdscr.getkey()
56 # workaround for <https://stackoverflow.com/a/56390915>
57 if self.store_widechar:
58 self.store_widechar = False
59 key = bytes([195, keycode]).decode()
61 self.store_widechar = True
65 def run_loop(self, stdscr):
69 self.on_each_loop_start()
70 for msg in self.socket.get_message():
71 self.handle_server_message(msg)
74 self.do_refresh = False
76 key, keycode = self.get_key_and_keycode()
79 self.on_key(key, keycode)
80 self.do_refresh = True
84 def msg_into_lines_of_width(msg, width):
88 for i in range(len(msg)):
89 if x >= width or msg[i] == "\n":