MCPcopy Create free account
hub / github.com/daniele77/cli / NewCommand

Method NewCommand

include/cli/detail/commandprocessor.h:91–162  ·  view source on GitHub ↗

* @brief Process a new command. * * @param s The symbol and string representing the command. */

Source from the content-addressed store, hash-verified

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 );

Callers

nothing calls this directly

Calls 14

CommonPrefixFunction · 0.85
ExitMethod · 0.80
SetLineMethod · 0.80
NextCmdMethod · 0.80
GetLineMethod · 0.80
PreviousCmdMethod · 0.80
OutStreamMethod · 0.80
ResetCursorMethod · 0.80
DeactivateInputMethod · 0.45
FeedMethod · 0.45
PromptMethod · 0.45
ActivateInputMethod · 0.45

Tested by

no test coverage detected