'[91, 49, 59, 51, 68]': ('window', 'left'),
'[91, 49, 59, 51, 67]': ('window', 'right'),
}
+CMD_SHORTCUTS = {
+ 'disconnect': 'window.disconnect',
+ 'reconnect': 'window.reconnect'
+}
IRCSPEC_LINE_SEPARATOR = b'\r\n'
IRCSPEC_TAG_ESCAPES = ((r'\:', ';'),
def _start_connecting(self) -> None:
- def connect(self):
+ def connect(self) -> None:
self._socket = socket()
self._broadcast('CONN_ALERT',
f'Connecting to {self._hostname} …')
self.prompt.draw()
+class ConnectionWindow(Window):
+ 'Window with attributes and methods for dealing with an IrcConnection.'
+
+ def __init__(self,
+ broadcast: Callable[[str, Any], None],
+ conn_idx: int,
+ *args, **kwargs
+ ) -> None:
+ self._broadcast = broadcast
+ self._conn_idx = conn_idx
+ super().__init__(*args, **kwargs)
+
+ def cmd__disconnect(self, quit_msg: str = 'ircplom says bye') -> None:
+ 'Send QUIT command to server.'
+ self._broadcast('SEND',
+ (self._conn_idx, IrcMessage('QUIT', [quit_msg])))
+
+ def cmd__reconnect(self) -> None:
+ 'Attempt reconnection.'
+ self._broadcast('INIT_RECONNECTION', (self._conn_idx,))
+
+
class TuiLoop(Loop):
'Loop for drawing/updating TUI.'
self.put(Event('SET_SCREEN'))
def _cmd_name_to_cmd(self, cmd_name: str) -> Optional[Callable]:
+ cmd_name = CMD_SHORTCUTS.get(cmd_name, cmd_name)
cmd_parent = self
while True:
cmd_name_toks = cmd_name.split('.', maxsplit=1)
window.set_geometry()
self.window.draw()
elif event.type_ == 'CONNECTION_WINDOW':
- conn_win = Window(len(self._windows), self._term)
+ conn_win = ConnectionWindow(self.broadcast, event.payload[0],
+ len(self._windows), self._term)
self._windows += [conn_win]
self._conn_windows += [conn_win]
self._switch_window(conn_win.idx)
self._window_idx = idx
self.window.draw()
- def cmd__reconnect(self) -> Optional[str]:
- 'Send INIT_RECONNECTION to server if in connection window.'
- if self.window not in self._conn_windows:
- return 'can only reconnect from inside connection window.'
- conn_idx = self._conn_windows.index(self.window)
- self.broadcast('INIT_RECONNECTION', (conn_idx,))
- return None
-
def cmd__connect(self,
hostname: str,
username: str,
self.broadcast('INIT_CONNECTION',
(hostname, (username, nickname, realname)))
- def cmd__disconnect(self,
- quit_msg: str = 'ircplom says bye'
- ) -> Optional[str]:
- 'Send QUIT command to server if in connection window.'
- if self.window not in self._conn_windows:
- return 'what to disconnect from? (not in connection window!)'
- self.broadcast('SEND', (self._conn_windows.index(self.window),
- IrcMessage('QUIT', [quit_msg])))
- return None
-
def cmd__prompt_enter(self) -> None:
'Get prompt content from .window.prompt.enter, parse to & run command.'
to_parse = self.window.prompt.enter()