mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
Add ability to send messages that longer than width of msgs pane
This commit is contained in:
parent
3d69431c39
commit
c37cabc72e
1 changed files with 13 additions and 7 deletions
20
view.py
20
view.py
|
@ -48,13 +48,12 @@ class View:
|
|||
# return curses.unctrl(ch).decode()
|
||||
|
||||
def get_input(self):
|
||||
curses.echo()
|
||||
curses.curs_set(1)
|
||||
|
||||
buff = ''
|
||||
pos = 0
|
||||
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)
|
||||
logger.info('Pressed in send msg: "%s"', key)
|
||||
# try:
|
||||
|
@ -64,17 +63,24 @@ class View:
|
|||
if key == 10:
|
||||
logger.info('Sending msg: %s', buff)
|
||||
break
|
||||
elif key == 127:
|
||||
if buff:
|
||||
buff = buff[:-1]
|
||||
elif key == 7:
|
||||
logger.info('Not Sending msg: %s', buff)
|
||||
buff = None
|
||||
break
|
||||
# elif (key >= 32 and key < 256):
|
||||
elif chr(key).isprintable():
|
||||
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)
|
||||
return buff
|
||||
|
||||
|
|
Loading…
Reference in a new issue