+ def client_wins(self, client_id: UUID) -> list['_ClientWindow']:
+ 'All _ClientWindows matching client_id.'
+ return [win for win in self.windows
+ if isinstance(win, _ClientWindow)
+ and win.client_id == client_id] # pylint: disable=no-member
+
+ def client_win(self, client_id: UUID, chat: str = '') -> '_ClientWindow':
+ '''That _ClientWindow matching client_id and chat; create if none.
+
+ In case of creation, also switch to window, and if not client's first
+ window, copy prompt prefix from client's first window.
+ '''
+ client_wins = self.client_wins(client_id)
+ candidates = [win for win in client_wins if win.chat == chat]
+ if candidates:
+ return candidates[0]
+ new_idx = len(self.windows)
+ win = _ClientWindow(idx=new_idx, term=self.term, q_out=self._q_out,
+ client_id=client_id, chat=chat)
+ if client_wins:
+ win.prompt.prefix = client_wins[0].prompt.prefix
+ self.windows += [win]
+ self._switch_window(new_idx)
+ return win
+