* 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 */
| 451 | * @return the command to execute |
| 452 | */ |
| 453 | static 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 |
no test coverage detected