Jelajahi Sumber

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

Sander, Paul 4 tahun lalu
induk
melakukan
69f3d1b2d0
2 mengubah file dengan 18 tambahan dan 5 penghapusan
  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();
 }