如何在面板中显示用户输入

How to display the user input in a panel

我实际上是在控制台中编写一个编辑器,比如 nano。 为了获得用户输入,我在面板中放置了一个 window,并使用函数 mvwprintw 来询问用户输入。经过大量测试,我确信输入正在获取,但在用户键入时它没有显示。 有人有解决这个问题的想法吗? 谢谢。

void keybord::init_panel_window()

{   

//prepare the window     

int x, y, i;

bool show_it=true;

char label[1000];

y = 2;

x = 10;

my_wins = newwin(10, 40, y, x);

 field[0] = new_field(1, 10, y, x, 0, 0);

 field[1] = NULL;

   field[2] = NULL;

 //char user_input[1000];

//attach panel to window and put this panel on top
my_panels = new_panel(my_wins); 
set_panel_userptr(my_panels, &show_it);
update_panels();
doupdate();

sprintf(label, " enter your message ");
//show the window by printing box arround window 
int startx, starty, height, width;
getbegyx(my_wins, starty, startx);
getmaxyx(my_wins, height, width);
box(my_wins, 0, 0);
mvwaddch(my_wins, 2, 0, ACS_LTEE); 
mvwhline(my_wins, 2, 1, ACS_HLINE, width - 2); 
mvwaddch(my_wins, 2, width - 1, ACS_RTEE); 
print_in_middle(my_wins, 1, 0, width, label, COLOR_PAIR(2));  
//show_panel(my_panels);       
}`


  void keybord::print_in_middle(WINDOW *win, int starty, int startx, int    width, char *string, chtype color)
  {       int length, x, y;
      float temp;
      char user_input[100];


    show_panel(my_panels); //show the panel 

    if(win == NULL)
            win = stdscr;
    getyx(win, y, x);
    if(startx != 0)
            x = startx;
    if(starty != 0)
            y = starty;
    if(width == 0)
            width = 80;

    length = strlen(string);
    temp = (width - length)/ 2;
    x = startx + (int)temp;

   // mvwprintw(win, y, x, " %s", string);
    mvwscanw(win,y+5,x+4,"%s",user_input); //USER INPUT , IT'S WORKINK BUT THE INPUT IS NOT DISPLAYING WHILE THE USER IS TYPING 
    refresh();
    printw("value : %s************************* ",user_input );
      wattron(win, color);
     mvwprintw(win, y, x, " %s", user_input);
    refresh();
    wattroff(win, color);
   // hide_panel(my_panels);
}

您的完整程序未显示,但 simple/likely 的解释是在初始化时调用 noecho(),并使用标准屏幕 stdscr,例如,通过传递一个NULL 作为 keybord::print_in_middle().

的第一个参数

如果 keybord::print_in_middle()win 参数启用了 echo(),那么它将按您的预期运行。