* @brief Process a new command. * * @param s The symbol and string representing the command. */
| 89 | * @param s The symbol and string representing the command. |
| 90 | */ |
| 91 | void NewCommand(const std::pair<Symbol, std::string>& s) |
| 92 | { |
| 93 | switch (s.first) |
| 94 | { |
| 95 | case Symbol::nothing: |
| 96 | { |
| 97 | break; |
| 98 | } |
| 99 | case Symbol::eof: |
| 100 | { |
| 101 | session.Exit(); |
| 102 | break; |
| 103 | } |
| 104 | case Symbol::command: |
| 105 | { |
| 106 | kb.DeactivateInput(); |
| 107 | session.Feed(s.second); |
| 108 | session.Prompt(); |
| 109 | kb.ActivateInput(); |
| 110 | break; |
| 111 | } |
| 112 | case Symbol::down: |
| 113 | { |
| 114 | terminal.SetLine(session.NextCmd()); |
| 115 | break; |
| 116 | } |
| 117 | case Symbol::up: |
| 118 | { |
| 119 | auto line = terminal.GetLine(); |
| 120 | terminal.SetLine(session.PreviousCmd(line)); |
| 121 | break; |
| 122 | } |
| 123 | case Symbol::tab: |
| 124 | { |
| 125 | auto line = terminal.GetLine(); |
| 126 | auto completions = session.GetCompletions(line); |
| 127 | |
| 128 | if (completions.empty()) |
| 129 | break; |
| 130 | if (completions.size() == 1) |
| 131 | { |
| 132 | terminal.SetLine(completions[0]+' '); |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | auto commonPrefix = CommonPrefix(completions); |
| 137 | if (commonPrefix.size() > line.size()) |
| 138 | { |
| 139 | terminal.SetLine(commonPrefix); |
| 140 | break; |
| 141 | } |
| 142 | session.OutStream() << '\n'; |
| 143 | std::string items; |
| 144 | std::for_each( completions.begin(), completions.end(), [&items](auto& cmd){ items += '\t' + cmd; } ); |
| 145 | session.OutStream() << items << '\n'; |
| 146 | session.Prompt(); |
| 147 | terminal.ResetCursor(); |
| 148 | terminal.SetLine( line ); |
nothing calls this directly
no test coverage detected