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

Method UserInterface

examples/standaloneasio_nonowner_iocontext.cpp:46–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

SetColorFunction · 0.85
SetNoColorFunction · 0.85
StdExceptionHandlerMethod · 0.80
whatMethod · 0.80
InsertMethod · 0.45
DisableMethod · 0.45
EnableMethod · 0.45
ExitActionMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected