Add status view

This commit is contained in:
Paul Nameless 2019-02-18 19:10:51 +01:00
parent c37cabc72e
commit 5aa9a73f16
2 changed files with 32 additions and 21 deletions

View file

@ -116,6 +116,7 @@ class Controller:
self.model.get_chats() self.model.get_chats()
) )
self.refresh_msgs() self.refresh_msgs()
self.view.draw_status()
def refresh_msgs(self): def refresh_msgs(self):
msgs = self.model.get_current_msgs() msgs = self.model.get_current_msgs()

52
view.py
View file

@ -22,11 +22,15 @@ class View:
self.stdscr = stdscr self.stdscr = stdscr
self.chats = ChatView(stdscr) self.chats = ChatView(stdscr)
self.msgs = MsgView(stdscr) self.msgs = MsgView(stdscr)
self.status = StatusView(stdscr)
self.max_read = 2048 self.max_read = 2048
def draw_chats(self, current, chats): def draw_chats(self, current, chats):
self.chats.draw(current, chats) self.chats.draw(current, chats)
def draw_status(self, msg=None):
self.status.draw(msg)
def draw_msgs(self, current, msgs): def draw_msgs(self, current, msgs):
self.msgs.draw(current, msgs) self.msgs.draw(current, msgs)
@ -60,13 +64,13 @@ class View:
logger.info('Trying to chr: %s', chr(key)) logger.info('Trying to chr: %s', chr(key))
# except ValueError: # except ValueError:
# logger.exception() # logger.exception()
if key == 10: if key == 10: # return
logger.info('Sending msg: %s', buff) logger.info('Sending msg: %s', buff)
break break
elif key == 127: elif key == 127: # del
if buff: if buff:
buff = buff[:-1] buff = buff[:-1]
elif key == 7: elif key == 7: # ^G cancel
logger.info('Not Sending msg: %s', buff) logger.info('Not Sending msg: %s', buff)
buff = None buff = None
break break
@ -88,28 +92,21 @@ class View:
class StatusView: class StatusView:
def __init__(self, stdscr): def __init__(self, stdscr):
# self.stdscr = stdscr self.h = 1
pass self.w = curses.COLS
self.y = curses.LINES - 1
self.x = 0
self.win = stdscr.subwin(self.h, self.w, self.y, self.x)
def resize(self): def resize(self):
pass self.w = curses.COLS
self.y = curses.LINES - 1
self.win.resize(self.h, self.w)
self.win.wmove(self.y, self.x)
def draw(self, msg): def draw(self, msg):
# draw msg on the last line msg = ' ' * (self.w - 1)
pass self.win.addstr(0, 0, msg, curses.A_REVERSE)
emoji_pattern = re.compile(
"["
"\U0001F600-\U0001F64F" # emoticons
"\U0001F300-\U0001F5FF" # symbols & pictographs
"\U0001F680-\U0001F6FF" # transport & map symbols
"\U0001F1E0-\U0001F1FF" # flags (iOS)
"\U00002702-\U000027B0"
"\U000024C2-\U0001F251"
"]+",
flags=re.UNICODE
)
class ChatView: class ChatView:
@ -235,3 +232,16 @@ def parse_content(content):
else: else:
logger.debug('Unknown content: %s', content) logger.debug('Unknown content: %s', content)
return f'[unknown type {_type}]' return f'[unknown type {_type}]'
emoji_pattern = re.compile(
"["
"\U0001F600-\U0001F64F" # emoticons
"\U0001F300-\U0001F5FF" # symbols & pictographs
"\U0001F680-\U0001F6FF" # transport & map symbols
"\U0001F1E0-\U0001F1FF" # flags (iOS)
"\U00002702-\U000027B0"
"\U000024C2-\U0001F251"
"]+",
flags=re.UNICODE
)