let parser = {
tokenize: function(str) {
+ let token_ends = [];
let tokens = [];
let token = ''
let quoted = false;
} else if (c == '\\') {
escaped = true;
} else if (c == '"') {
- quoted = false
+ quoted = false
} else {
token += c;
}
quoted = true
} else if (c === ' ') {
if (token.length > 0) {
+ token_ends.push(i);
tokens.push(token);
token = '';
}
if (token.length > 0) {
tokens.push(token);
}
- return tokens;
+ let token_starts = [];
+ for (let i = 0; i < token_ends.length; i++) {
+ token_starts.push(token_ends[i] - tokens[i].length);
+ };
+ return [tokens, token_starts];
},
parse_yx(position_string) {
let coordinate_strings = position_string.split(',')
let websocket = new WebSocket(websocket_location);
websocket.onmessage = function (event) {
- let tokens = parser.tokenize(event.data);
+ let tokens = parser.tokenize(event.data)[0];
if (tokens[0] === 'TURN') {
game.things = {}
game.turn = parseInt(tokens[1]);
tui.draw_input_line();
tui.refresh();
} else if (event.key == 'Enter') {
- let tokens = parser.tokenize(chat.input_line);
+ let [tokens, token_starts] = parser.tokenize(chat.input_line);
if (tokens.length > 0 && tokens[0].length > 0) {
if (tokens[0][0] == '/') {
if (tokens[0] == '/play') {
}
} else if (tokens[0] == '/msg') {
if (tokens.length > 2) {
- // FIXME only sends first word
- websocket.send('QUERY ' + quote(tokens[1]) + ' ' + quote(tokens[2]));
+ let msg = chat.input_line.slice(token_starts[2]);
+ websocket.send('QUERY ' + quote(tokens[1]) + ' ' + quote(msg));
} else {
tui.log_msg('? need message target and message');
}