/* Updates the status bar */ static void update_status_win(enum win_refresh dorefresh) { int pos; int attr; attr = hl_groups_get_attr(hl_groups_instance, HLG_STATUS_BAR); /* Print white background */ swin_wattron(status_win, attr); for (pos = 0; pos < WIDTH; pos++) swin_mvwprintw(status_win, 0, pos, " "); /* Show the user which window is focused */ if (focus == GDB) swin_mvwprintw(status_win, 0, WIDTH - 1, "*"); else if (focus == CGDB || focus == CGDB_STATUS_BAR) swin_mvwprintw(status_win, 0, WIDTH - 1, " "); swin_wattroff(status_win, attr); /* Print the regex that the user is looking for Forward */ if (sbc_kind == SBC_REGEX && regex_direction_cur) { if_display_message("/", dorefresh, WIDTH - 1, "%s", ibuf_get(regex_cur)); swin_curs_set(1); } /* Regex backwards */ else if (sbc_kind == SBC_REGEX) { if_display_message("?", dorefresh, WIDTH - 1, "%s", ibuf_get(regex_cur)); swin_curs_set(1); } /* A colon command typed at the status bar */ else if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_NORMAL) { const char *command = ibuf_get(cur_sbc); if (!command) command = ""; if_display_message(":", dorefresh, WIDTH - 1, "%s", command); swin_curs_set(1); } /* Default: Current Filename */ else { /* Print filename */ const char *filename = source_current_file(src_viewer); if (filename) { if_display_message("", dorefresh, WIDTH - 1, "%s", filename); } } if (dorefresh == WIN_REFRESH) swin_wrefresh(status_win); else swin_wnoutrefresh(status_win); }
void if_display_message(const char *msg, enum win_refresh dorefresh, int width, const char *fmt, ...) { va_list ap; char va_buf[MAXLINE]; char buf_display[MAXLINE]; int pos, error_length, length; int attr; attr = hl_groups_get_attr(hl_groups_instance, HLG_STATUS_BAR); swin_curs_set(0); if (!width) width = WIDTH; /* Get the buffer with format */ va_start(ap, fmt); #ifdef HAVE_VSNPRINTF vsnprintf(va_buf, sizeof (va_buf), fmt, ap); /* this is safe */ #else vsprintf(va_buf, fmt, ap); /* this is not safe */ #endif va_end(ap); error_length = strlen(msg); length = strlen(va_buf); if (error_length > width) strcat(strncpy(buf_display, msg, width - 1), ">"); else if (error_length + length > width) snprintf(buf_display, sizeof(buf_display), "%s>%s", msg, va_buf + (length - (width - error_length) + 1)); else snprintf(buf_display, sizeof(buf_display), "%s%s", msg, va_buf); /* Print white background */ swin_wattron(status_win, attr); for (pos = 0; pos < WIDTH; pos++) swin_mvwprintw(status_win, 0, pos, " "); swin_mvwprintw(status_win, 0, 0, "%s", buf_display); swin_wattroff(status_win, attr); if (dorefresh == WIN_REFRESH) swin_wrefresh(status_win); else swin_wnoutrefresh(status_win); }
void filedlg_display_message(struct filedlg *fd, char *message) { int height, width, i; int attr; attr = hl_groups_get_attr(hl_groups_instance, HLG_STATUS_BAR); height = swin_getmaxy(fd->win); width = swin_getmaxx(fd->win); /* Print white background */ swin_wattron(fd->win, attr); for (i = 0; i < width; i++) swin_mvwprintw(fd->win, height - 1, i, " "); swin_mvwprintw(fd->win, height - 1, 0, "%s", message); swin_wattroff(fd->win, attr); swin_wrefresh(fd->win); }
/* print_in_middle: Prints the message 'string' centered at line in win * ---------------- * * win: Curses window * line: The line to print the message at * width: The width of the window * string: The message to print */ static void print_in_middle(SWINDOW *win, int line, int width, const char *string) { int x, y; int j; int length = strlen(string); y = swin_getcury(win); x = swin_getcurx(win); x = (int) ((width - length) / 2); swin_wmove(win, line, 0); for (j = 0; j < x; j++) swin_waddch(win, ' '); swin_mvwprintw(win, line, x, "%s", string); for (j = x + length; j < width; j++) swin_waddch(win, ' '); }
void scr_refresh(struct scroller *scr, int focus, enum win_refresh dorefresh) { int length; /* Length of current line */ int nlines; /* Number of lines written so far */ int r; /* Current row in scroller */ int c; /* Current column in row */ int width, height; /* Width and height of window */ int highlight_attr; int hlsearch = cgdbrc_get_int(CGDBRC_HLSEARCH); int rows_to_display = 0; /* Steal line highlight attribute for our scroll mode status */ highlight_attr = hl_groups_get_attr(hl_groups_instance, HLG_SCROLL_MODE_STATUS); /* Sanity check */ height = swin_getmaxy(scr->win); width = swin_getmaxx(scr->win); if (scr->current.c > 0) { if (scr->current.c % width != 0) scr->current.c = (scr->current.c / width) * width; } r = scr->current.r; c = scr->current.c; rows_to_display = number_rows_to_display(scr, height, width); /** * Printing the scroller to the gdb window. * * The gdb window has a certain dimension (height and width). * The scroller has a certain number of rows to print. * * When starting cgdb, or when the user clears the screen with Ctrl-L, * the entire scroller buffer is not displayed in the gdb window. * * The gdb readline input will be displayed just below the last * line of output in the scroller. * * In order to display the scroller buffer, first determine how many * lines should be displayed. Then start drawing from the bottom of * the viewable space and work our way up. */ for (nlines = 1; nlines <= height; nlines++) { /* Empty lines below the scroller prompt should be empty. * When in scroller mode, there should be no empty lines on the * bottom. */ if (!scr->in_scroll_mode && nlines <= height - rows_to_display) { swin_wmove(scr->win, height - nlines, 0); swin_wclrtoeol(scr->win); } /* Print the current line [segment] */ else if (r >= 0) { struct scroller_line *sline = &scr->lines[r]; hl_printline(scr->win, sline->line, sline->line_len, sline->attrs, 0, height - nlines, c, width); /* If we're searching right now or we finished search * and have focus... */ if (hlsearch && scr->last_hlregex && focus) { struct hl_line_attr *attrs = hl_regex_highlight( &scr->last_hlregex, sline->line, HLG_SEARCH); if (sbcount(attrs)) { hl_printline_highlight(scr->win, sline->line, sline->line_len, attrs, 0, height - nlines, c, width); sbfree(attrs); } } if (scr->hlregex && scr->current.r == r) { struct hl_line_attr *attrs = hl_regex_highlight( &scr->hlregex, sline->line, HLG_INCSEARCH); if (sbcount(attrs)) { hl_printline_highlight(scr->win, sline->line, sline->line_len, attrs, 0, height - nlines, c, width); sbfree(attrs); } } /* Update our position */ if (c >= width) c -= width; else { r--; if (r >= 0) { length = scr->lines[r].line_len; if (length > width) c = ((length - 1) / width) * width; } } /* Empty lines above the first line in the scroller should be empty. * Since the scroller starts at the top, this should only occur when * in the scroll mode. */ } else { swin_wmove(scr->win, height - nlines, 0); swin_wclrtoeol(scr->win); } /* If we're in scroll mode and this is the top line, spew status on right */ if (scr->in_scroll_mode && (nlines == height)) { char status[ 64 ]; size_t status_len; snprintf(status, sizeof(status), "[%d/%d]", scr->current.r + 1, sbcount(scr->lines)); status_len = strlen(status); if ( status_len < width ) { swin_wattron(scr->win, highlight_attr); swin_mvwprintw(scr->win, height - nlines, width - status_len, "%s", status); swin_wattroff(scr->win, highlight_attr); } } } length = scr->lines[scr->current.r].line_len - scr->current.c; /* Only show the cursor when * - the scroller is in focus * - on the last line * - when it is within the width of the screen * - when not in scroller mode */ if (focus && scr->current.r == sbcount(scr->lines) - 1 && length <= width && !scr->in_scroll_mode) { swin_curs_set(1); swin_wmove(scr->win, rows_to_display-1, scr->current.pos % width); } else { /* Hide the cursor */ swin_curs_set(0); } switch(dorefresh) { case WIN_NO_REFRESH: swin_wnoutrefresh(scr->win); break; case WIN_REFRESH: swin_wrefresh(scr->win); break; } }
int filedlg_display(struct filedlg *fd) { char fmt[16]; int width, height; int lwidth; int file; int i; int statusbar; int arrow_attr; int count = sbcount(fd->buf->files); int hlsearch = cgdbrc_get_int(CGDBRC_HLSEARCH); static const char label[] = "Select a file or press q to cancel."; int inc_search_attr = hl_groups_get_attr(hl_groups_instance, HLG_INCSEARCH); int search_attr = hl_groups_get_attr(hl_groups_instance, HLG_SEARCH); swin_curs_set(0); statusbar = hl_groups_get_attr(hl_groups_instance, HLG_STATUS_BAR); arrow_attr = hl_groups_get_attr(hl_groups_instance, HLG_SELECTED_LINE_ARROW); /* Check that a file is loaded */ if (fd == NULL || fd->buf == NULL || fd->buf->files == NULL) { swin_wrefresh(fd->win); return 0; } /* Initialize variables */ height = swin_getmaxy(fd->win); width = swin_getmaxx(fd->win); /* The status bar and display line * Fake the display function to think the height is 2 lines less */ height -= 2; /* Set starting line number (center source file if it's small enough) */ if (count < height) file = (count - height) / 2; else { file = fd->buf->sel_line - height / 2; if (file > count - height) file = count - height; else if (file < 0) file = 0; } /* Print 'height' lines of the file, starting at 'file' */ lwidth = log10_uint(count) + 1; snprintf(fmt, sizeof(fmt), "%%%dd", lwidth); print_in_middle(fd->win, 0, width, label); swin_wmove(fd->win, 0, 0); for (i = 1; i < height + 1; i++, file++) { swin_wmove(fd->win, i, 0); /* Outside of filename, just finish drawing the vertical file */ if (file < 0 || file >= count) { int j; for (j = 1; j < lwidth; j++) swin_waddch(fd->win, ' '); swin_waddch(fd->win, '~'); swin_wattron(fd->win, SWIN_A_BOLD); swin_waddch(fd->win, SWIN_SYM_VLINE); swin_wattroff(fd->win, SWIN_A_BOLD); for (j = 2 + lwidth; j < width; j++) swin_waddch(fd->win, ' '); continue; } int x, y; char *filename = fd->buf->files[file]; /* Mark the current file with an arrow */ if (file == fd->buf->sel_line) { swin_wattron(fd->win, SWIN_A_BOLD); swin_wprintw(fd->win, fmt, file + 1); swin_wattroff(fd->win, SWIN_A_BOLD); swin_wattron(fd->win, arrow_attr); swin_waddch(fd->win, '-'); swin_waddch(fd->win, '>'); swin_wattroff(fd->win, arrow_attr); } else { /* Ordinary file */ swin_wprintw(fd->win, fmt, file + 1); swin_wattron(fd->win, SWIN_A_BOLD); swin_waddch(fd->win, SWIN_SYM_VLINE); swin_wattroff(fd->win, SWIN_A_BOLD); swin_waddch(fd->win, ' '); } y = swin_getcury(fd->win); x = swin_getcurx(fd->win); hl_printline(fd->win, filename, strlen(filename), NULL, -1, -1, fd->buf->sel_col, width - lwidth - 2); if (hlsearch && fd->last_hlregex) { struct hl_line_attr *attrs = hl_regex_highlight( &fd->last_hlregex, filename, search_attr); if (sbcount(attrs)) { hl_printline_highlight(fd->win, filename, strlen(filename), attrs, x, y, fd->buf->sel_col, width - lwidth - 2); sbfree(attrs); } } if (regex_search && file == fd->buf->sel_line) { struct hl_line_attr *attrs = hl_regex_highlight( &fd->hlregex, filename, inc_search_attr); if (sbcount(attrs)) { hl_printline_highlight(fd->win, filename, strlen(filename), attrs, x, y, fd->buf->sel_col, width - lwidth - 2); sbfree(attrs); } } } /* Add the 2 lines back in so the status bar can be drawn */ height += 2; /* Update status bar */ swin_wmove(fd->win, height, 0); /* Print white background */ swin_wattron(fd->win, statusbar); for (i = 0; i < width; i++) swin_mvwprintw(fd->win, height - 1, i, " "); if (regex_search && regex_direction) swin_mvwprintw(fd->win, height - 1, 0, "Search:%s", regex_line); else if (regex_search) swin_mvwprintw(fd->win, height - 1, 0, "RSearch:%s", regex_line); swin_wattroff(fd->win, statusbar); swin_wmove(fd->win, height - (file - fd->buf->sel_line) - 1, lwidth + 2); swin_wrefresh(fd->win); return 0; }