#include "settings.h"
#include "util/numeric.h"
#include "util/string.h"
+#include "chat_interface.h"
TerminalChatConsole g_term_console;
void TerminalChatConsole::handleInput(int ch, bool &complete_redraw_needed)
{
+ ChatPrompt &prompt = m_chat_backend.getPrompt();
// Helpful if you want to collect key codes that aren't documented
/*if (ch != ERR) {
m_chat_backend.addMessage(L"",
case KEY_ENTER:
case '\r':
case '\n': {
- std::wstring text = m_chat_backend.getPrompt().submit();
- typeChatMessage(text);
+ prompt.addToHistory(prompt.getLine());
+ typeChatMessage(prompt.replace(L""));
break;
}
case KEY_UP:
- m_chat_backend.getPrompt().historyPrev();
+ prompt.historyPrev();
break;
case KEY_DOWN:
- m_chat_backend.getPrompt().historyNext();
+ prompt.historyNext();
break;
case KEY_LEFT:
// Left pressed
// move character to the left
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_LEFT,
ChatPrompt::CURSOROP_SCOPE_CHARACTER);
case 545:
// Ctrl-Left pressed
// move word to the left
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_LEFT,
ChatPrompt::CURSOROP_SCOPE_WORD);
case KEY_RIGHT:
// Right pressed
// move character to the right
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_RIGHT,
ChatPrompt::CURSOROP_SCOPE_CHARACTER);
case 560:
// Ctrl-Right pressed
// move word to the right
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_RIGHT,
ChatPrompt::CURSOROP_SCOPE_WORD);
case KEY_HOME:
// Home pressed
// move to beginning of line
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_LEFT,
ChatPrompt::CURSOROP_SCOPE_LINE);
case KEY_END:
// End pressed
// move to end of line
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_RIGHT,
ChatPrompt::CURSOROP_SCOPE_LINE);
case 127:
// Backspace pressed
// delete character to the left
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_LEFT,
ChatPrompt::CURSOROP_SCOPE_CHARACTER);
case KEY_DC:
// Delete pressed
// delete character to the right
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_RIGHT,
ChatPrompt::CURSOROP_SCOPE_CHARACTER);
case 519:
// Ctrl-Delete pressed
// delete word to the right
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_RIGHT,
ChatPrompt::CURSOROP_SCOPE_WORD);
case 21:
// Ctrl-U pressed
// kill line to left end
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_LEFT,
ChatPrompt::CURSOROP_SCOPE_LINE);
case 11:
// Ctrl-K pressed
// kill line to right end
- m_chat_backend.getPrompt().cursorOperation(
+ prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_RIGHT,
ChatPrompt::CURSOROP_SCOPE_LINE);
case KEY_TAB:
// Tab pressed
// Nick completion
- m_chat_backend.getPrompt().nickCompletion(m_nicks, false);
+ prompt.nickCompletion(m_nicks, false);
break;
default:
// Add character to the prompt,
m_pending_utf8_bytes = "";
// hopefully only one char in the wstring...
for (size_t i = 0; i < w.size(); i++) {
- m_chat_backend.getPrompt().input(w.c_str()[i]);
+ prompt.input(w.c_str()[i]);
}
}
} else if (IS_ASCII_PRINTABLE_CHAR(ch)) {
- m_chat_backend.getPrompt().input(ch);
+ prompt.input(ch);
} else {
// Silently ignore characters we don't handle
if (p.first > m_log_level)
continue;
- m_chat_backend.addMessage(
- utf8_to_wide(Logger::getLevelLabel(p.first)),
- utf8_to_wide(p.second));
+ std::wstring error_message = utf8_to_wide(Logger::getLevelLabel(p.first));
+ if (!g_settings->getBool("disable_escape_sequences")) {
+ error_message = std::wstring(L"\x1b(c@red)").append(error_message)
+ .append(L"\x1b(c@white)");
+ }
+ m_chat_backend.addMessage(error_message, utf8_to_wide(p.second));
}
// handle input
const ChatFormattedLine& line = buf.getFormattedLine(row);
if (line.fragments.empty())
continue;
- for (u32 i = 0; i < line.fragments.size(); ++i) {
- const ChatFormattedFragment& fragment = line.fragments[i];
- addstr(wide_to_utf8(fragment.text).c_str());
+ for (const ChatFormattedFragment &fragment : line.fragments) {
+ addstr(wide_to_utf8(fragment.text.getString()).c_str());
}
}
}