def set_geometry(self, measurements: YX) -> None:
self._y, self._width = measurements
- def update_prompt(self, new_prefix: str) -> None:
- 'Set as new prompt string new_prefix followed by PROMPT_TEMPLATE.'
- self._prompt = f'{new_prefix}{PROMPT_TEMPLATE}'
-
def append(self, to_append: str) -> None:
self._cursor_x += len(to_append)
self._input_buffer = (self._input_buffer[:self._cursor_x - 1]
return to_return
+class ConnectionPromptWidget(PromptWidget):
+ 'PromptWidget with attributes, methods for dealing with an IrcConnection.'
+ _nickname: str = ''
+
+ def update_prompt(self,
+ nick_confirmed=False,
+ nick: Optional[str] = None
+ ) -> None:
+ 'Update nickname-relevant knowledge to go into prompt string.'
+ self._prompt = ''
+ if nick:
+ self._nickname = nick
+ if self._nickname:
+ self._prompt += ' ' if nick_confirmed else '?'
+ self._prompt += self._nickname
+ self._prompt += PROMPT_TEMPLATE
+
+
class LogWidget(ScrollableWidget):
'Collects line-shaped messages, scrolls and wraps them for display.'
_view_size: YX
class Window(Widget):
'Collects a log and a prompt meant for the same content stream.'
_y_status: int
+ prompt: PromptWidget
def __init__(self, idx: int, term: Terminal) -> None:
self.idx = idx
self._term = term
self.log = LogWidget(self._term.wrap, self._term.write)
- self.prompt = PromptWidget(self._term.write)
+ self.prompt = self.__annotations__['prompt'](self._term.write)
if hasattr(self._term, 'size'):
self.set_geometry()
class ConnectionWindow(Window):
'Window with attributes and methods for dealing with an IrcConnection.'
+ prompt: ConnectionPromptWidget
def __init__(self,
broadcast: Callable[[EventType, Any], None],
self._term = term
self._windows = [Window(0, self._term)]
self._window_idx = 0
- self._conn_windows: list[Window] = []
+ self._conn_windows: list[ConnectionWindow] = []
super().__init__(*args, **kwargs)
self.put(Event(EventType.SET_SCREEN))
conn_idx=event.payload[0],
idx=len(self._windows),
term=self._term)
- conn_win.prompt.update_prompt(f'?{event.payload[1]} ')
+ conn_win.prompt.update_prompt(nick_confirmed=False,
+ nick=event.payload[1])
self._windows += [conn_win]
self._conn_windows += [conn_win]
self._switch_window(conn_win.idx)
self.window.log.draw()
elif event.type_ == EventType.NICK_SET:
conn_win = self._conn_windows[event.payload[0]]
- conn_win.prompt.update_prompt(f' {event.payload[1]} ')
+ conn_win.prompt.update_prompt(nick_confirmed=True,
+ nick=event.payload[1])
+ if conn_win == self.window:
+ self.window.prompt.draw()
+ elif event.type_ == EventType.DISCONNECTED:
+ conn_win = self._conn_windows[event.payload[0]]
+ conn_win.prompt.update_prompt(nick_confirmed=False)
if conn_win == self.window:
self.window.prompt.draw()
elif event.type_ == EventType.KEYBINDING: