Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 改为“r”(正如另一个答案中所建议的)。在使用“\r”代码一段时间后,我改变了主意……我更喜欢这个,因为它不需要在末尾加空格(我更喜欢在服务器输出之前加空格,所以这个解决方案最适合我,更不用说它是对我最初问题的最直接的答案).不幸的是,诅咒和阅读不能混为一_C_Readline - Fatal编程技术网

C 改为“r”(正如另一个答案中所建议的)。在使用“\r”代码一段时间后,我改变了主意……我更喜欢这个,因为它不需要在末尾加空格(我更喜欢在服务器输出之前加空格,所以这个解决方案最适合我,更不用说它是对我最初问题的最直接的答案).不幸的是,诅咒和阅读不能混为一

C 改为“r”(正如另一个答案中所建议的)。在使用“\r”代码一段时间后,我改变了主意……我更喜欢这个,因为它不需要在末尾加空格(我更喜欢在服务器输出之前加空格,所以这个解决方案最适合我,更不用说它是对我最初问题的最直接的答案).不幸的是,诅咒和阅读不能混为一,c,readline,C,Readline,改为“r”(正如另一个答案中所建议的)。在使用“\r”代码一段时间后,我改变了主意……我更喜欢这个,因为它不需要在末尾加空格(我更喜欢在服务器输出之前加空格,所以这个解决方案最适合我,更不用说它是对我最初问题的最直接的答案).不幸的是,诅咒和阅读不能混为一谈。请参阅(我也问过)。如果您建议我将我的readline应用程序也设置为curses应用程序,这似乎是不可能的:我尝试了rl\u reset\u line\u state()和rl\u clear\u message()。这两种方法都没有帮助


改为“r”(正如另一个答案中所建议的)。在使用“\r”代码一段时间后,我改变了主意……我更喜欢这个,因为它不需要在末尾加空格(我更喜欢在服务器输出之前加空格,所以这个解决方案最适合我,更不用说它是对我最初问题的最直接的答案).不幸的是,诅咒和阅读不能混为一谈。请参阅(我也问过)。如果您建议我将我的readline应用程序也设置为curses应用程序,这似乎是不可能的:我尝试了
rl\u reset\u line\u state()
rl\u clear\u message()
。这两种方法都没有帮助。如果可能的话,我会尝试更多的readline函数,但我想我已经尝试过很多看起来很有趣的函数了。@John Zwinck:我还没有对readline库进行足够的研究,以确定这些函数是否有用。如果readline不能使用curses(这并不奇怪),那么有两种可能性:(1)忽略这个建议,或者(2)修改应用程序以使用curses而不是readline。这(选项2)肯定是更多的工作。这很聪明,我实现了它并使用了一段时间。最后我发现我更喜欢pmg发布的“\b\b”解决方案。但是,好的!这应该是公认的解决方案。这可能很奇怪,但它应该正确处理多行输入。
rl_callback_handler_install("", on_readline_input);
user input
SERVER OUTPUT
SERVER OUTPUT
user input
SERVER OUTPUT
user input
SERVER OUTPUT
user inSERVER OUTPUT
put
SERVER OUTPUT
user input
SERVER OUTPUT
user in
SERVER OUTPUT
user input
SERVER OUTPUT
user input
SERVER OUTPUT
user input
SERVER OUTPUT
user input
SERVER OUTPUT
user input
SERVER OUTPUT
user input - INCOMPLETE
SERVER OUTPUT
user input
SERVER OUTPUT
Hello, world!
             ^ /* active position */ /* now write "\b \b" */
               /* '\b' moves the active position back;
               // ' ' writes a space (erases the '!')
               // and another '\b' to go back again */
Hello, world
            ^ /* active position */ /* now write "\b \b" again */
Hello, worl
           ^ /* active position */ /* now write "\b \b" 4 times ... */
Hello, 
       ^ /* active position */ /* now write "Jim." */
Hello, Jim.
           ^ /* active position */
> 1   The active position is that location on a display device where the next character output by
>     the fputc function would appear. The intent of writing a printing character (as defined
>     by the isprint function) to a display device is to display a graphic representation of
>     that character at the active position and then advance the active position to the next
>     position on the current line. The direction of writing is locale-specific. If the active
>     position is at the final position of a line (if there is one), the behavior of the display devic e
>     is unspecified.
>  
> 2   Alphabetic escape sequences representing nongraphic characters in the execution
>     character set are intended to produce actions on display devices as follows:
>     \a (alert) Produces an audible or visible alert without changing the active position.
>     \b (backspace) Moves the active position to the previous position on the current line. If
>        the active position is at the initial position of a line, the behavior of the display
>        device is unspecified.
>     \f ( form feed) Moves the active position to the initial position at the start of the next
>        logical page.
>     \n (new line) Moves the active position to the initial position of the next line.
>     \r (carriage return) Moves the active position to the initial position of the current line.
>     \t (horizontal tab) Moves the active position to the next horizontal tabulation position
>        on the current line. If the active position is at or past the last defined horizontal
>        tabulation position, the behavior of the display device is unspecified.
>     \v (vertical tab) Moves the active position to the initial position of the next vertical
>         tabulation position. If the active position is at or past the last defined vertical
>         tabulation position, the behavior of the display device is unspecified.
>  
> 3   Each of these escape sequences shall produce a unique implementation-defined value
>     which can be stored in a single char object. The external representations in a text file
>     need not be identical to the internal representations, and are outside the scope of this
>     International Standard.
#include <unistd.h> 
#include <curses.h> 
#include <pthread.h> 

WINDOW *top, *bottom;

int win_update( WINDOW *win, void *data ){
  wprintw(win,"%s", (char*)data ); wrefresh(win);
  return 0;
}

void *top_thread( void *data ){
  char buff[1024];
  int i=0;
  while(1){
    snprintf(buff, 1024, "SERVER OUTPUT: %i\n", i++ );
    use_window( top, win_update, (void*)buff );
    sleep(1);
  }
  return NULL;
}

int main(){
  initscr();
  int maxy, maxx;
  getmaxyx( stdscr, maxy, maxx );

  top = newwin(maxy-1,maxx,0,0);
  wsetscrreg(top,0,maxy-1); idlok(top,1); scrollok(top,1);
  pthread_t top_tid;
  pthread_create(&top_tid, NULL, top_thread, NULL);

  bottom = newwin(1,maxx,maxy-1,0);
  char buff[1024], input[maxx];
  do{
    werase(bottom); wmove(bottom,0,0);
    wprintw(bottom,"input> " ); wrefresh(bottom);
    wgetnstr(bottom,input,sizeof(input));
    snprintf(buff, 1024, "user input: '%s'\n", input );
    use_window( top, win_update, (void*)buff );
  }while( input[0] != 'q' );

  endwin();
}
fprintf (stdout, "\r%-20s\n", "SERVER OUTPUT");
#include <readline/readline.h>
    #include <readline/history.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>

    const char const* prompt = "PROMPT> ";

    void printlog(int c) {
        char* saved_line;
        int saved_point;
        saved_point = rl_point;
        saved_line = rl_copy_text(0, rl_end);
        rl_set_prompt("");
        rl_replace_line("", 0);
        rl_redisplay();
        printf("Message: %d\n", c);
        rl_set_prompt(prompt);
        rl_replace_line(saved_line, 0);
        rl_point = saved_point;
        rl_redisplay();
        free(saved_line);
    }


    void handle_line(char* ch) {
        printf("%s\n", ch);
        add_history(ch);
    }

    int main() {
        int c = 1;

        printf("Start.\n");
        rl_callback_handler_install(prompt, handle_line);

        while (1) {
            if (((++c) % 5) == 0) {
                printlog(c);
            }

            usleep(10);
            rl_callback_read_char();
        }
        rl_callback_handler_remove();
    }
rl_clear_visible_line();
printf(...);
rl_reset_line_state();
rl_redisplay();