瀏覽代碼

Resolve "User mode prompt doesn't get properly redrawn after output"

Sander, Paul 4 年之前
父節點
當前提交
69f3d1b2d0
共有 2 個文件被更改,包括 18 次插入5 次删除
  1. 5 5
      cli/src/ioman.cpp
  2. 13 0
      cli/src/userioman.cpp

+ 5 - 5
cli/src/ioman.cpp

@@ -535,9 +535,9 @@ void ioman_readlineHandler(char *line) {
 /* main user input loop */
 void IoMan::run() {
 	printMessage("IoMan::run() begin", debug);
-	struct pollfd inPipeStatus;
-	inPipeStatus.fd = STDIN_FILENO;
-	inPipeStatus.events = POLLIN;
+	struct pollfd inpipestatus;
+	inpipestatus.fd = STDIN_FILENO;
+	inpipestatus.events = POLLIN;
 
 	runmain = true;
 
@@ -548,9 +548,9 @@ void IoMan::run() {
 	while (runmain) {
 		mainmutex.unlock();
 
-		poll(&inPipeStatus, 1, 100);
+		poll(&inpipestatus, 1, 100);
 
-		if (inPipeStatus.revents & POLLIN) {
+		if (inpipestatus.revents & POLLIN) {
 			rl_callback_read_char();
 		}
 		if (!connected)

+ 13 - 0
cli/src/userioman.cpp

@@ -37,6 +37,13 @@ UserIoMan::~UserIoMan() { delete reader; }
 void UserIoMan::printMessage(std::string msg, OutMsgType type) {
 	Json::Value root;
 	msgmutex.lock();
+
+	char *savedline = rl_copy_text(0, rl_end);
+	int savedpoint = rl_point;
+	rl_set_prompt("");
+	rl_replace_line("", 0);
+	rl_redisplay();
+
 	switch (type) {
 	case normal:
 	case error: {
@@ -54,7 +61,13 @@ void UserIoMan::printMessage(std::string msg, OutMsgType type) {
 		break;
 	}
 	}
+
+	rl_set_prompt(getCmdPrompt().c_str());
+	rl_replace_line(savedline, 0);
+	rl_point = savedpoint;
 	rl_redisplay();
+	free(savedline);
+
 	msgmutex.unlock();
 }