Skip to content

Commit

Permalink
Provide wrappers for new API curses functions
Browse files Browse the repository at this point in the history
At least on OS X, they seem to fail if `WINDOW *` parameter is NULL.
  • Loading branch information
xaizek committed Feb 6, 2019
1 parent c71dcb9 commit 5881d76
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 107 deletions.
5 changes: 1 addition & 4 deletions src/event_loop.c
Expand Up @@ -37,7 +37,6 @@
#include "modes/dialogs/msg_dialog.h"
#include "modes/modes.h"
#include "modes/wk.h"
#include "ui/color_manager.h"
#include "ui/fileview.h"
#include "ui/statusbar.h"
#include "ui/statusline.h"
Expand Down Expand Up @@ -642,9 +641,7 @@ prepare_suggestion_box(int *height)
win = stat_win;
}

cchar_t bg;
setcchar(&bg, L" ", col.attr, colmgr_get_pair(col.fg, col.bg), NULL);
wbkgrndset(win, &bg);
ui_set_bg(win, &col, -1);
werase(win);

return win;
Expand Down
2 changes: 1 addition & 1 deletion src/menus/menus.c
Expand Up @@ -476,7 +476,7 @@ draw_menu_item(menu_state_t *ms, int pos, int line, int clear)
item_tail = strdup(m->items[pos] + off);
replace_char(item_tail, '\t', ' ');

(void)wattr_set(menu_win, col.attr, color_pair, NULL);
ui_set_attr(menu_win, &col, color_pair);

/* Clear the area. */
checked_wmove(menu_win, line, 1);
Expand Down
27 changes: 12 additions & 15 deletions src/modes/cmdline.c
Expand Up @@ -40,7 +40,6 @@
#include "../engine/keys.h"
#include "../engine/mode.h"
#include "../modes/dialogs/msg_dialog.h"
#include "../ui/color_manager.h"
#include "../ui/color_scheme.h"
#include "../ui/colors.h"
#include "../ui/fileview.h"
Expand Down Expand Up @@ -388,7 +387,7 @@ draw_cmdline_text(line_stats_t *stat)
}

int pair = -1;
int attr = 0;
col_attr_t prompt_col = {};

werase(status_bar);

Expand All @@ -397,16 +396,16 @@ draw_cmdline_text(line_stats_t *stat)
case PS_NORMAL: pair = CMD_LINE_COLOR; break;
case PS_WRONG_PATTERN: pair = ERROR_MSG_COLOR; break;
case PS_NO_MATCH: pair = CMD_LINE_COLOR;
attr = A_REVERSE;
prompt_col.attr = A_REVERSE;
break;
}
attr ^= cfg.cs.color[pair].attr;
prompt_col.attr ^= cfg.cs.color[pair].attr;

(void)wattr_set(status_bar, attr, cfg.cs.pair[pair], NULL);
ui_set_attr(status_bar, &prompt_col, cfg.cs.pair[pair]);
compat_mvwaddwstr(status_bar, 0, 0, stat->prompt);

(void)wattr_set(status_bar, cfg.cs.color[CMD_LINE_COLOR].attr,
cfg.cs.pair[CMD_LINE_COLOR], NULL);
ui_set_attr(status_bar, &cfg.cs.color[CMD_LINE_COLOR],
cfg.cs.pair[CMD_LINE_COLOR]);
compat_mvwaddwstr(status_bar, stat->prompt_wid/line_width,
stat->prompt_wid%line_width, stat->line);

Expand Down Expand Up @@ -1173,14 +1172,13 @@ draw_wild_bar(int *last_pos, int *pos, int *len)
{
col_attr_t col = cfg.cs.color[STATUS_LINE_COLOR];
cs_mix_colors(&col, &cfg.cs.color[WILD_MENU_COLOR]);
(void)wattr_set(stat_win, col.attr, colmgr_get_pair(col.fg, col.bg),
NULL);
ui_set_attr(stat_win, &col, -1);
}
wprint(stat_win, items[i].text);
if(i == *pos)
{
(void)wattr_set(stat_win, cfg.cs.color[STATUS_LINE_COLOR].attr,
cfg.cs.pair[STATUS_LINE_COLOR], NULL);
ui_set_attr(stat_win, &cfg.cs.color[STATUS_LINE_COLOR],
cfg.cs.pair[STATUS_LINE_COLOR]);
*pos = -*pos;
}
}
Expand Down Expand Up @@ -1225,8 +1223,7 @@ draw_wild_popup(int *last_pos, int *pos, int *len)
{
col_attr_t col = cfg.cs.color[STATUS_LINE_COLOR];
cs_mix_colors(&col, &cfg.cs.color[WILD_MENU_COLOR]);
(void)wattr_set(stat_win, col.attr, colmgr_get_pair(col.fg, col.bg),
NULL);
ui_set_attr(stat_win, &col, -1);
}

checked_wmove(stat_win, j, 0);
Expand All @@ -1235,8 +1232,8 @@ draw_wild_popup(int *last_pos, int *pos, int *len)

if(i == *pos)
{
(void)wattr_set(stat_win, cfg.cs.color[STATUS_LINE_COLOR].attr,
cfg.cs.pair[STATUS_LINE_COLOR], NULL);
ui_set_attr(stat_win, &cfg.cs.color[STATUS_LINE_COLOR],
cfg.cs.pair[STATUS_LINE_COLOR]);
*pos = -*pos;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/modes/more.c
Expand Up @@ -240,8 +240,8 @@ draw_all(const char text[])
wprint(menu_win, text);

/* Draw status line. */
(void)wattr_set(status_bar, cfg.cs.color[CMD_LINE_COLOR].attr,
cfg.cs.pair[CMD_LINE_COLOR], NULL);
ui_set_attr(status_bar, &cfg.cs.color[CMD_LINE_COLOR],
cfg.cs.pair[CMD_LINE_COLOR]);
checked_wmove(status_bar, 0, 0);
mvwprintw(status_bar, 0, 0, "-- More -- %d-%d/%d", curr_vline + 1,
MIN(nvlines, curr_vline + viewport_height), nvlines);
Expand Down
5 changes: 2 additions & 3 deletions src/ui/escape.c
Expand Up @@ -35,7 +35,6 @@
#include "../utils/str.h"
#include "../utils/utf8.h"
#include "../utils/utils.h"
#include "color_manager.h"
#include "ui.h"

static char * add_pattern_highlights(const char line[], size_t len,
Expand Down Expand Up @@ -414,8 +413,8 @@ print_char_esc(WINDOW *win, const char str[], esc_state *state)
if(str[0] == '\033')
{
esc_state_update(state, str);
(void)wattr_set(win, state->attrs, colmgr_get_pair(state->fg, state->bg),
NULL);
col_attr_t col = { .fg = state->fg, .bg = state->bg, .attr = state->attrs };
ui_set_attr(win, &col, -1);
}
else
{
Expand Down
7 changes: 3 additions & 4 deletions src/ui/statusbar.c
Expand Up @@ -32,7 +32,6 @@
#include "../utils/str.h"
#include "../utils/utf8.h"
#include "../status.h"
#include "color_manager.h"
#include "statusline.h"
#include "ui.h"

Expand Down Expand Up @@ -245,12 +244,12 @@ status_bar_message(const char msg[], int error)
{
col_attr_t col = cfg.cs.color[CMD_LINE_COLOR];
cs_mix_colors(&col, &cfg.cs.color[ERROR_MSG_COLOR]);
(void)wattr_set(status_bar, col.attr, colmgr_get_pair(col.fg, col.bg), NULL);
ui_set_attr(status_bar, &col, -1);
}
else
{
(void)wattr_set(status_bar, cfg.cs.color[CMD_LINE_COLOR].attr,
cfg.cs.pair[CMD_LINE_COLOR], NULL);
ui_set_attr(status_bar, &cfg.cs.color[CMD_LINE_COLOR],
cfg.cs.pair[CMD_LINE_COLOR]);
}
werase(status_bar);

Expand Down
17 changes: 8 additions & 9 deletions src/ui/statusline.c
Expand Up @@ -112,15 +112,16 @@ ui_stat_update(view_t *view, int lazy_redraw)

const int width = getmaxx(stdscr);

cchar_t default_attr;
setcchar(&default_attr, L" ", cfg.cs.color[STATUS_LINE_COLOR].attr,
cfg.cs.pair[STATUS_LINE_COLOR], NULL);

wresize(stat_win, 1, width);
wbkgrndset(stat_win, &default_attr);
ui_set_bg(stat_win, &cfg.cs.color[STATUS_LINE_COLOR],
cfg.cs.pair[STATUS_LINE_COLOR]);
werase(stat_win);
checked_wmove(stat_win, 0, 0);

cchar_t default_attr;
setcchar(&default_attr, L" ", cfg.cs.color[STATUS_LINE_COLOR].attr,
cfg.cs.pair[STATUS_LINE_COLOR], NULL);

LineWithAttrs result = expand_status_line_macros(view, cfg.status_line);
assert(strlen(result.attrs) == utf8_strsw(result.line) && "Broken attrs!");
result.line = break_in_two(result.line, width, "%=");
Expand Down Expand Up @@ -188,10 +189,8 @@ update_stat_window_old(view_t *view, int lazy_redraw)
x = getmaxx(stdscr);
wresize(stat_win, 1, x);

cchar_t bg;
setcchar(&bg, L" ", cfg.cs.color[STATUS_LINE_COLOR].attr,
cfg.cs.pair[STATUS_LINE_COLOR], NULL);
wbkgrndset(stat_win, &bg);
ui_set_bg(stat_win, &cfg.cs.color[STATUS_LINE_COLOR],
cfg.cs.pair[STATUS_LINE_COLOR]);

filename = get_current_file_name(view);
print_width = utf8_strsnlen(filename, 20 + MAX(0, x - 83));
Expand Down

0 comments on commit 5881d76

Please sign in to comment.