static void print_horizontal_tab_title(struct view *v, int idx) { int skip = v->tt_width - v->tt_truncated_width; const char *filename = buffer_filename(v->buffer); char buf[16]; if (skip > 0) { filename += u_skip_chars(filename, &skip); } snprintf(buf, sizeof(buf), "%c%d%s", obuf.x == 0 && idx > 0 ? '<' : ' ', idx + 1, buffer_modified(v->buffer) ? "+" : ":"); if (v == v->window->view) set_builtin_color(BC_ACTIVETAB); else set_builtin_color(BC_INACTIVETAB); buf_add_str(buf); buf_add_str(filename); if (obuf.x == obuf.width - 1 && idx < v->window->views.count - 1) buf_put_char('>'); else buf_put_char(' '); }
static void print_vertical_tab_title(struct view *v, int idx, int width) { const char *orig_filename = buffer_filename(v->buffer); const char *filename = orig_filename; int max = options.tab_bar_max_components; char buf[16]; int skip; snprintf(buf, sizeof(buf), "%2d%s", idx + 1, buffer_modified(v->buffer) ? "+" : " "); if (max) { int i, count = 1; for (i = 0; filename[i]; i++) { if (filename[i] == '/') count++; } // ignore first slash because it does not separate components if (filename[0] == '/') count--; if (count > max) { // skip possible first slash for (i = 1; ; i++) { if (filename[i] == '/' && --count == max) { i++; break; } } filename += i; } } else { skip = strlen(buf) + u_str_width(filename) - width + 1; if (skip > 0) filename += u_skip_chars(filename, &skip); } if (filename != orig_filename) { // filename was shortened. add "<<" symbol long i = strlen(buf); u_set_char(buf, &i, 0xab); buf[i] = 0; } if (v == v->window->view) set_builtin_color(BC_ACTIVETAB); else set_builtin_color(BC_INACTIVETAB); buf_add_str(buf); buf_add_str(filename); buf_clear_eol(); }
int print_command(char prefix) { long i, w; unsigned int u; int x; // width of characters up to and including cursor position w = 1; // ":" (prefix) i = 0; while (i <= cmdline.pos && i < cmdline.buf.len) { u = u_get_char(cmdline.buf.buffer, cmdline.buf.len, &i); w += u_char_width(u); } if (cmdline.pos == cmdline.buf.len) { w++; } if (w > screen_w) obuf.scroll_x = w - screen_w; set_builtin_color(BC_COMMANDLINE); i = 0; buf_put_char(prefix); x = obuf.x - obuf.scroll_x; while (i < cmdline.buf.len) { BUG_ON(obuf.x > obuf.scroll_x + obuf.width); u = u_get_char(cmdline.buf.buffer, cmdline.buf.len, &i); if (!buf_put_char(u)) break; if (i <= cmdline.pos) x = obuf.x - obuf.scroll_x; } return x; }
static void print_horizontal_tabbar(struct window *win) { int i; buf_reset(win->x, win->w, 0); buf_move_cursor(win->x, win->y); calculate_tabbar(win); for (i = win->first_tab_idx; i < win->views.count; i++) { struct view *v = win->views.ptrs[i]; if (obuf.x + v->tt_truncated_width > win->w) break; print_horizontal_tab_title(v, i); } set_builtin_color(BC_TABBAR); if (i != win->views.count) { while (obuf.x < obuf.width - 1) buf_put_char(' '); if (obuf.x == obuf.width - 1) buf_put_char('>'); } else { buf_clear_eol(); } }
void print_message(const char *msg, bool is_error) { enum builtin_color c = BC_COMMANDLINE; long i = 0; if (msg[0]) c = is_error ? BC_ERRORMSG : BC_INFOMSG; set_builtin_color(c); while (msg[i]) { unsigned int u = u_get_char(msg, i + 4, &i); if (!buf_put_char(u)) break; } }
void update_git_open(void) { int x = 0; int y = 0; int w = screen_w; int h = screen_h - 1; int max_y = git_open.scroll + h - 1; int i; if (h >= git_open.files.count) git_open.scroll = 0; if (git_open.scroll > git_open.selected) git_open.scroll = git_open.selected; if (git_open.selected > max_y) git_open.scroll += git_open.selected - max_y; buf_reset(x, w, 0); buf_move_cursor(0, 0); cmdline_x = print_command('/'); buf_clear_eol(); y++; for (i = 0; i < h; i++) { int file_idx = git_open.scroll + i; char *file; struct term_color color; if (file_idx >= git_open.files.count) break; file = git_open.files.ptrs[file_idx]; obuf.x = 0; buf_move_cursor(x, y + i); color = *builtin_colors[BC_DEFAULT]; if (file_idx == git_open.selected) mask_color(&color, builtin_colors[BC_SELECTION]); buf_set_color(&color); buf_add_str(file); buf_clear_eol(); } set_builtin_color(BC_DEFAULT); for (; i < h; i++) { obuf.x = 0; buf_move_cursor(x, y + i); buf_clear_eol(); } }
static void print_vertical_tabbar(struct window *win) { int width = vertical_tabbar_width(win); int h = win->edit_h; int i, n, cur_idx = 0; for (i = 0; i < win->views.count; i++) { if (win->view == win->views.ptrs[i]) { cur_idx = i; break; } } if (win->views.count <= h) { // all tabs fit win->first_tab_idx = 0; } else { int max_y = win->first_tab_idx + h - 1; if (win->first_tab_idx > cur_idx) win->first_tab_idx = cur_idx; if (cur_idx > max_y) win->first_tab_idx += cur_idx - max_y; } buf_reset(win->x, width, 0); n = h; if (n + win->first_tab_idx > win->views.count) n = win->views.count - win->first_tab_idx; for (i = 0; i < n; i++) { int idx = win->first_tab_idx + i; obuf.x = 0; buf_move_cursor(win->x, win->y + i); print_vertical_tab_title(win->views.ptrs[idx], idx, width); } set_builtin_color(BC_TABBAR); for (; i < h; i++) { obuf.x = 0; buf_move_cursor(win->x, win->y + i); buf_clear_eol(); } }
void update_status_line(struct window *win) { struct formatter f; char lbuf[256]; char rbuf[256]; int lw, rw; sf_init(&f, win); f.misc_status = format_misc_status(win); sf_format(&f, lbuf, sizeof(lbuf), options.statusline_left); sf_format(&f, rbuf, sizeof(rbuf), options.statusline_right); buf_reset(win->x, win->w, 0); buf_move_cursor(win->x, win->y + win->h - 1); set_builtin_color(BC_STATUSLINE); lw = u_str_width(lbuf); rw = u_str_width(rbuf); if (lw + rw <= win->w) { // both fit buf_add_str(lbuf); buf_set_bytes(' ', win->w - lw - rw); buf_add_str(rbuf); } else if (lw <= win->w && rw <= win->w) { // both would fit separately, draw overlapping buf_add_str(lbuf); obuf.x = win->w - rw; buf_move_cursor(win->x + win->w - rw, win->y + win->h - 1); buf_add_str(rbuf); } else if (lw <= win->w) { // left fits buf_add_str(lbuf); buf_clear_eol(); } else if (rw <= win->w) { // right fits buf_set_bytes(' ', win->w - rw); buf_add_str(rbuf); } else { buf_clear_eol(); } }
void update_line_numbers(struct window *win, bool force) { struct view *v = win->view; long lines = v->buffer->nl; int i, first, last; int x = win->x + vertical_tabbar_width(win); calculate_line_numbers(win); first = v->vy + 1; last = v->vy + win->edit_h; if (last > lines) last = lines; if (!force && win->line_numbers.first == first && win->line_numbers.last == last) return; win->line_numbers.first = first; win->line_numbers.last = last; buf_reset(win->x, win->w, 0); set_builtin_color(BC_LINENUMBER); for (i = 0; i < win->edit_h; i++) { int line = v->vy + i + 1; int w = win->line_numbers.width - 1; char buf[32]; if (line > lines) { snprintf(buf, sizeof(buf), "%*s ", w, ""); } else { snprintf(buf, sizeof(buf), "%*d ", w, line); } buf_move_cursor(x, win->edit_y + i); buf_add_bytes(buf, win->line_numbers.width); } }
void update_separators(void) { set_builtin_color(BC_STATUSLINE); for_each_window(print_separator); }