Commit 8ad0767a authored by aligungr's avatar aligungr

gNB CLI improvements

parent b7a56d6d
...@@ -214,9 +214,15 @@ static bool HandleMessage(const app::CliMessage &msg, bool isOneShot) ...@@ -214,9 +214,15 @@ static bool HandleMessage(const app::CliMessage &msg, bool isOneShot)
std::cout << "\x1b[1m"; std::cout << "\x1b[1m";
std::cout << std::string(92, '-') << std::endl; std::cout << std::string(92, '-') << std::endl;
std::string line{}; std::string line{};
bool isEof{};
std::vector<std::string> tokens{}; std::vector<std::string> tokens{};
if (!opt::ReadLine(std::cin, std::cout, line, tokens)) if (!opt::ReadLine(std::cin, std::cout, line, tokens, isEof))
{
if (isEof)
exit(0); exit(0);
else
std::cout << "ERROR: Invalid command" << std::endl;
}
std::cout << "\x1b[0m"; std::cout << "\x1b[0m";
if (line.empty()) if (line.empty())
continue; continue;
......
...@@ -361,17 +361,22 @@ opt::ExpansionResult opt::PerformExpansion(const std::string &command, std::vect ...@@ -361,17 +361,22 @@ opt::ExpansionResult opt::PerformExpansion(const std::string &command, std::vect
return ExpansionResult::UNSPECIFIED_ERROR; return ExpansionResult::UNSPECIFIED_ERROR;
} }
bool opt::ReadLine(std::istream &istream, std::ostream &ostream, std::string &line, std::vector<std::string> &tokens) bool opt::ReadLine(std::istream &istream, std::ostream &ostream, std::string &line, std::vector<std::string> &tokens,
bool &isEof)
{ {
ostream << "$ "; ostream << "$ ";
std::string input{}; std::string input{};
isEof = false;
while (true) while (true)
{ {
std::string ln{}; std::string ln{};
std::getline(istream, ln); std::getline(istream, ln);
if (!istream) if (!istream)
{
isEof = true;
return false; return false;
}
input += ln; input += ln;
std::vector<std::string> vec{}; std::vector<std::string> vec{};
......
...@@ -127,6 +127,7 @@ enum class ExpansionResult ...@@ -127,6 +127,7 @@ enum class ExpansionResult
ExpansionResult PerformExpansion(const std::string &command, std::vector<std::string> &argv); ExpansionResult PerformExpansion(const std::string &command, std::vector<std::string> &argv);
bool ReadLine(std::istream &istream, std::ostream &ostream, std::string &line, std::vector<std::string> &tokens); bool ReadLine(std::istream &istream, std::ostream &ostream, std::string &line, std::vector<std::string> &tokens,
bool &isEof);
} // namespace opt } // namespace opt
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment