diff options
author | Thomas Adam <thomas@xteddy.org> | 2023-08-17 18:01:09 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2023-08-17 18:01:09 +0100 |
commit | e3a8b8434cf656164d74ae115ebccd432144ed2c (patch) | |
tree | 45b6061279b4b6155e0b6dd921b42a9341d3e98d /format.c | |
parent | 3d93b0c52ecd6d5b321fef777d49c360c9fbe069 (diff) | |
parent | 8636848e6348bb0e38cd6aaaadbe61e15181bc8f (diff) |
Merge branch 'obsd-master'
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 72 |
1 files changed, 72 insertions, 0 deletions
@@ -1191,6 +1191,72 @@ format_cb_mouse_line(struct format_tree *ft) return (format_grid_line(gd, gd->hsize + y)); } +/* Callback for mouse_status_line. */ +static void * +format_cb_mouse_status_line(struct format_tree *ft) +{ + char *value; + u_int y; + + if (!ft->m.valid) + return (NULL); + if (ft->c == NULL || (~ft->c->tty.flags & TTY_STARTED)) + return (NULL); + + if (ft->m.statusat == 0 && ft->m.y < ft->m.statuslines) { + y = ft->m.y; + } else if (ft->m.statusat > 0 && ft->m.y >= (u_int)ft->m.statusat) { + y = ft->m.y - ft->m.statusat; + } else + return (NULL); + xasprintf(&value, "%u", y); + return (value); + +} + +/* Callback for mouse_status_range. */ +static void * +format_cb_mouse_status_range(struct format_tree *ft) +{ + struct style_range *sr; + u_int x, y; + + if (!ft->m.valid) + return (NULL); + if (ft->c == NULL || (~ft->c->tty.flags & TTY_STARTED)) + return (NULL); + + if (ft->m.statusat == 0 && ft->m.y < ft->m.statuslines) { + x = ft->m.x; + y = ft->m.y; + } else if (ft->m.statusat > 0 && ft->m.y >= (u_int)ft->m.statusat) { + x = ft->m.x; + y = ft->m.y - ft->m.statusat; + } else + return (NULL); + + sr = status_get_range(ft->c, x, y); + if (sr == NULL) + return (NULL); + switch (sr->type) { + case STYLE_RANGE_NONE: + return (NULL); + case STYLE_RANGE_LEFT: + return (xstrdup("left")); + case STYLE_RANGE_RIGHT: + return (xstrdup("right")); + case STYLE_RANGE_PANE: + return (xstrdup("pane")); + case STYLE_RANGE_WINDOW: + return (xstrdup("window")); + case STYLE_RANGE_SESSION: + return (xstrdup("session")); + case STYLE_RANGE_USER: + return (xstrdup(sr->string)); + } + return (NULL); +} + /* Callback for alternate_on. */ static void * format_cb_alternate_on(struct format_tree *ft) @@ -2848,6 +2914,12 @@ static const struct format_table_entry format_table[] = { { "mouse_standard_flag", FORMAT_TABLE_STRING, format_cb_mouse_standard_flag }, + { "mouse_status_line", FORMAT_TABLE_STRING, + format_cb_mouse_status_line + }, + { "mouse_status_range", FORMAT_TABLE_STRING, + format_cb_mouse_status_range + }, { "mouse_utf8_flag", FORMAT_TABLE_STRING, format_cb_mouse_utf8_flag }, |