/* Does window event processing (e.g. exposure events). A noop for the tty and X window-ports. */ void curses_get_nh_event() { #ifdef PDCURSES if (is_termresized()) { resize_term(0, 0); getmaxyx(base_term, term_rows, term_cols); curses_create_main_windows(); curses_last_messages(); doredraw(); } #endif #ifdef NCURSES_VERSION /* Is there a better way to detect ncurses? */ if (is_term_resized(term_rows, term_cols)) { if (!isendwin()) { endwin(); } refresh(); getmaxyx(base_term, term_rows, term_cols); curses_create_main_windows(); curses_last_messages(); doredraw(); } #endif }
/*#DOC*/ int viewG_resizeWindow(int w, int h) { if (is_term_resized(h, w)) return ERR; if (OK == resizeterm(h, w)) { TERM_W = w; TERM_H = h; return OK; } return ERR; }
resize_term(int ToLines, int ToCols) { int result = OK; int was_stolen = (screen_lines - SP->_lines_avail); T((T_CALLED("resize_term(%d,%d) old(%d,%d)"), ToLines, ToCols, screen_lines, screen_columns)); if (is_term_resized(ToLines, ToCols)) { int myLines = screen_lines; int myCols = screen_columns; if (ToLines > screen_lines) { increase_size(myLines = ToLines, myCols, was_stolen); } if (ToCols > screen_columns) { increase_size(myLines, myCols = ToCols, was_stolen); } if (ToLines < myLines || ToCols < myCols) { decrease_size(ToLines, ToCols, was_stolen); } screen_lines = lines = ToLines; screen_columns = columns = ToCols; SP->_lines_avail = lines - was_stolen; if (SP->oldhash) { FreeAndNull(SP->oldhash); } if (SP->newhash) { FreeAndNull(SP->newhash); } } /* * Always update LINES, to allow for call from lib_doupdate.c which * needs to have the count adjusted by the stolen (ripped off) lines. */ LINES = ToLines - was_stolen; COLS = ToCols; returnCode(result); }
/** Control keyboard input. * @return Return 0 if error apears (terminal size changed). Else return value of button which is selected. */ int CSMenu::control ( void ){ int c; while(true){ c = getch(); if(c==KEY_UP){ m_Index--; if(m_Index < 0)m_Index = 0; this->printAll(); }else if(c == KEY_DOWN){ m_Index++; if(m_Index >= m_BCount) m_Index--; this->printAll(); }else if(c == 10){ return m_Buttons[m_Index].m_Value; } if(is_term_resized(m_Lines, m_Cols)) return 0; refresh(); } return 0; }
resizeterm(int ToLines, int ToCols) { int result = OK; SP->_sig_winch = FALSE; T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"), ToLines, ToCols, screen_lines, screen_columns)); if (is_term_resized(ToLines, ToCols)) { #if USE_SIGWINCH ungetch(KEY_RESIZE); /* so application can know this */ clearok(curscr, TRUE); /* screen contents are unknown */ #endif result = resize_term(ToLines, ToCols); } returnCode(result); }
// Wait for input from user, quit if recieved 'q' keypress void Menu::get_keyboard_input() { while (! dying) { // Check if we need to resize window display if (is_term_resized(screen_lines, screen_cols)) { reframe_resized_window(); } // Check if we need to update content (i.e. been longer than 5 seconds) std::chrono::steady_clock::time_point current_time = std::chrono::steady_clock::now(); if (current_time > (last_update + std::chrono::seconds(5))) { get_lines(); } // Update window display after each key press print_window(); // This is blocking ch = getch(); switch(ch) { case KEY_UP: case 'k': move_cursor_up(); break; case KEY_DOWN: case 'j': move_cursor_down(); break; case KEY_LEFT: case 'h': move_cursor_left(); break; case KEY_RIGHT: case 'l': move_cursor_right(); break; case 'q': endwin(); dying = true; break; case KEY_PPAGE: handle_page_up(); break; case KEY_NPAGE: handle_page_down(); break; case KEY_HOME: handle_home(); break; case KEY_END: handle_end(); break; case KEY_ENTER: case 10: case 13: handle_enter_key(); break; default: // Uncoded key, ignore break; } } }
void check_resize() /* {{{ */ { /* check for a screen resize and handle it */ if (is_term_resized(rows, cols)) handle_resize(); } /* }}} */
resize_term(int ToLines, int ToCols) { int result = OK; int was_stolen = (screen_lines - SP->_lines_avail); T((T_CALLED("resize_term(%d,%d) old(%d,%d)"), ToLines, ToCols, screen_lines, screen_columns)); if (is_term_resized(ToLines, ToCols)) { int myLines = current_lines = screen_lines; int myCols = current_cols = screen_columns; #ifdef TRACE if (_nc_tracing & TRACE_UPDATE) show_window_sizes("before"); #endif if (ToLines > screen_lines) { increase_size(myLines = ToLines, myCols, was_stolen); current_lines = myLines; current_cols = myCols; } if (ToCols > screen_columns) { increase_size(myLines, myCols = ToCols, was_stolen); current_lines = myLines; current_cols = myCols; } if (ToLines < myLines || ToCols < myCols) { decrease_size(ToLines, ToCols, was_stolen); } screen_lines = lines = ToLines; screen_columns = columns = ToCols; SP->_lines_avail = lines - was_stolen; if (SP->oldhash) { FreeAndNull(SP->oldhash); } if (SP->newhash) { FreeAndNull(SP->newhash); } #ifdef TRACE if (_nc_tracing & TRACE_UPDATE) { LINES = ToLines - was_stolen; COLS = ToCols; show_window_sizes("after"); } #endif } /* * Always update LINES, to allow for call from lib_doupdate.c which * needs to have the count adjusted by the stolen (ripped off) lines. */ LINES = ToLines - was_stolen; COLS = ToCols; returnCode(result); }