self.input_ = self.input_[:max_length]
elif self.mode == self.mode_login and key == '\n':
self.socket.send('LOGIN ' + quote(self.input_))
+ self.input_ = ""
elif self.mode == self.mode_chat and key == '\n':
# TODO: query, nick, help, reconnect, unknown command
- if self.input_ == ':p':
- self.switch_mode('play')
- elif self.input_ == ':?':
- self.switch_mode('study')
+ if self.input_[0] == ':':
+ if self.input_ in {':p', ':play'}:
+ self.switch_mode('play')
+ elif self.input_ in {':?', ':study'}:
+ self.switch_mode('study')
+ elif self.input_.startswith(':nick'):
+ tokens = self.input_.split(maxsplit=1)
+ if len(tokens) == 2:
+ self.socket.send('LOGIN ' + quote(tokens[1]))
+ else:
+ self.log_msg('? need login name')
+ elif self.input_.startswith(':msg'):
+ tokens = self.input_.split(maxsplit=2)
+ if len(tokens) == 3:
+ self.socket.send('QUERY %s %s' % (quote(tokens[1]),
+ quote(tokens[2])))
+ else:
+ self.log_msg('? need message target and message')
+ else:
+ self.log_msg('? unknown command')
else:
self.socket.send('ALL ' + quote(self.input_))
- self.input_ = ""
+ self.input_ = ""
elif self.mode == self.mode_annotate and key == '\n':
if (self.input_ == ''):
self.input_ = ' '
} else if (tokens[0] === 'LOGIN_OK') {
this.send(['GET_GAMESTATE']);
tui.log_help();
+ // TODO wait for game state for this switch, use intermediary mode?
tui.switch_mode(mode_play);
} else if (tokens[0] === 'PORTAL') {
let position = parser.parse_yx(tokens[1]);
}, false);
tui.inputEl.addEventListener('keydown', (event) => {
if (event.key == 'Enter') {
- event.preventDefault();
+ event.preventDefault();
}
if (tui.mode == mode_login && event.key == 'Enter') {
server.send(['LOGIN', tui.inputEl.value]);