int main(void) { struct winsize ws; /* get the size of the terminal connected to stdout */ if (ioctl(1, TIOCGWINSZ, &ws)) { perror("failed to get window size"); return 1; } SLtt_get_terminfo(); SLtt_Screen_Rows = ws.ws_row; SLtt_Screen_Cols = ws.ws_col; SLsmg_init_smg(); SLang_init_tty(-1, 0, 1); drawCharSet(0, 0, "Normal Character Set"); drawCharSet(40, 1, "Alternate Character Set"); SLsmg_refresh(); SLang_getkey(); SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); SLsmg_refresh(); SLsmg_reset_smg(); SLang_reset_tty(); return 0; }
int SLsmg_resume_smg (void) { BLOCK_SIGNALS; if (Smg_Suspended == 0) { UNBLOCK_SIGNALS; return 0; } Smg_Suspended = 0; if (-1 == (*tt_init_video) ()) { UNBLOCK_SIGNALS; return -1; } Cls_Flag = 1; SLsmg_touch_screen (); SLsmg_refresh (); UNBLOCK_SIGNALS; return 0; }
void newtResizeScreen(int redraw) { newtPushHelpLine(""); SLtt_get_screen_size(); SLang_init_tty(0, 0, 0); SLsmg_touch_lines (0, SLtt_Screen_Rows - 1); /* I don't know why I need this */ SLsmg_refresh(); newtPopHelpLine(); if (redraw) SLsmg_refresh(); }
int main(void) { struct winsize ws; /* get the size of the terminal connected to stdout */ if (ioctl(1, TIOCGWINSZ, &ws)) { perror("failed to get window size"); return 1; } SLtt_get_terminfo(); SLtt_Screen_Rows = ws.ws_row; SLtt_Screen_Cols = ws.ws_col; SLsmg_init_smg(); /* heart of the program goes here */ SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); SLsmg_refresh(); SLsmg_reset_smg(); SLang_reset_tty(); return 0; }
void ui_progress__update(u64 curr, u64 total, const char *title) { int bar, y; /* * FIXME: We should have a per UI backend way of showing progress, * stdio will just show a percentage as NN%, etc. */ if (use_browser <= 0) return; if (total == 0) return; ui__refresh_dimensions(true); pthread_mutex_lock(&ui__lock); y = SLtt_Screen_Rows / 2 - 2; SLsmg_set_color(0); SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols); SLsmg_gotorc(y++, 1); SLsmg_write_string((char *)title); SLsmg_set_color(HE_COLORSET_SELECTED); bar = ((SLtt_Screen_Cols - 2) * curr) / total; SLsmg_fill_region(y, 1, 1, bar, ' '); SLsmg_refresh(); pthread_mutex_unlock(&ui__lock); }
/* * Suspend / Resume */ static errr Term_xtra_sla_alive(int v) { /* Suspend */ if (!v) { /* Oops */ if (!slang_on) return (1); /* We are now off */ slang_on = FALSE; /* Shut down (temporarily) */ SLsmg_reset_smg(); SLang_reset_tty(); } /* Resume */ else { /* Oops */ if (slang_on) return (1); /* Fix the screen */ SLsmg_refresh(); /* Note that we are on */ slang_on = TRUE; } /* Success */ return (0); }
/** * @brief Closedown the newt library, tidying screen. * @returns int , 0. (no errors reported) */ int newtFinished(void) { if (currentWindow) { for (; currentWindow >= windowStack; currentWindow--) { free(currentWindow->buffer); free(currentWindow->title); } currentWindow = NULL; } if (currentHelpline) { for (; currentHelpline >= helplineStack; currentHelpline--) free(*currentHelpline); currentHelpline = NULL; } freeKeymap(); SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); newtCursorOn(); SLsmg_refresh(); SLsmg_reset_smg(); SLang_reset_tty(); return 0; }
void point_cursor (int c) { int r, row; Line *tthis, *cline; if (JWindow->trashed) return; cline = CLine; #if JED_HAS_LINE_ATTRIBUTES if (cline->flags & JED_LINE_HIDDEN) { cline = jed_find_non_hidden_line (cline); if (cline != NULL) c = Non_Hidden_Point; } #endif r = JWindow->sy + 1; Point_Cursor_Flag = 0; for (row = r; row < r + JWindow->rows; row++) { tthis = JScreen[row-1].line; if (tthis == NULL) break; if ((tthis == cline) || (tthis == &Eob_Line)) { r = row; break; } } if (Point >= CLine->len) { Point = CLine->len - 1; if (Point < 0) Point = 0; else if ((*(CLine->data + Point) != '\n') || (CBuf == MiniBuffer)) Point++; } if (c == 0) c = calculate_column (); c -= (JWindow->hscroll_column - 1); if (cline == HScroll_Line) c -= HScroll; if (c < 1) c = 1; else if (c > JWindow->width) c = JWindow->width; c += JWindow->sx; #if JED_HAS_DISPLAY_LINE_NUMBERS c += CBuf->line_num_display_size; #endif SLsmg_gotorc (r - 1, c - 1); Screen_Row = r; Screen_Col = c; SLsmg_refresh (); if (!Cursor_Motion) Goal_Column = c; }
static void smg_refresh (void) { if (Smg_Initialized <= 0) return; SLsig_block_signals (); SLsmg_refresh (); SLsig_unblock_signals (); }
int newtFinished(void) { SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); newtCursorOn(); SLsmg_refresh(); SLsmg_reset_smg(); SLang_reset_tty(); return 0; }
void ephemeral_message(char *s) { SLsmg_gotorc(disp.num_rows - 1, 0); SLsmg_set_color(3); SLsmg_write_string(s); SLsmg_erase_eol(); SLsmg_refresh(); }
void flush_message (char *m) { message(m); if (Batch || (JWindow == NULL)) return; do_dialog(Message_Buffer); SLsmg_gotorc (Jed_Num_Screen_Rows - 1, strlen(Message_Buffer)); *Message_Buffer = 0; JWindow->trashed = 1; SLsmg_refresh (); }
static void tui_helpline__push(const char *msg) { const size_t sz = sizeof(ui_helpline__current); SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); SLsmg_set_color(0); SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols); SLsmg_refresh(); strlcpy(ui_helpline__current, msg, sz); }
static int getkey() { int c; while ((c = SLang_getkey()) == '\xC') { /* if Ctrl-L redraw whole screen */ SLsmg_touch_lines(0, SLtt_Screen_Rows); SLsmg_refresh(); } return c; }
void c11_draw_background(void) { SLtt_set_color(255,NULL,confdb.background,confdb.background); SLsmg_set_color(255); SLsmg_gotorc(0,0); SLsmg_erase_eos(); SLsmg_refresh(); return; }
static void rline_update(unsigned char *buf, int len, int col) { SLsmg_gotorc (SLtt_Screen_Rows - 1, 0); SLsmg_set_color(2); if( buf ) { SLsmg_write_nchars ((char *) buf, len); } SLsmg_erase_eol (); SLsmg_gotorc (SLtt_Screen_Rows - 1, col); SLsmg_refresh (); }
/* Unconditionally redraw the entire screen. */ void total_redraw(void) { #ifdef USE_SLANG /* Slang curses emulation brain damage, part 4: Slang doesn't define * curscr. */ SLsmg_touch_screen(); SLsmg_refresh(); #else wrefresh(curscr); #endif }
int SLcurses_wrefresh (SLcurses_Window_Type *w) { if (w == NULL) return -1; if (w->modified == 0) return 0; SLcurses_wnoutrefresh (w); SLsmg_refresh (); return 0; }
static void ctl_close(void) { if (ctl.opened) { SLsmg_normal(); SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); SLsmg_refresh(); SLsmg_reset_smg(); SLang_reset_tty(); ctl.opened=0; } }
int ui__question_window(const char *title, const char *text, const char *exit_msg, int delay_secs) { int x, y; int max_len = 0, nr_lines = 0; const char *t; t = text; while (1) { const char *sep = strchr(t, '\n'); int len; if (sep == NULL) sep = strchr(t, '\0'); len = sep - t; if (max_len < len) max_len = len; ++nr_lines; if (*sep == '\0') break; t = sep + 1; } pthread_mutex_lock(&ui__lock); max_len += 2; nr_lines += 4; y = SLtt_Screen_Rows / 2 - nr_lines / 2, x = SLtt_Screen_Cols / 2 - max_len / 2; SLsmg_set_color(0); SLsmg_draw_box(y, x++, nr_lines, max_len); if (title) { SLsmg_gotorc(y, x + 1); SLsmg_write_string((char *)title); } SLsmg_gotorc(++y, x); nr_lines -= 2; max_len -= 2; SLsmg_write_wrapped_string((unsigned char *)text, y, x, nr_lines, max_len, 1); SLsmg_gotorc(y + nr_lines - 2, x); SLsmg_write_nstring((char *)" ", max_len); SLsmg_gotorc(y + nr_lines - 1, x); SLsmg_write_nstring((char *)exit_msg, max_len); SLsmg_refresh(); pthread_mutex_unlock(&ui__lock); return ui__getch(delay_secs); }
void ui__exit(bool wait_for_ok) { if (wait_for_ok) ui__question_window("Fatal Error", ui_helpline__last_msg, "Press any key...", 0); SLtt_set_cursor_visibility(1); SLsmg_refresh(); SLsmg_reset_smg(); SLang_reset_tty(); perf_error__unregister(&perf_tui_eops); }
int main(void) { SLtt_get_terminfo(); SLtt_Use_Ansi_Colors = 1; SLsmg_init_smg(); SLang_init_tty(4, 0, 0); SLsmg_cls(); printall(0); SLsmg_set_char_set(1); printall(40); SLsmg_refresh(); SLang_getkey(); SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); SLsmg_refresh(); SLsmg_reset_smg(); SLang_reset_tty(); return 0; }
/* * Handle a "special request" */ static errr Term_xtra_sla(int n, int v) { /* Analyze the request */ switch (n) { /* Make a noise */ case TERM_XTRA_NOISE: (void)SLsmg_write_char('\007'); return (0); /* Flush the ncurses buffer */ case TERM_XTRA_FRESH: (void)SLsmg_refresh(); return (0); /* Make the cursor invisible or visible */ case TERM_XTRA_SHAPE: /* curs_set(v); */ return (0); /* Handle events */ case TERM_XTRA_EVENT: return (Term_xtra_sla_event(v)); /* Handle events */ case TERM_XTRA_FLUSH: while (!Term_xtra_sla_event(FALSE)); return (0); /* Suspend/Resume */ case TERM_XTRA_ALIVE: return (Term_xtra_sla_alive(v)); /* Clear the screen */ case TERM_XTRA_CLEAR: (void)SLsmg_cls(); SLsmg_gotorc(0, 0); return (0); /* Delay */ case TERM_XTRA_DELAY: usleep(1000 * v); return (0); } /* Oops */ return (1); }
bool SLangConsole::refresh() { /* S-Lang says: * All well behaved applications should block signals that * may affect the display while performing screen update. */ SLsig_block_signals (); if(screen_size_changed && !keyboard_quit) { SLtt_get_screen_size (); SLsmg_reinit_smg (); this->w = SLtt_Screen_Cols; this->h = SLtt_Screen_Rows; screen_size_changed = false; // refresh all widgets SLangWidget *wid; wid = (SLangWidget*) widgets.begin(); while(wid) { wid->refresh(); wid = (SLangWidget*) wid->next; } } if(focused && !keyboard_quit) if(focused->cursor) { SLtt_set_cursor_visibility(1); focused->gotoxy( focused->cur_x, focused->cur_y); } else SLtt_set_cursor_visibility(0); SLsmg_refresh(); SLsig_unblock_signals(); if(keyboard_quit) { func("keyboard requested forced quit"); return false; } return true; }
static void update_display (void) { unsigned int row, nrows; File_Line_Type *line; /* All well behaved applications should block signals that may affect * the display while performing screen update. */ SLsig_block_signals (); Line_Window.nrows = nrows = SLtt_Screen_Rows - 1; /* Always make the current line equal to the top window line. */ if (Line_Window.top_window_line != NULL) Line_Window.current_line = Line_Window.top_window_line; SLscroll_find_top (&Line_Window); row = 0; line = (File_Line_Type *) Line_Window.top_window_line; SLsmg_normal_video (); while (row < Line_Window.nrows) { SLsmg_gotorc (row, 0); if (line != NULL) { SLsmg_write_string (line->data); line = line->next; } SLsmg_erase_eol (); row++; } SLsmg_gotorc (row, 0); SLsmg_reverse_video (); SLsmg_printf ("%s | UTF-8 = %d", (File_Name == NULL) ? "<stdin>" : File_Name, SLutf8_is_utf8_mode ()); SLsmg_erase_eol (); SLsmg_refresh (); SLsig_unblock_signals (); }
static void do_dialog(char *b) { char *quit = "Quit!"; if (Batch) return; #ifdef FIX_CHAR_WIDTH FIX_CHAR_WIDTH; #endif if (! *b) { if(!SLKeyBoard_Quit) return; b = quit; } if ((b == Error_Buffer) || (b == quit)) { SLsmg_set_color (JERROR_COLOR); touch_screen(); } else SLsmg_set_color (JMESSAGE_COLOR); SLsmg_Newline_Behavior = SLSMG_NEWLINE_PRINTABLE; SLsmg_gotorc (Jed_Num_Screen_Rows - 1, 0); SLsmg_write_string (b); SLsmg_set_color (0); SLsmg_erase_eol (); SLsmg_Newline_Behavior = 0; if ((b == Error_Buffer) || (SLKeyBoard_Quit)) { jed_beep(); flush_input(); } if (*b) { if (MiniBuffer != NULL) { SLsmg_refresh (); (void) input_pending(&Number_Ten); } Mini_Ghost = -1; } else Mini_Ghost = 0; }
int ui_helpline__show_help(const char *format, va_list ap) { int ret; static int backlog; pthread_mutex_lock(&ui__lock); ret = vscnprintf(ui_helpline__last_msg + backlog, sizeof(ui_helpline__last_msg) - backlog, format, ap); backlog += ret; if (ui_helpline__last_msg[backlog - 1] == '\n') { ui_helpline__puts(ui_helpline__last_msg); SLsmg_refresh(); backlog = 0; } pthread_mutex_unlock(&ui__lock); return ret; }
int SLcurses_wnoutrefresh (SLcurses_Window_Type *w) { unsigned int len; unsigned int r, c; unsigned int i, imax; if (SLcurses_Is_Endwin) { if (TTY_State) init_tty (TTY_State - 1); SLsmg_resume_smg (); SLcurses_Is_Endwin = 0; } if (w == NULL) { SLsmg_refresh (); return -1; } if (w->modified == 0) return 0; r = w->_begy; c = w->_begx; len = w->ncols; imax = w->nrows; for (i = 0; i < imax; i++) { SLsmg_gotorc (r, c); write_color_chars (w->lines[i], len); r++; } if (w->has_box) SLsmg_draw_box(w->_begy, w->_begx, w->nrows, w->ncols); SLsmg_gotorc (w->_begy + w->_cury, w->_begx + w->_curx); w->modified = 0; return 0; }
/* * Nuke SLang */ static void Term_nuke_sla(term *t) { if (!slang_on) return; /* Show the cursor */ /* curs_set(1); */ /* Clear the screen */ (void)SLsmg_cls(); /* Refresh */ SLsmg_refresh(); /* We are now off */ slang_on = FALSE; /* Shut down */ SLsmg_reset_smg(); SLang_reset_tty(); }
static void most_do_help_text (void) { char **p = help, *sect = NULL; int r; while (*p != NULL) { SLsmg_cls (); r = 0; SLsmg_gotorc (0, 0); if ((sect != NULL) && (**p == ' ')) { most_tt_bold_video (); SLsmg_gotorc (r, 0); SLsmg_write_string (sect); most_tt_normal_video (); SLsmg_write_string (" (continued)"); r += 2; } else sect = NULL; while (r < SLtt_Screen_Rows - 1) { if (*p == NULL) break; if (**p != ' ') { if (((r + 5) > SLtt_Screen_Rows) && (**p != '*')) { sect = NULL; break; } if (sect != NULL) { r++; } if (**p != '*') { sect = *p; most_tt_bold_video (); } else sect = NULL; } SLsmg_gotorc (r, 0); SLsmg_write_string (*p); if ((**p != ' ') && (**p != '*')) { most_tt_normal_video (); r++; } p++; r++; } SLsmg_gotorc (r, 0); most_tt_reverse_video(); SLsmg_write_string("Press any key to continue."); most_tt_normal_video(); SLsmg_refresh (); most_getkey (); } most_redraw_display(); }