Add ability to send messages that longer than width of msgs pane

This commit is contained in:
Paul Nameless 2019-02-18 17:00:30 +01:00
parent 3d69431c39
commit c37cabc72e

20
view.py
View file

@ -48,13 +48,12 @@ class View:
# return curses.unctrl(ch).decode() # return curses.unctrl(ch).decode()
def get_input(self): def get_input(self):
curses.echo()
curses.curs_set(1) curses.curs_set(1)
buff = '' buff = ''
pos = 0
while True: while True:
key = self.msgs.win.get_wch(self.msgs.h-1, pos) key = self.msgs.win.get_wch(
self.msgs.h-1, min(len(buff), self.msgs.w-1))
key = ord(key) key = ord(key)
logger.info('Pressed in send msg: "%s"', key) logger.info('Pressed in send msg: "%s"', key)
# try: # try:
@ -64,17 +63,24 @@ class View:
if key == 10: if key == 10:
logger.info('Sending msg: %s', buff) logger.info('Sending msg: %s', buff)
break break
elif key == 127:
if buff:
buff = buff[:-1]
elif key == 7: elif key == 7:
logger.info('Not Sending msg: %s', buff) logger.info('Not Sending msg: %s', buff)
buff = None buff = None
break break
# elif (key >= 32 and key < 256):
elif chr(key).isprintable(): elif chr(key).isprintable():
buff += chr(key) buff += chr(key)
pos += 1 if len(buff) >= self.msgs.w:
start = len(buff) - self.msgs.w
buff_wrapped = buff[start+1:]
else:
buff_wrapped = (buff + ' ' * (self.msgs.w -
len(buff) - 1))
self.msgs.win.addstr(self.msgs.h-1, 0, buff_wrapped)
self.msgs.win.move(self.msgs.h-1, min(len(buff), self.msgs.w-1))
# curses.cbreak()
curses.noecho()
curses.curs_set(0) curses.curs_set(0)
return buff return buff