chat.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "chat.h"
  17. #include "debug.h"
  18. #include "config.h"
  19. #include "util/strfnd.h"
  20. #include <cctype>
  21. #include <sstream>
  22. #include "util/string.h"
  23. #include "util/numeric.h"
  24. ChatBuffer::ChatBuffer(u32 scrollback):
  25. m_scrollback(scrollback)
  26. {
  27. if (m_scrollback == 0)
  28. m_scrollback = 1;
  29. m_empty_formatted_line.first = true;
  30. }
  31. void ChatBuffer::addLine(std::wstring name, std::wstring text)
  32. {
  33. ChatLine line(name, text);
  34. m_unformatted.push_back(line);
  35. if (m_rows > 0)
  36. {
  37. // m_formatted is valid and must be kept valid
  38. bool scrolled_at_bottom = (m_scroll == getBottomScrollPos());
  39. u32 num_added = formatChatLine(line, m_cols, m_formatted);
  40. if (scrolled_at_bottom)
  41. m_scroll += num_added;
  42. }
  43. // Limit number of lines by m_scrollback
  44. if (m_unformatted.size() > m_scrollback)
  45. {
  46. deleteOldest(m_unformatted.size() - m_scrollback);
  47. }
  48. }
  49. void ChatBuffer::clear()
  50. {
  51. m_unformatted.clear();
  52. m_formatted.clear();
  53. m_scroll = 0;
  54. }
  55. u32 ChatBuffer::getLineCount() const
  56. {
  57. return m_unformatted.size();
  58. }
  59. const ChatLine& ChatBuffer::getLine(u32 index) const
  60. {
  61. assert(index < getLineCount()); // pre-condition
  62. return m_unformatted[index];
  63. }
  64. void ChatBuffer::step(f32 dtime)
  65. {
  66. for (ChatLine &line : m_unformatted) {
  67. line.age += dtime;
  68. }
  69. }
  70. void ChatBuffer::deleteOldest(u32 count)
  71. {
  72. bool at_bottom = (m_scroll == getBottomScrollPos());
  73. u32 del_unformatted = 0;
  74. u32 del_formatted = 0;
  75. while (count > 0 && del_unformatted < m_unformatted.size())
  76. {
  77. ++del_unformatted;
  78. // keep m_formatted in sync
  79. if (del_formatted < m_formatted.size())
  80. {
  81. sanity_check(m_formatted[del_formatted].first);
  82. ++del_formatted;
  83. while (del_formatted < m_formatted.size() &&
  84. !m_formatted[del_formatted].first)
  85. ++del_formatted;
  86. }
  87. --count;
  88. }
  89. m_unformatted.erase(m_unformatted.begin(), m_unformatted.begin() + del_unformatted);
  90. m_formatted.erase(m_formatted.begin(), m_formatted.begin() + del_formatted);
  91. if (at_bottom)
  92. m_scroll = getBottomScrollPos();
  93. else
  94. scrollAbsolute(m_scroll - del_formatted);
  95. }
  96. void ChatBuffer::deleteByAge(f32 maxAge)
  97. {
  98. u32 count = 0;
  99. while (count < m_unformatted.size() && m_unformatted[count].age > maxAge)
  100. ++count;
  101. deleteOldest(count);
  102. }
  103. u32 ChatBuffer::getColumns() const
  104. {
  105. return m_cols;
  106. }
  107. u32 ChatBuffer::getRows() const
  108. {
  109. return m_rows;
  110. }
  111. void ChatBuffer::reformat(u32 cols, u32 rows)
  112. {
  113. if (cols == 0 || rows == 0)
  114. {
  115. // Clear formatted buffer
  116. m_cols = 0;
  117. m_rows = 0;
  118. m_scroll = 0;
  119. m_formatted.clear();
  120. }
  121. else if (cols != m_cols || rows != m_rows)
  122. {
  123. // TODO: Avoid reformatting ALL lines (even invisible ones)
  124. // each time the console size changes.
  125. // Find out the scroll position in *unformatted* lines
  126. u32 restore_scroll_unformatted = 0;
  127. u32 restore_scroll_formatted = 0;
  128. bool at_bottom = (m_scroll == getBottomScrollPos());
  129. if (!at_bottom)
  130. {
  131. for (s32 i = 0; i < m_scroll; ++i)
  132. {
  133. if (m_formatted[i].first)
  134. ++restore_scroll_unformatted;
  135. }
  136. }
  137. // If number of columns change, reformat everything
  138. if (cols != m_cols)
  139. {
  140. m_formatted.clear();
  141. for (u32 i = 0; i < m_unformatted.size(); ++i)
  142. {
  143. if (i == restore_scroll_unformatted)
  144. restore_scroll_formatted = m_formatted.size();
  145. formatChatLine(m_unformatted[i], cols, m_formatted);
  146. }
  147. }
  148. // Update the console size
  149. m_cols = cols;
  150. m_rows = rows;
  151. // Restore the scroll position
  152. if (at_bottom)
  153. {
  154. scrollBottom();
  155. }
  156. else
  157. {
  158. scrollAbsolute(restore_scroll_formatted);
  159. }
  160. }
  161. }
  162. const ChatFormattedLine& ChatBuffer::getFormattedLine(u32 row) const
  163. {
  164. s32 index = m_scroll + (s32) row;
  165. if (index >= 0 && index < (s32) m_formatted.size())
  166. return m_formatted[index];
  167. return m_empty_formatted_line;
  168. }
  169. void ChatBuffer::scroll(s32 rows)
  170. {
  171. scrollAbsolute(m_scroll + rows);
  172. }
  173. void ChatBuffer::scrollAbsolute(s32 scroll)
  174. {
  175. s32 top = getTopScrollPos();
  176. s32 bottom = getBottomScrollPos();
  177. m_scroll = scroll;
  178. if (m_scroll < top)
  179. m_scroll = top;
  180. if (m_scroll > bottom)
  181. m_scroll = bottom;
  182. }
  183. void ChatBuffer::scrollBottom()
  184. {
  185. m_scroll = getBottomScrollPos();
  186. }
  187. void ChatBuffer::scrollTop()
  188. {
  189. m_scroll = getTopScrollPos();
  190. }
  191. u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
  192. std::vector<ChatFormattedLine>& destination) const
  193. {
  194. u32 num_added = 0;
  195. std::vector<ChatFormattedFragment> next_frags;
  196. ChatFormattedLine next_line;
  197. ChatFormattedFragment temp_frag;
  198. u32 out_column = 0;
  199. u32 in_pos = 0;
  200. u32 hanging_indentation = 0;
  201. // Format the sender name and produce fragments
  202. if (!line.name.empty()) {
  203. temp_frag.text = L"<";
  204. temp_frag.column = 0;
  205. //temp_frag.bold = 0;
  206. next_frags.push_back(temp_frag);
  207. temp_frag.text = line.name;
  208. temp_frag.column = 0;
  209. //temp_frag.bold = 1;
  210. next_frags.push_back(temp_frag);
  211. temp_frag.text = L"> ";
  212. temp_frag.column = 0;
  213. //temp_frag.bold = 0;
  214. next_frags.push_back(temp_frag);
  215. }
  216. std::wstring name_sanitized = line.name.c_str();
  217. // Choose an indentation level
  218. if (line.name.empty()) {
  219. // Server messages
  220. hanging_indentation = 0;
  221. } else if (name_sanitized.size() + 3 <= cols/2) {
  222. // Names shorter than about half the console width
  223. hanging_indentation = line.name.size() + 3;
  224. } else {
  225. // Very long names
  226. hanging_indentation = 2;
  227. }
  228. //EnrichedString line_text(line.text);
  229. next_line.first = true;
  230. bool text_processing = false;
  231. // Produce fragments and layout them into lines
  232. while (!next_frags.empty() || in_pos < line.text.size())
  233. {
  234. // Layout fragments into lines
  235. while (!next_frags.empty())
  236. {
  237. ChatFormattedFragment& frag = next_frags[0];
  238. if (frag.text.size() <= cols - out_column)
  239. {
  240. // Fragment fits into current line
  241. frag.column = out_column;
  242. next_line.fragments.push_back(frag);
  243. out_column += frag.text.size();
  244. next_frags.erase(next_frags.begin());
  245. }
  246. else
  247. {
  248. // Fragment does not fit into current line
  249. // So split it up
  250. temp_frag.text = frag.text.substr(0, cols - out_column);
  251. temp_frag.column = out_column;
  252. //temp_frag.bold = frag.bold;
  253. next_line.fragments.push_back(temp_frag);
  254. frag.text = frag.text.substr(cols - out_column);
  255. out_column = cols;
  256. }
  257. if (out_column == cols || text_processing)
  258. {
  259. // End the current line
  260. destination.push_back(next_line);
  261. num_added++;
  262. next_line.fragments.clear();
  263. next_line.first = false;
  264. out_column = text_processing ? hanging_indentation : 0;
  265. }
  266. }
  267. // Produce fragment
  268. if (in_pos < line.text.size())
  269. {
  270. u32 remaining_in_input = line.text.size() - in_pos;
  271. u32 remaining_in_output = cols - out_column;
  272. // Determine a fragment length <= the minimum of
  273. // remaining_in_{in,out}put. Try to end the fragment
  274. // on a word boundary.
  275. u32 frag_length = 1, space_pos = 0;
  276. while (frag_length < remaining_in_input &&
  277. frag_length < remaining_in_output)
  278. {
  279. if (iswspace(line.text.getString()[in_pos + frag_length]))
  280. space_pos = frag_length;
  281. ++frag_length;
  282. }
  283. if (space_pos != 0 && frag_length < remaining_in_input)
  284. frag_length = space_pos + 1;
  285. temp_frag.text = line.text.substr(in_pos, frag_length);
  286. temp_frag.column = 0;
  287. //temp_frag.bold = 0;
  288. next_frags.push_back(temp_frag);
  289. in_pos += frag_length;
  290. text_processing = true;
  291. }
  292. }
  293. // End the last line
  294. if (num_added == 0 || !next_line.fragments.empty())
  295. {
  296. destination.push_back(next_line);
  297. num_added++;
  298. }
  299. return num_added;
  300. }
  301. s32 ChatBuffer::getTopScrollPos() const
  302. {
  303. s32 formatted_count = (s32) m_formatted.size();
  304. s32 rows = (s32) m_rows;
  305. if (rows == 0)
  306. return 0;
  307. if (formatted_count <= rows)
  308. return formatted_count - rows;
  309. return 0;
  310. }
  311. s32 ChatBuffer::getBottomScrollPos() const
  312. {
  313. s32 formatted_count = (s32) m_formatted.size();
  314. s32 rows = (s32) m_rows;
  315. if (rows == 0)
  316. return 0;
  317. return formatted_count - rows;
  318. }
  319. ChatPrompt::ChatPrompt(const std::wstring &prompt, u32 history_limit):
  320. m_prompt(prompt),
  321. m_history_limit(history_limit)
  322. {
  323. }
  324. void ChatPrompt::input(wchar_t ch)
  325. {
  326. m_line.insert(m_cursor, 1, ch);
  327. m_cursor++;
  328. clampView();
  329. m_nick_completion_start = 0;
  330. m_nick_completion_end = 0;
  331. }
  332. void ChatPrompt::input(const std::wstring &str)
  333. {
  334. m_line.insert(m_cursor, str);
  335. m_cursor += str.size();
  336. clampView();
  337. m_nick_completion_start = 0;
  338. m_nick_completion_end = 0;
  339. }
  340. void ChatPrompt::addToHistory(std::wstring line)
  341. {
  342. if (!line.empty())
  343. m_history.push_back(line);
  344. if (m_history.size() > m_history_limit)
  345. m_history.erase(m_history.begin());
  346. m_history_index = m_history.size();
  347. }
  348. void ChatPrompt::clear()
  349. {
  350. m_line.clear();
  351. m_view = 0;
  352. m_cursor = 0;
  353. m_nick_completion_start = 0;
  354. m_nick_completion_end = 0;
  355. }
  356. std::wstring ChatPrompt::replace(std::wstring line)
  357. {
  358. std::wstring old_line = m_line;
  359. m_line = line;
  360. m_view = m_cursor = line.size();
  361. clampView();
  362. m_nick_completion_start = 0;
  363. m_nick_completion_end = 0;
  364. return old_line;
  365. }
  366. void ChatPrompt::historyPrev()
  367. {
  368. if (m_history_index != 0)
  369. {
  370. --m_history_index;
  371. replace(m_history[m_history_index]);
  372. }
  373. }
  374. void ChatPrompt::historyNext()
  375. {
  376. if (m_history_index + 1 >= m_history.size())
  377. {
  378. m_history_index = m_history.size();
  379. replace(L"");
  380. }
  381. else
  382. {
  383. ++m_history_index;
  384. replace(m_history[m_history_index]);
  385. }
  386. }
  387. void ChatPrompt::nickCompletion(const std::list<std::string>& names, bool backwards)
  388. {
  389. // Two cases:
  390. // (a) m_nick_completion_start == m_nick_completion_end == 0
  391. // Then no previous nick completion is active.
  392. // Get the word around the cursor and replace with any nick
  393. // that has that word as a prefix.
  394. // (b) else, continue a previous nick completion.
  395. // m_nick_completion_start..m_nick_completion_end are the
  396. // interval where the originally used prefix was. Cycle
  397. // through the list of completions of that prefix.
  398. u32 prefix_start = m_nick_completion_start;
  399. u32 prefix_end = m_nick_completion_end;
  400. bool initial = (prefix_end == 0);
  401. if (initial)
  402. {
  403. // no previous nick completion is active
  404. prefix_start = prefix_end = m_cursor;
  405. while (prefix_start > 0 && !iswspace(m_line[prefix_start-1]))
  406. --prefix_start;
  407. while (prefix_end < m_line.size() && !iswspace(m_line[prefix_end]))
  408. ++prefix_end;
  409. if (prefix_start == prefix_end)
  410. return;
  411. }
  412. std::wstring prefix = m_line.substr(prefix_start, prefix_end - prefix_start);
  413. // find all names that start with the selected prefix
  414. std::vector<std::wstring> completions;
  415. for (const std::string &name : names) {
  416. if (str_starts_with(narrow_to_wide(name), prefix, true)) {
  417. std::wstring completion = narrow_to_wide(name);
  418. if (prefix_start == 0)
  419. completion += L": ";
  420. completions.push_back(completion);
  421. }
  422. }
  423. if (completions.empty())
  424. return;
  425. // find a replacement string and the word that will be replaced
  426. u32 word_end = prefix_end;
  427. u32 replacement_index = 0;
  428. if (!initial)
  429. {
  430. while (word_end < m_line.size() && !iswspace(m_line[word_end]))
  431. ++word_end;
  432. std::wstring word = m_line.substr(prefix_start, word_end - prefix_start);
  433. // cycle through completions
  434. for (u32 i = 0; i < completions.size(); ++i)
  435. {
  436. if (str_equal(word, completions[i], true))
  437. {
  438. if (backwards)
  439. replacement_index = i + completions.size() - 1;
  440. else
  441. replacement_index = i + 1;
  442. replacement_index %= completions.size();
  443. break;
  444. }
  445. }
  446. }
  447. std::wstring replacement = completions[replacement_index];
  448. if (word_end < m_line.size() && iswspace(m_line[word_end]))
  449. ++word_end;
  450. // replace existing word with replacement word,
  451. // place the cursor at the end and record the completion prefix
  452. m_line.replace(prefix_start, word_end - prefix_start, replacement);
  453. m_cursor = prefix_start + replacement.size();
  454. clampView();
  455. m_nick_completion_start = prefix_start;
  456. m_nick_completion_end = prefix_end;
  457. }
  458. void ChatPrompt::reformat(u32 cols)
  459. {
  460. if (cols <= m_prompt.size())
  461. {
  462. m_cols = 0;
  463. m_view = m_cursor;
  464. }
  465. else
  466. {
  467. s32 length = m_line.size();
  468. bool was_at_end = (m_view + m_cols >= length + 1);
  469. m_cols = cols - m_prompt.size();
  470. if (was_at_end)
  471. m_view = length;
  472. clampView();
  473. }
  474. }
  475. std::wstring ChatPrompt::getVisiblePortion() const
  476. {
  477. return m_prompt + m_line.substr(m_view, m_cols);
  478. }
  479. s32 ChatPrompt::getVisibleCursorPosition() const
  480. {
  481. return m_cursor - m_view + m_prompt.size();
  482. }
  483. void ChatPrompt::cursorOperation(CursorOp op, CursorOpDir dir, CursorOpScope scope)
  484. {
  485. s32 old_cursor = m_cursor;
  486. s32 new_cursor = m_cursor;
  487. s32 length = m_line.size();
  488. s32 increment = (dir == CURSOROP_DIR_RIGHT) ? 1 : -1;
  489. switch (scope) {
  490. case CURSOROP_SCOPE_CHARACTER:
  491. new_cursor += increment;
  492. break;
  493. case CURSOROP_SCOPE_WORD:
  494. if (dir == CURSOROP_DIR_RIGHT) {
  495. // skip one word to the right
  496. while (new_cursor < length && iswspace(m_line[new_cursor]))
  497. new_cursor++;
  498. while (new_cursor < length && !iswspace(m_line[new_cursor]))
  499. new_cursor++;
  500. while (new_cursor < length && iswspace(m_line[new_cursor]))
  501. new_cursor++;
  502. } else {
  503. // skip one word to the left
  504. while (new_cursor >= 1 && iswspace(m_line[new_cursor - 1]))
  505. new_cursor--;
  506. while (new_cursor >= 1 && !iswspace(m_line[new_cursor - 1]))
  507. new_cursor--;
  508. }
  509. break;
  510. case CURSOROP_SCOPE_LINE:
  511. new_cursor += increment * length;
  512. break;
  513. case CURSOROP_SCOPE_SELECTION:
  514. break;
  515. }
  516. new_cursor = MYMAX(MYMIN(new_cursor, length), 0);
  517. switch (op) {
  518. case CURSOROP_MOVE:
  519. m_cursor = new_cursor;
  520. m_cursor_len = 0;
  521. break;
  522. case CURSOROP_DELETE:
  523. if (m_cursor_len > 0) { // Delete selected text first
  524. m_line.erase(m_cursor, m_cursor_len);
  525. } else {
  526. m_cursor = MYMIN(new_cursor, old_cursor);
  527. m_line.erase(m_cursor, abs(new_cursor - old_cursor));
  528. }
  529. m_cursor_len = 0;
  530. break;
  531. case CURSOROP_SELECT:
  532. if (scope == CURSOROP_SCOPE_LINE) {
  533. m_cursor = 0;
  534. m_cursor_len = length;
  535. } else {
  536. m_cursor = MYMIN(new_cursor, old_cursor);
  537. m_cursor_len += abs(new_cursor - old_cursor);
  538. m_cursor_len = MYMIN(m_cursor_len, length - m_cursor);
  539. }
  540. break;
  541. }
  542. clampView();
  543. m_nick_completion_start = 0;
  544. m_nick_completion_end = 0;
  545. }
  546. void ChatPrompt::clampView()
  547. {
  548. s32 length = m_line.size();
  549. if (length + 1 <= m_cols)
  550. {
  551. m_view = 0;
  552. }
  553. else
  554. {
  555. m_view = MYMIN(m_view, length + 1 - m_cols);
  556. m_view = MYMIN(m_view, m_cursor);
  557. m_view = MYMAX(m_view, m_cursor - m_cols + 1);
  558. m_view = MYMAX(m_view, 0);
  559. }
  560. }
  561. ChatBackend::ChatBackend():
  562. m_console_buffer(500),
  563. m_recent_buffer(6),
  564. m_prompt(L"]", 500)
  565. {
  566. }
  567. void ChatBackend::addMessage(std::wstring name, std::wstring text)
  568. {
  569. // Note: A message may consist of multiple lines, for example the MOTD.
  570. text = translate_string(text);
  571. WStrfnd fnd(text);
  572. while (!fnd.at_end())
  573. {
  574. std::wstring line = fnd.next(L"\n");
  575. m_console_buffer.addLine(name, line);
  576. m_recent_buffer.addLine(name, line);
  577. }
  578. }
  579. void ChatBackend::addUnparsedMessage(std::wstring message)
  580. {
  581. // TODO: Remove the need to parse chat messages client-side, by sending
  582. // separate name and text fields in TOCLIENT_CHAT_MESSAGE.
  583. if (message.size() >= 2 && message[0] == L'<')
  584. {
  585. std::size_t closing = message.find_first_of(L'>', 1);
  586. if (closing != std::wstring::npos &&
  587. closing + 2 <= message.size() &&
  588. message[closing+1] == L' ')
  589. {
  590. std::wstring name = message.substr(1, closing - 1);
  591. std::wstring text = message.substr(closing + 2);
  592. addMessage(name, text);
  593. return;
  594. }
  595. }
  596. // Unable to parse, probably a server message.
  597. addMessage(L"", message);
  598. }
  599. ChatBuffer& ChatBackend::getConsoleBuffer()
  600. {
  601. return m_console_buffer;
  602. }
  603. ChatBuffer& ChatBackend::getRecentBuffer()
  604. {
  605. return m_recent_buffer;
  606. }
  607. EnrichedString ChatBackend::getRecentChat()
  608. {
  609. EnrichedString result;
  610. for (u32 i = 0; i < m_recent_buffer.getLineCount(); ++i)
  611. {
  612. const ChatLine& line = m_recent_buffer.getLine(i);
  613. if (i != 0)
  614. result += L"\n";
  615. if (!line.name.empty()) {
  616. result += L"<";
  617. result += line.name;
  618. result += L"> ";
  619. }
  620. result += line.text;
  621. }
  622. return result;
  623. }
  624. ChatPrompt& ChatBackend::getPrompt()
  625. {
  626. return m_prompt;
  627. }
  628. void ChatBackend::reformat(u32 cols, u32 rows)
  629. {
  630. m_console_buffer.reformat(cols, rows);
  631. // no need to reformat m_recent_buffer, its formatted lines
  632. // are not used
  633. m_prompt.reformat(cols);
  634. }
  635. void ChatBackend::clearRecentChat()
  636. {
  637. m_recent_buffer.clear();
  638. }
  639. void ChatBackend::step(float dtime)
  640. {
  641. m_recent_buffer.step(dtime);
  642. m_recent_buffer.deleteByAge(60.0);
  643. // no need to age messages in anything but m_recent_buffer
  644. }
  645. void ChatBackend::scroll(s32 rows)
  646. {
  647. m_console_buffer.scroll(rows);
  648. }
  649. void ChatBackend::scrollPageDown()
  650. {
  651. m_console_buffer.scroll(m_console_buffer.getRows());
  652. }
  653. void ChatBackend::scrollPageUp()
  654. {
  655. m_console_buffer.scroll(-(s32)m_console_buffer.getRows());
  656. }