-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change ui_window_style_set and change the way cursorline is drawn #1229
base: master
Are you sure you want to change the base?
Conversation
Hi! I'm not sure I understand the point? CURSOR_LINE already doesn't override non-default styles if the user didn't request it. For example the zenburn theme only specifies the background for CURSOR_LINE so whatever foreground was set by the other rules remains unchanged when CURSOR_LINE is applied. |
If other styles on the same line have non-default background, then CURSOR_LINE will override them. That's is kind of the problem when using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delayed review. I'm fine with this if you address the comments I left inline.
static bool is_default_fg(CellColor c) { | ||
return is_default_color(c); | ||
static bool is_default_fg(CellColor c, CellColor default_fg) { | ||
return is_default_color(c) || cell_color_equal(c, default_fg); | ||
} | ||
|
||
static bool is_default_bg(CellColor c) { | ||
return is_default_color(c); | ||
static bool is_default_bg(CellColor c, CellColor default_bg) { | ||
return is_default_color(c) || cell_color_equal(c, default_bg); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do the cell_color_equal()
inline where its needed. The current change makes it very hard to understand what the is_default_*
functions are checking.
@@ -269,25 +269,29 @@ static void ui_window_draw(Win *win) { | |||
} | |||
} | |||
|
|||
void ui_window_style_set(Ui *tui, int win_id, Cell *cell, enum UiStyle id) { | |||
void ui_window_style_set(Ui *tui, int win_id, Cell *cell, enum UiStyle id, bool keep) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a more descriptive name than keep
. What is being kept? It should be immediately clear.
set.bg = is_default_bg(set.bg)? cell->style.bg : set.bg; | ||
CellStyle def = tui->styles[win_id * UI_STYLE_MAX + UI_STYLE_DEFAULT]; | ||
if (keep) { | ||
set.fg = is_default_fg(cell->style.fg, def.fg) ? set.fg : cell->style.fg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set.fg = is_default_fg(cell->style.fg, def.fg) ? set.fg : cell->style.fg; | |
if (!is_default_fg(cell->style.fg) && !cell_color_equal(cell->style.fg, def.fg)) | |
set.fg = cell->style.fg; |
These ternary operations are too difficult to follow with the proposed changes.
@@ -2038,7 +2039,8 @@ static int window_style(lua_State *L) { | |||
enum UiStyle style = luaL_checkunsigned(L, 2); | |||
size_t start = checkpos(L, 3); | |||
size_t end = checkpos(L, 4); | |||
win_style(win, style, start, end); | |||
bool keep = lua_isboolean(L, 5) && lua_toboolean(L, 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool keep = lua_isboolean(L, 5) && lua_toboolean(L, 5); | |
if (!lua_isboolean(L, 5)) | |
return luaL_argerror(L, 5, "boolean expected"); |
I think we should raise an error rather than assume false when the caller passes something weird.
@@ -2063,7 +2066,8 @@ static int window_style_pos(lua_State *L) { | |||
enum UiStyle style = luaL_checkunsigned(L, 2); | |||
size_t x = checkpos(L, 3); | |||
size_t y = checkpos(L, 4); | |||
bool ret = ui_window_style_set_pos(win, (int)x, (int)y, style); | |||
bool keep = lua_isboolean(L, 5) && lua_toboolean(L, 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
Changes:
ui_window_style_set
now acceptskeep
flag, that allows to not override non-default style values (fg and bg);ui_window_style_set_pos
andwin_style
also accept the same flag;win:style
andwin:style_pos
both accept the samekeep
flag, but it is optional;This was mainly done so that CURSOR_LINE wouldn't override other styles, but plugins can potentially benefit from this as well.