mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add colored text (not only colored chat).
Add documentation, move files to a proper place and avoid memory leaks. Make it work with most kind of texts, and allow backgrounds too.
This commit is contained in:
parent
1d40385d4a
commit
14ef2b445a
28 changed files with 689 additions and 318 deletions
37
src/chat.cpp
37
src/chat.cpp
|
@ -267,28 +267,26 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
|||
next_frags.push_back(temp_frag);
|
||||
}
|
||||
|
||||
std::wstring name_sanitized = removeEscapes(line.name);
|
||||
std::wstring name_sanitized = line.name.c_str();
|
||||
|
||||
// Choose an indentation level
|
||||
if (line.name.empty()) {
|
||||
// Server messages
|
||||
hanging_indentation = 0;
|
||||
}
|
||||
else if (name_sanitized.size() + 3 <= cols/2) {
|
||||
} else if (name_sanitized.size() + 3 <= cols/2) {
|
||||
// Names shorter than about half the console width
|
||||
hanging_indentation = line.name.size() + 3;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Very long names
|
||||
hanging_indentation = 2;
|
||||
}
|
||||
ColoredString line_text(line.text);
|
||||
//EnrichedString line_text(line.text);
|
||||
|
||||
next_line.first = true;
|
||||
bool text_processing = false;
|
||||
|
||||
// Produce fragments and layout them into lines
|
||||
while (!next_frags.empty() || in_pos < line_text.size())
|
||||
while (!next_frags.empty() || in_pos < line.text.size())
|
||||
{
|
||||
// Layout fragments into lines
|
||||
while (!next_frags.empty())
|
||||
|
@ -326,9 +324,9 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
|||
}
|
||||
|
||||
// Produce fragment
|
||||
if (in_pos < line_text.size())
|
||||
if (in_pos < line.text.size())
|
||||
{
|
||||
u32 remaining_in_input = line_text.size() - in_pos;
|
||||
u32 remaining_in_input = line.text.size() - in_pos;
|
||||
u32 remaining_in_output = cols - out_column;
|
||||
|
||||
// Determine a fragment length <= the minimum of
|
||||
|
@ -338,14 +336,14 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
|||
while (frag_length < remaining_in_input &&
|
||||
frag_length < remaining_in_output)
|
||||
{
|
||||
if (isspace(line_text[in_pos + frag_length]))
|
||||
if (isspace(line.text.getString()[in_pos + frag_length]))
|
||||
space_pos = frag_length;
|
||||
++frag_length;
|
||||
}
|
||||
if (space_pos != 0 && frag_length < remaining_in_input)
|
||||
frag_length = space_pos + 1;
|
||||
|
||||
temp_frag.text = line_text.substr(in_pos, frag_length);
|
||||
temp_frag.text = line.text.substr(in_pos, frag_length);
|
||||
temp_frag.column = 0;
|
||||
//temp_frag.bold = 0;
|
||||
next_frags.push_back(temp_frag);
|
||||
|
@ -729,19 +727,22 @@ ChatBuffer& ChatBackend::getRecentBuffer()
|
|||
return m_recent_buffer;
|
||||
}
|
||||
|
||||
std::wstring ChatBackend::getRecentChat()
|
||||
EnrichedString ChatBackend::getRecentChat()
|
||||
{
|
||||
std::wostringstream stream;
|
||||
EnrichedString result;
|
||||
for (u32 i = 0; i < m_recent_buffer.getLineCount(); ++i)
|
||||
{
|
||||
const ChatLine& line = m_recent_buffer.getLine(i);
|
||||
if (i != 0)
|
||||
stream << L"\n";
|
||||
if (!line.name.empty())
|
||||
stream << L"<" << line.name << L"> ";
|
||||
stream << line.text;
|
||||
result += L"\n";
|
||||
if (!line.name.empty()) {
|
||||
result += L"<";
|
||||
result += line.name;
|
||||
result += L"> ";
|
||||
}
|
||||
result += line.text;
|
||||
}
|
||||
return stream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
ChatPrompt& ChatBackend::getPrompt()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue