MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / IConsoleHistoryAdd

Function IConsoleHistoryAdd

src/console_gui.cpp:453–470  ·  view source on GitHub ↗

* Add the entered line into the history so you can look it back * scroll, etc. Put it to the beginning as it is the latest text * @param cmd Text to be entered into the 'history' * @return the command to execute */

Source from the content-addressed store, hash-verified

451 * @return the command to execute
452 */
453static std::optional<std::string_view> IConsoleHistoryAdd(std::string_view cmd)
454{
455 /* Strip all spaces at the begin */
456 while (!cmd.empty() && IsWhitespace(cmd[0])) cmd.remove_prefix(1);
457
458 /* Do not put empty command in history */
459 if (cmd.empty()) return std::nullopt;
460
461 /* Do not put in history if command is same as previous */
462 if (_iconsole_history.empty() || _iconsole_history.front() != cmd) {
463 _iconsole_history.emplace_front(cmd);
464 while (_iconsole_history.size() > ICON_HISTORY_SIZE) _iconsole_history.pop_back();
465 }
466
467 /* Reset the history position */
468 IConsoleResetHistoryPos();
469 return _iconsole_history.front();
470}
471
472/**
473 * Navigate Up/Down in the history of typed commands

Callers 1

OnKeyPressMethod · 0.85

Calls 5

IsWhitespaceFunction · 0.85
IConsoleResetHistoryPosFunction · 0.85
pop_backMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected