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

Method UserInterface

examples/boostasio_nonowner_iocontext.cpp:51–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49{
50public:
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 }
103private:
104 BoostAsioScheduler scheduler;
105 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