self._socket: Optional[socket] = None
self._assumed_open = False
self._loop: Optional[ConnectionLoop] = None
- self._broadcast(EventType.CONN_WINDOW, self._idx)
+ self._broadcast(EventType.CONN_WINDOW, self._login.nick)
self._start_connecting()
def _start_connecting(self) -> None:
'Keyboard-controlled command input field.'
_y: int
_width: int
+ _prompt: str = PROMPT_TEMPLATE
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
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 - 2]
self.draw()
def draw(self) -> None:
- prompt = PROMPT_TEMPLATE[:]
+ prefix = self._prompt[:]
content = self._input_buffer[:]
if self._cursor_x > len(self._input_buffer):
content += ' '
half_width = self._width // 2
offset = 0
- if len(prompt) + len(content) > self._width\
+ if len(prefix) + len(content) > self._width\
and self._cursor_x > half_width:
- prompt += PROMPT_ELL_IN
+ prefix += PROMPT_ELL_IN
if self._cursor_x > len(content) - half_width:
- offset = len(content) - self._width + len(prompt)
+ offset = len(content) - self._width + len(prefix)
else:
- offset = self._cursor_x - half_width + (len(prompt) // 2)
- cursor_x_to_write = len(prompt) - 1 + self._cursor_x - offset
- to_write = f'{prompt}{content[offset:]}'
+ offset = self._cursor_x - half_width + (len(prefix) // 2)
+ cursor_x_to_write = len(prefix) - 1 + self._cursor_x - offset
+ to_write = f'{prefix}{content[offset:]}'
if len(to_write) > self._width:
to_write = (to_write[:self._width - len(PROMPT_ELL_OUT)]
+ PROMPT_ELL_OUT)
window.set_geometry()
self.window.draw()
elif event.type_ == EventType.CONN_WINDOW:
- conn_win = ConnectionWindow(self.broadcast, event.payload[0],
- len(self._windows), self._term)
+ conn_win = ConnectionWindow(broadcast=self.broadcast,
+ conn_idx=event.payload[0],
+ idx=len(self._windows),
+ term=self._term)
+ conn_win.prompt.update_prompt(f'?{event.payload[1]} ')
self._windows += [conn_win]
self._conn_windows += [conn_win]
self._switch_window(conn_win.idx)