add better line editing capability to ws connect, thanks to linenoise-cpp

This commit is contained in:
Benjamin Sergeant
2019-07-25 11:54:50 -07:00
parent 18485a74e5
commit c300866dcc
10 changed files with 2839 additions and 10 deletions

View File

@ -23,6 +23,7 @@ include_directories(ws ..)
include_directories(ws ../third_party)
include_directories(ws ../third_party/statsd-client-cpp/src)
include_directories(ws ../third_party/spdlog/include)
include_directories(ws ../third_party/cpp-linenoise)
include_directories(ws snake)
if (UNIX)

View File

@ -9,6 +9,9 @@
#include <ixwebsocket/IXWebSocket.h>
#include <ixwebsocket/IXSocket.h>
#include "linenoise.hpp"
namespace ix
{
class WebSocketConnect
@ -148,30 +151,33 @@ namespace ix
while (true)
{
std::string text;
std::cout << "> " << std::flush;
std::getline(std::cin, text);
// Read line
std::string line;
auto quit = linenoise::Readline("> ", line);
if (text == "/stop")
if (quit)
{
break;
}
if (line == "/stop")
{
std::cout << "Stopping connection..." << std::endl;
webSocketChat.stop();
continue;
}
if (text == "/start")
if (line == "/start")
{
std::cout << "Starting connection..." << std::endl;
webSocketChat.start();
continue;
}
if (!std::cin)
{
break;
}
webSocketChat.sendMessage(line);
webSocketChat.sendMessage(text);
// Add text to history
linenoise::AddHistory(line.c_str());
}
std::cout << std::endl;