/* * The common entry for processing command. */ static void cmd_received(cmd_t *cmd, boolean_t *quit, struct timespec *timeout) { boolean_t badcmd, execute; int cmd_id = CMD_ID(cmd); execute = B_TRUE; *quit = B_FALSE; switch (cmd_id) { case CMD_QUIT_ID: *quit = B_TRUE; return; case CMD_RESIZE_ID: /* * The screen resize signal would trigger this * command. Destroy existing screen and curses * resources and then re-init the curses resources. */ win_fix_fini(); page_win_destroy(); reg_curses_fini(); if (reg_curses_init(B_FALSE)) { win_fix_init(); } else { execute = B_FALSE; } timeout_set(timeout, DISP_DEFAULT_INTVAL); break; case CMD_REFRESH_ID: /* * User hit the hotkey 'R' to refresh current window. */ timeout_set(timeout, DISP_DEFAULT_INTVAL); break; } if (execute) { cmd_execute(cmd, &badcmd); } }
/* * Initialization for libcurses. */ boolean_t reg_curses_init(boolean_t first_load) { (void) initscr(); (void) refresh(); (void) start_color(); (void) keypad(stdscr, TRUE); (void) nonl(); (void) cbreak(); (void) noecho(); (void) curs_set(0); getmaxyx(stdscr, g_scr_height, g_scr_width); /* * Set a window resize signal handler. */ (void) signal(SIGWINCH, disp_on_resize); s_curses_init = B_TRUE; if ((g_scr_height < 24 || g_scr_width < 80)) { if (!first_load) { (void) mvwprintw(stdscr, 0, 0, "Terminal size is too small."); (void) mvwprintw(stdscr, 1, 0, "Please resize it to 80x24 or larger."); (void) refresh(); } else { reg_curses_fini(); stderr_print("Terminal size is too small " "(resize it to 80x24 or larger).\n"); } dump_write("\n%s\n", "Terminal size is too small."); dump_write("%s\n", "Please resize it to 80x24 or larger."); return (B_FALSE); } return (B_TRUE); }
/* ARGSUSED */ static void * cons_handler(void *arg) { int c, cmd_id; unsigned char ch; if (!reg_curses_init(B_TRUE)) { goto L_EXIT; } win_fix_init(); /* * Excute "home" command. It shows the NumaTop default page. */ disp_go_home(); for (;;) { FD_ZERO(&s_cons_ctl.fds); FD_SET(STDIN_FILENO, &s_cons_ctl.fds); FD_SET(s_cons_ctl.pipe[0], &s_cons_ctl.fds); /* * Wait one character from "stdin" or pipe. */ if (select(s_cons_ctl.pipe[0] + 1, &s_cons_ctl.fds, NULL, NULL, NULL) > 0) { if (FD_ISSET(s_cons_ctl.pipe[0], &s_cons_ctl.fds)) { if (read(s_cons_ctl.pipe[0], &ch, 1) == 1) { /* * Character is from pipe. */ if (ch == PIPE_CHAR_QUIT) { /* * Received a QUIT notification, * "console thread" will be quit */ debug_print(NULL, 2, "cons: " "received PIPE_CHAR_QUIT\n"); break; } if (ch == PIPE_CHAR_RESIZE) { /* * Send the "RESIZE" command * to "display thread". */ (void) pthread_mutex_lock( &s_disp_ctl.mutex); CMD_ID_SET(&s_disp_ctl.cmd, CMD_RESIZE_ID); dispthr_flagset_nolock(DISP_FLAG_CMD); (void) pthread_mutex_unlock( &s_disp_ctl.mutex); } } } else { /* * Character is from STDIN. */ if ((c = getch()) == ERR) { /* * It's possile if the associated * terminal is lost. */ debug_print(NULL, 2, "cons: " "getch() failed.\n"); break; } ch = tolower((unsigned char)c); dump_write("\n<-- User hit the key '%c' " "(ascii = %d) -->\n", ch, (int)ch); cmd_id = cmd_id_get(ch); if (cmd_id != CMD_INVALID_ID) { /* * The character is a command. Send * the command to 'disp thread'. */ (void) pthread_mutex_lock( &s_disp_ctl.mutex); CMD_ID_SET(&s_disp_ctl.cmd, cmd_id); dispthr_flagset_nolock(DISP_FLAG_CMD); (void) pthread_mutex_unlock( &s_disp_ctl.mutex); } else { /* * Hit the keys 'UP'/'DOWN'/'ENTER' */ switch (ch) { case 2: /* KEY DOWN */ dispthr_flagset_lock( DISP_FLAG_SCROLLDOWN); break; case 3: /* KEY UP */ dispthr_flagset_lock( DISP_FLAG_SCROLLUP); break; case 13: /* enter. */ dispthr_flagset_lock( DISP_FLAG_SCROLLENTER); break; default: break; } } } } } reg_curses_fini(); L_EXIT: debug_print(NULL, 2, "cons thread is exiting\n"); return (NULL); }