| 877 | // CliSession implementation |
| 878 | |
| 879 | inline CliSession::CliSession(Cli& _cli, std::ostream& _out, std::size_t historySize) : |
| 880 | cli(_cli), |
| 881 | coutPtr(Cli::CoutPtr()), |
| 882 | current(cli.RootMenu()), |
| 883 | globalScopeMenu(std::make_unique< Menu >()), |
| 884 | out(_out), |
| 885 | history(historySize) |
| 886 | { |
| 887 | history.LoadCommands(cli.GetCommands()); |
| 888 | |
| 889 | coutPtr->Register(out); |
| 890 | globalScopeMenu->Insert( |
| 891 | "help", |
| 892 | [this](std::ostream&){ Help(); }, |
| 893 | "This help message" |
| 894 | ); |
| 895 | globalScopeMenu->Insert( |
| 896 | "exit", |
| 897 | [this](std::ostream&){ Exit(); }, |
| 898 | "Quit the session" |
| 899 | ); |
| 900 | globalScopeMenu->Insert( |
| 901 | "history", |
| 902 | [this](std::ostream&){ ShowHistory(); }, |
| 903 | "Show the history" |
| 904 | ); |
| 905 | globalScopeMenu->Insert( |
| 906 | "!", {"history entry index"}, |
| 907 | [this](std::ostream&, unsigned cmdIndex){ ExecFromHistory(cmdIndex); }, |
| 908 | "Exec a command by index in the history" |
| 909 | ); |
| 910 | } |
| 911 | |
| 912 | inline void CliSession::Feed(const std::string& cmd) |
| 913 | { |
nothing calls this directly
no test coverage detected