| 49 | { |
| 50 | public: |
| 51 | UserInterface(IoContext& iocontext) : scheduler(iocontext) |
| 52 | { |
| 53 | auto rootMenu = make_unique< Menu >("cli"); |
| 54 | rootMenu->Insert( |
| 55 | "hello", |
| 56 | [](std::ostream& out){ out << "Hello, world\n"; }, |
| 57 | "Print hello world" ); |
| 58 | colorCmd = rootMenu->Insert( |
| 59 | "color", |
| 60 | [&](std::ostream& out) |
| 61 | { |
| 62 | out << "Colors ON\n"; |
| 63 | SetColor(); |
| 64 | colorCmd.Disable(); |
| 65 | nocolorCmd.Enable(); |
| 66 | }, |
| 67 | "Enable colors in the cli" ); |
| 68 | nocolorCmd = rootMenu->Insert( |
| 69 | "nocolor", |
| 70 | [&](std::ostream& out) |
| 71 | { |
| 72 | out << "Colors OFF\n"; |
| 73 | SetNoColor(); |
| 74 | colorCmd.Enable(); |
| 75 | nocolorCmd.Disable(); |
| 76 | }, |
| 77 | "Disable colors in the cli" ); |
| 78 | |
| 79 | cli = make_unique<Cli>(std::move(rootMenu)); |
| 80 | // global exit action |
| 81 | cli->ExitAction( [](auto& out){ out << "Goodbye and thanks for all the fish.\n"; } ); |
| 82 | // std exception custom handler |
| 83 | cli->StdExceptionHandler( |
| 84 | [](std::ostream& out, const std::string& cmd, const std::exception& e) |
| 85 | { |
| 86 | out << "Exception caught in cli handler: " |
| 87 | << e.what() |
| 88 | << " handling command: " |
| 89 | << cmd |
| 90 | << ".\n"; |
| 91 | } |
| 92 | ); |
| 93 | |
| 94 | localSession = make_unique<CliLocalTerminalSession>(*cli, scheduler, std::cout, 200); |
| 95 | localSession->ExitAction( |
| 96 | [this](auto& out) // session exit action |
| 97 | { |
| 98 | out << "Closing App...\n"; |
| 99 | scheduler.Stop(); |
| 100 | } |
| 101 | ); |
| 102 | } |
| 103 | private: |
| 104 | BoostAsioScheduler scheduler; |
| 105 | unique_ptr<Cli> cli; |
nothing calls this directly
no test coverage detected