#include "chat.h"
#include "debug.h"
-#include <cassert>
+#include "strfnd.h"
#include <cctype>
#include <sstream>
#include "util/string.h"
const ChatLine& ChatBuffer::getLine(u32 index) const
{
- assert(index < getLineCount());
+ assert(index < getLineCount()); // pre-condition
return m_unformatted[index];
}
// keep m_formatted in sync
if (del_formatted < m_formatted.size())
{
- assert(m_formatted[del_formatted].first);
+
+ sanity_check(m_formatted[del_formatted].first);
++del_formatted;
while (del_formatted < m_formatted.size() &&
!m_formatted[del_formatted].first)
}
else if (cols != m_cols || rows != m_rows)
{
- // TODO: Avoid reformatting ALL lines (even inivisble ones)
+ // TODO: Avoid reformatting ALL lines (even invisible ones)
// each time the console size changes.
// Find out the scroll position in *unformatted* lines
m_nick_completion_end = 0;
}
+void ChatPrompt::input(const std::wstring &str)
+{
+ m_line.insert(m_cursor, str);
+ m_cursor += str.size();
+ clampView();
+ m_nick_completion_start = 0;
+ m_nick_completion_end = 0;
+}
+
std::wstring ChatPrompt::submit()
{
std::wstring line = m_line;
}
}
-void ChatPrompt::nickCompletion(const std::list<std::wstring>& names, bool backwards)
+void ChatPrompt::nickCompletion(const std::list<std::string>& names, bool backwards)
{
// Two cases:
// (a) m_nick_completion_start == m_nick_completion_end == 0
// find all names that start with the selected prefix
std::vector<std::wstring> completions;
- for (std::list<std::wstring>::const_iterator
+ for (std::list<std::string>::const_iterator
i = names.begin();
i != names.end(); ++i)
{
- if (str_starts_with(*i, prefix, true))
+ if (str_starts_with(narrow_to_wide(*i), prefix, true))
{
- std::wstring completion = *i;
+ std::wstring completion = narrow_to_wide(*i);
if (prefix_start == 0)
- completion += L":";
+ completion += L": ";
completions.push_back(completion);
}
}
}
}
}
- std::wstring replacement = completions[replacement_index] + L" ";
+ std::wstring replacement = completions[replacement_index];
if (word_end < m_line.size() && isspace(word_end))
++word_end;
void ChatBackend::scrollPageUp()
{
- m_console_buffer.scroll(-m_console_buffer.getRows());
+ m_console_buffer.scroll(-(s32)m_console_buffer.getRows());
}