diff options
Diffstat (limited to 'src/interface-curses/curses-info-popup.c')
| -rw-r--r-- | src/interface-curses/curses-info-popup.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/src/interface-curses/curses-info-popup.c b/src/interface-curses/curses-info-popup.c index 332d434..edb6e15 100644 --- a/src/interface-curses/curses-info-popup.c +++ b/src/interface-curses/curses-info-popup.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2025 Robin Haberkorn + * Copyright (C) 2012-2026 Robin Haberkorn * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,8 @@ #include "config.h" #endif +#include <string.h> + #include <glib.h> #include <curses.h> @@ -26,6 +28,7 @@ #include "list.h" #include "string-utils.h" #include "interface.h" +#include "cmdline.h" #include "curses-utils.h" #include "curses-info-popup.h" #include "curses-icons.h" @@ -37,6 +40,7 @@ typedef struct { teco_stailq_entry_t entry; teco_popup_entry_type_t type; + /** entry name or empty string for the "(Unnamed)" buffer */ teco_string_t name; gboolean highlight; } teco_popup_entry_t; @@ -71,7 +75,6 @@ teco_curses_info_popup_add(teco_curses_info_popup_t *ctx, teco_popup_entry_type_ static void teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) { - int cols = getmaxx(stdscr); /**! screen width */ int pad_lines; /**! pad height */ gint pad_cols; /**! entry columns */ gint pad_colwidth; /**! width per entry column */ @@ -82,10 +85,10 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) * Otherwise 2 characters after the entry. */ gint reserve = teco_ed & TECO_ED_ICONS ? 2+1 : 2; - pad_colwidth = MIN(ctx->longest + reserve, cols - 2); + pad_colwidth = MIN(ctx->longest + reserve, COLS - 2); /* pad_cols = floor((cols - 2) / pad_colwidth) */ - pad_cols = (cols - 2) / pad_colwidth; + pad_cols = (COLS - 2) / pad_colwidth; /* pad_lines = ceil(length / pad_cols) */ pad_lines = (ctx->length+pad_cols-1) / pad_cols; @@ -96,7 +99,7 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) * it will be drawn into the popup window which has left * and right borders. */ - ctx->pad = newpad(pad_lines, cols - 2); + ctx->pad = newpad(pad_lines, COLS - 2); /* * NOTE: attr could contain A_REVERSE on monochrome terminals, @@ -122,25 +125,32 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) if (entry->highlight) wattron(ctx->pad, A_BOLD); + teco_string_t name = entry->name; + if (!name.len) { + name.data = TECO_UNNAMED_FILE; + name.len = strlen(name.data); + } + switch (entry->type) { case TECO_POPUP_FILE: - g_assert(!teco_string_contains(&entry->name, '\0')); + g_assert(!teco_string_contains(name, '\0')); if (teco_ed & TECO_ED_ICONS) { + /* "(Unnamed)" buffer is looked up as "" */ teco_curses_add_wc(ctx->pad, teco_curses_icons_lookup_file(entry->name.data)); waddch(ctx->pad, ' '); } - teco_curses_format_filename(ctx->pad, entry->name.data, -1); + teco_curses_format_filename(ctx->pad, name.data, -1); break; case TECO_POPUP_DIRECTORY: - g_assert(!teco_string_contains(&entry->name, '\0')); + g_assert(!teco_string_contains(name, '\0')); if (teco_ed & TECO_ED_ICONS) { teco_curses_add_wc(ctx->pad, teco_curses_icons_lookup_dir(entry->name.data)); waddch(ctx->pad, ' '); } - teco_curses_format_filename(ctx->pad, entry->name.data, -1); + teco_curses_format_filename(ctx->pad, name.data, -1); break; default: - teco_curses_format_str(ctx->pad, entry->name.data, entry->name.len, -1); + teco_curses_format_str(ctx->pad, name.data, name.len, -1); break; } @@ -157,9 +167,6 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr) /* nothing to display */ return; - int lines, cols; /* screen dimensions */ - getmaxyx(stdscr, lines, cols); - if (ctx->window) delwin(ctx->window); @@ -171,10 +178,10 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr) * Popup window can cover all but one screen row. * Another row is reserved for the top border. */ - gint popup_lines = MIN(pad_lines + 1, lines - 1); + gint popup_lines = MIN(pad_lines + 1, LINES - teco_cmdline.height); /* window covers message, scintilla and info windows */ - ctx->window = newwin(popup_lines, 0, lines - 1 - popup_lines, 0); + ctx->window = newwin(popup_lines, 0, LINES - teco_cmdline.height - popup_lines, 0); wattrset(ctx->window, attr); @@ -188,7 +195,7 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr) copywin(ctx->pad, ctx->window, ctx->pad_first_line, 0, - 1, 1, popup_lines - 1, cols - 2, FALSE); + 1, 1, popup_lines - 1, COLS - 2, FALSE); if (pad_lines <= popup_lines - 1) /* no need for scrollbar */ @@ -200,13 +207,13 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr) /* bar_y = floor(pad_first_line/pad_lines * (popup_lines-2)) + 1 */ gint bar_y = ctx->pad_first_line*(popup_lines-2) / pad_lines + 1; - mvwvline(ctx->window, 1, cols-1, ACS_CKBOARD, popup_lines-2); + mvwvline(ctx->window, 1, COLS-1, ACS_CKBOARD, popup_lines-2); /* * We do not use ACS_BLOCK here since it will not * always be drawn as a solid block (e.g. xterm). * Instead, simply draw reverse blanks. */ - wmove(ctx->window, bar_y, cols-1); + wmove(ctx->window, bar_y, COLS-1); wattrset(ctx->window, attr ^ A_REVERSE); wvline(ctx->window, ' ', bar_height); } @@ -227,7 +234,6 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr) const teco_string_t * teco_curses_info_popup_getentry(teco_curses_info_popup_t *ctx, gint y, gint x) { - int cols = getmaxx(stdscr); /**! screen width */ gint pad_cols; /**! entry columns */ gint pad_colwidth; /**! width per entry column */ @@ -240,10 +246,10 @@ teco_curses_info_popup_getentry(teco_curses_info_popup_t *ctx, gint y, gint x) * Otherwise 2 characters after the entry. */ gint reserve = teco_ed & TECO_ED_ICONS ? 2+1 : 2; - pad_colwidth = MIN(ctx->longest + reserve, cols - 2); + pad_colwidth = MIN(ctx->longest + reserve, COLS - 2); /* pad_cols = floor((cols - 2) / pad_colwidth) */ - pad_cols = (cols - 2) / pad_colwidth; + pad_cols = (COLS - 2) / pad_colwidth; gint cur_col = 0; for (teco_stailq_entry_t *cur = ctx->list.first; cur != NULL; cur = cur->next) { @@ -265,9 +271,8 @@ teco_curses_info_popup_getentry(teco_curses_info_popup_t *ctx, gint y, gint x) void teco_curses_info_popup_scroll_page(teco_curses_info_popup_t *ctx) { - gint lines = getmaxy(stdscr); gint pad_lines = getmaxy(ctx->pad); - gint popup_lines = MIN(pad_lines + 1, lines - 1); + gint popup_lines = MIN(pad_lines + 1, LINES - teco_cmdline.height); /* progress scroll position */ ctx->pad_first_line += popup_lines - 1; @@ -281,9 +286,8 @@ teco_curses_info_popup_scroll_page(teco_curses_info_popup_t *ctx) void teco_curses_info_popup_scroll(teco_curses_info_popup_t *ctx, gint delta) { - gint lines = getmaxy(stdscr); gint pad_lines = getmaxy(ctx->pad); - gint popup_lines = MIN(pad_lines + 1, lines - 1); + gint popup_lines = MIN(pad_lines + 1, LINES - teco_cmdline.height); ctx->pad_first_line = MAX(ctx->pad_first_line+delta, 0); if (pad_lines - ctx->pad_first_line < popup_lines - 1) |
