Exemple #1
0
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();
    }
}
Exemple #2
0
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();
	}
}
Exemple #3
0
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();
    }
}
Exemple #4
0
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();
}
Exemple #5
0
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();
	}
}