diff options
Diffstat (limited to 'src/tab.py')
-rw-r--r-- | src/tab.py | 119 |
1 files changed, 80 insertions, 39 deletions
@@ -216,7 +216,7 @@ class MucTab(Tab): self.info_header = window.MucInfoWin(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, stdscr, self.visible) self.info_win = window.TextWin(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, stdscr, self.visible) self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible) - self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible) + self.input = window.MessageInput(1, self.width, self.height-1, 0, stdscr, self.visible) def resize(self, stdscr): """ @@ -244,14 +244,17 @@ class MucTab(Tab): self.input.refresh() def on_input(self, key): - self.key_func = { + key_func = { "\t": self.completion, "^I": self.completion, "M-i": self.completion, "KEY_BTAB": self.last_words_completion, + "^J": self.on_enter, + "^M": self.on_enter, + "\n": self.on_enter } - if key in self.key_func: - return self.key_func[key]() + if key in key_func: + return key_func[key]() return self.input.do_command(key) def completion(self): @@ -271,7 +274,6 @@ class MucTab(Tab): for msg in self._room.messages[:-40:-1]: if not msg: continue - log.debug('line: %s\n'%msg) for char in char_we_dont_want: msg.txt = msg.txt.replace(char, ' ') for word in msg.txt.split(): @@ -279,6 +281,12 @@ class MucTab(Tab): words.append(word) self.input.auto_completion(words, False) + def on_enter(self): + """ + When enter is pressed, send the message to the Muc + """ + self.core.execute(self.input.key_enter()) + def get_color_state(self): return self._room.color_state @@ -313,7 +321,7 @@ class MucTab(Tab): self.info_win.resize(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, stdscr, self.visible) def just_before_refresh(self): - self.input.move_cursor_to_pos() + return def on_close(self): return @@ -329,7 +337,7 @@ class PrivateTab(Tab): self.info_header = window.PrivateInfoWin(1, self.width, self.height-3-self.core.information_win_size, 0, stdscr, self.visible) self.info_win = window.TextWin(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, stdscr, self.visible) self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible) - self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible) + self.input = window.MessageInput(1, self.width, self.height-1, 0, stdscr, self.visible) def resize(self, stdscr): Tab.resize(self, stdscr) @@ -359,8 +367,21 @@ class PrivateTab(Tab): return self._room.name def on_input(self, key): + key_func = { + "^J": self.on_enter, + "^M": self.on_enter, + "\n": self.on_enter + } + if key in key_func: + return key_func[key]() return self.input.do_command(key) + def on_enter(self): + """ + When enter is pressed, send the message to the Muc + """ + self.core.execute(self.input.key_enter()) + def on_lose_focus(self): self._room.set_color_state(theme.COLOR_TAB_NORMAL) self._room.remove_line_separator() @@ -395,17 +416,6 @@ class RosterInfoTab(Tab): A tab, splitted in two, containing the roster and infos """ def __init__(self, stdscr, core): - self.single_key_commands = { - "^J": self.on_enter, - "^M": self.on_enter, - "\n": self.on_enter, - ' ': self.on_space, - "/": self.on_slash, - "KEY_UP": self.move_cursor_up, - "KEY_DOWN": self.move_cursor_down, - "o": self.toggle_offline_show, - "^F": self.start_search, - } Tab.__init__(self, stdscr, core) self.name = "Roster" roster_width = self.width//2 @@ -415,7 +425,8 @@ class RosterInfoTab(Tab): self.info_win = window.TextWin(self.height-2, info_width, 0, roster_width+1, stdscr, self.visible) self.roster_win = window.RosterWin(self.height-2-3, roster_width, 0, 0, stdscr, self.visible) self.contact_info_win = window.ContactInfoWin(3, roster_width, self.height-2-3, 0, stdscr, self.visible) - self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible, False, "Enter commands with “/”. “o”: toggle offline show") + self.default_help_message = window.HelpText(1, self.width, self.height-1, 0, stdscr, self.visible, "Enter commands with “/”. “o”: toggle offline show") + self.input = self.default_help_message self.set_color_state(theme.COLOR_TAB_NORMAL) def resize(self, stdscr): @@ -447,19 +458,22 @@ class RosterInfoTab(Tab): self._color_state = color def on_input(self, key): - if self.input.input_mode: - ret = self.input.do_command(key) - roster._contact_filter = (jid_and_name_match, self.input.text) - # if the input is empty, go back to command mode - if self.input.is_empty() and not self.input._instructions: - self.input.input_mode = False - curses.curs_set(0) - self.input.rewrite_text() - if self.input._instructions: - return True - return ret - if key in self.single_key_commands: - return self.single_key_commands[key]() + key_commands = { + "^J": self.on_enter, + "^M": self.on_enter, + "\n": self.on_enter, + ' ': self.on_space, + "/": self.on_slash, + "KEY_UP": self.move_cursor_up, + "KEY_DOWN": self.move_cursor_down, + "o": self.toggle_offline_show, + "^F": self.start_search, + } + res = self.input.do_command(key) + if res: + return res + if key in key_commands: + return key_commands[key]() def toggle_offline_show(self): """ @@ -476,9 +490,19 @@ class RosterInfoTab(Tab): """ '/' is pressed, we enter "input mode" """ - self.input.input_mode = True curses.curs_set(1) - self.on_input("/") # we add the slash + self.input = window.CommandInput(1, self.width, self.height-1, 0, self.default_help_message, self.visible, "", self.reset_help_message, self.execute_slash_command) + self.input.do_command("/") # we add the slash + + def reset_help_message(self, _=None): + curses.curs_set(0) + self.input = self.default_help_message + return True + + def execute_slash_command(self, txt): + if txt.startswith('/'): + self.core.execute(txt) + return self.reset_help_message() def on_lose_focus(self): self._color_state = theme.COLOR_TAB_NORMAL @@ -518,6 +542,7 @@ class RosterInfoTab(Tab): def on_enter(self): selected_row = self.roster_win.get_selected_row() + self.core.on_roster_enter_key(selected_row) return selected_row def start_search(self): @@ -526,15 +551,17 @@ class RosterInfoTab(Tab): in it. """ curses.curs_set(1) - roster._contact_filter = (jid_and_name_match, self.input.text) - self.input.input_mode = True - self.input.start_command(self.on_search_terminate, self.on_search_terminate, '[search]') + self.input = window.CommandInput(1, self.width, self.height-1, 0, self.default_help_message, self.visible, "[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter) return True + def set_roster_filter(self, txt): + roster._contact_filter = (jid_and_name_match, txt) + def on_search_terminate(self, txt): curses.curs_set(0) roster._contact_filter = None - return True + self.reset_help_message() + return False def just_before_refresh(self): return @@ -556,7 +583,7 @@ class ConversationTab(Tab): self.info_header = window.ConversationInfoWin(1, self.width, self.height-3-self.core.information_win_size, 0, stdscr, self.visible) self.info_win = window.TextWin(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, stdscr, self.visible) self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible) - self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible) + self.input = window.MessageInput(1, self.width, self.height-1, 0, stdscr, self.visible) def resize(self, stdscr): Tab.resize(self, stdscr) @@ -588,8 +615,22 @@ class ConversationTab(Tab): return self._name def on_input(self, key): + key_func = { + "^J": self.on_enter, + "^M": self.on_enter, + "\n": self.on_enter + } + if key in key_func: + return key_func[key]() return self.input.do_command(key) + + def on_enter(self): + """ + When enter is pressed, send the message to the Muc + """ + self.core.execute(self.input.key_enter()) + def on_lose_focus(self): self.set_color_state(theme.COLOR_TAB_NORMAL) self._text_buffer.remove_line_separator() |