enabled: bool
data: str
- def str_for_log(self, name: str) -> str:
- 'Optimized for Client._log per-line listing.'
- listing = '+' if self.enabled else '-'
- listing += f' {name}'
- if self.data:
- listing += f' ({self.data})'
- return listing
-
class _CapsManager:
self._log = Logger(self._do_log).add
self.update_login(nick_confirmed=False,
nickname=self.conn_setup.nickname)
- self._log(f'connecting {self.conn_setup}')
+ self._log('connecting …', conn_setup=self.conn_setup)
self._start_connecting()
def _start_connecting(self) -> None:
self.send(IrcMessage(verb='NICK', params=(self.conn_setup.nickname,)))
@abstractmethod
- def _do_log(self, msg: str, stream: str = STREAM_SERVER) -> None:
+ def _do_log(self, msg: str, stream: str = STREAM_SERVER, **kwargs) -> None:
'Write msg into log of stream, whatever shape that may have.'
def send(self,
def close(self) -> None:
'Close both recv Loop and socket.'
- self._log(msg='disconnecting from server', stream=STREAM_ALL)
+ self._log(msg='disconnecting from server …', stream=STREAM_ALL)
self._caps.clear()
if self.conn:
self.conn.close()
if isinstance(result, str):
self._log(result)
else:
- for line in (['server capabilities (enabled: "+"):']
- + [cap.str_for_log(c_name) for c_name, cap
- in self._caps.dict.items()]):
- self._log(line)
+ self._log('', caps=self._caps.dict)
if self._caps.sasl_wait:
if self.conn_setup.password:
self._log('trying to authenticate via SASL/plain')
'TUI adaptions to Client.'
# built-ins
from getpass import getuser
+from dataclasses import asdict as dc_asdict
from inspect import signature
from typing import Callable, Optional
# ourselves
return
self._start_connecting()
- def _do_log(self, msg: str, stream: str = STREAM_SERVER) -> None:
- if stream == _STREAM_SAME:
- self._put(TuiEvent.affector('_log').kw(msg=msg))
- self._put(TuiEvent.affector('redraw_affected'))
- else:
- self._client_tui_trigger('log', stream=stream, msg=msg)
+ def _do_log(self, msg: str, stream: str = STREAM_SERVER, **kwargs) -> None:
+ to_log = []
+ if msg:
+ to_log += [msg]
+ if 'caps' in kwargs:
+ to_log += ['server capabilities (enabled: "+"):']
+ for cap_name, cap in kwargs['caps'].items():
+ listing = '+' if cap.enabled else '-'
+ listing += f' {cap_name}'
+ if cap.data:
+ listing += f' ({cap.data})'
+ to_log += [listing]
+ if 'conn_setup' in kwargs:
+ to_log += ['connection setup:']
+ for k, v in dc_asdict(kwargs['conn_setup']).items():
+ to_log += [f' {k}: [{v}]']
+ for item in to_log:
+ if stream == _STREAM_SAME:
+ self._put(TuiEvent.affector('_log').kw(msg=item))
+ self._put(TuiEvent.affector('redraw_affected'))
+ else:
+ self._client_tui_trigger('log', stream=stream, msg=item)
def update_login(self, nick_confirmed: bool, nickname: str = '') -> None:
super().update_login(nick_confirmed, nickname)