mirror of
https://github.com/tmux/tmux.git
synced 2026-10-06 17:49:52 +00:00
Show hook count and time in customize mode.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: window-customize.c,v 1.35 2026/07/15 12:45:39 nicm Exp $ */
|
/* $OpenBSD: window-customize.c,v 1.36 2026/07/28 10:35:31 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||||
@@ -276,6 +276,36 @@ window_customize_scope_text(enum window_customize_scope scope,
|
|||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
window_customize_write_hook_fire(struct screen_write_ctx *ctx, u_int cx,
|
||||||
|
u_int sx, u_int sy, struct options_entry *o)
|
||||||
|
{
|
||||||
|
char *fire_time_string;
|
||||||
|
u_int fire_count;
|
||||||
|
time_t fire_time;
|
||||||
|
|
||||||
|
if (options_get_monitor_data(o) != NULL) {
|
||||||
|
fire_count = hooks_monitor_get_fire_count(o);
|
||||||
|
fire_time = hooks_monitor_get_fire_time(o);
|
||||||
|
} else {
|
||||||
|
fire_count = options_get_fire_count(o);
|
||||||
|
fire_time = options_get_fire_time(o);
|
||||||
|
}
|
||||||
|
if (fire_time != 0) {
|
||||||
|
fire_time_string = format_pretty_time(fire_time, 0);
|
||||||
|
if (!screen_write_text(ctx, cx, sx, sy, 0, &grid_default_cell,
|
||||||
|
"This hook has been fired %u times, last %s.", fire_count,
|
||||||
|
fire_time_string)) {
|
||||||
|
free(fire_time_string);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
free(fire_time_string);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (screen_write_text(ctx, cx, sx, sy, 0, &grid_default_cell,
|
||||||
|
"This hook has been fired %u times.", fire_count));
|
||||||
|
}
|
||||||
|
|
||||||
static struct window_customize_itemdata *
|
static struct window_customize_itemdata *
|
||||||
window_customize_add_item(struct window_customize_modedata *data)
|
window_customize_add_item(struct window_customize_modedata *data)
|
||||||
{
|
{
|
||||||
@@ -654,7 +684,7 @@ window_customize_build_option(struct window_customize_modedata *data,
|
|||||||
char *text, *expanded, *value;
|
char *text, *expanded, *value;
|
||||||
int global = 0, array = 0;
|
int global = 0, array = 0;
|
||||||
int is_hook = 0, is_monitor = 0;
|
int is_hook = 0, is_monitor = 0;
|
||||||
int is_user_hook = 0;
|
int is_user_hook = 0, is_any_hook;
|
||||||
uint64_t tag;
|
uint64_t tag;
|
||||||
|
|
||||||
if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_HOOK))
|
if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_HOOK))
|
||||||
@@ -663,13 +693,14 @@ window_customize_build_option(struct window_customize_modedata *data,
|
|||||||
is_monitor = 1;
|
is_monitor = 1;
|
||||||
if (*name == '@' && hooks_is_event(name))
|
if (*name == '@' && hooks_is_event(name))
|
||||||
is_user_hook = 1;
|
is_user_hook = 1;
|
||||||
|
is_any_hook = (is_hook || is_monitor || is_user_hook);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WINDOW_CUSTOMIZE_OPTIONS:
|
case WINDOW_CUSTOMIZE_OPTIONS:
|
||||||
if (is_hook || is_monitor || is_user_hook)
|
if (is_any_hook)
|
||||||
return (0);
|
return (0);
|
||||||
break;
|
break;
|
||||||
case WINDOW_CUSTOMIZE_HOOKS:
|
case WINDOW_CUSTOMIZE_HOOKS:
|
||||||
if (!is_hook && !is_monitor && !is_user_hook)
|
if (!is_any_hook)
|
||||||
return (0);
|
return (0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1188,6 +1219,7 @@ window_customize_draw_option(struct window_customize_modedata *data,
|
|||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
int is_hook, is_monitor, is_user_hook;
|
int is_hook, is_monitor, is_user_hook;
|
||||||
|
int is_any_hook;
|
||||||
|
|
||||||
if (!window_customize_check_item(data, item, &fs))
|
if (!window_customize_check_item(data, item, &fs))
|
||||||
return;
|
return;
|
||||||
@@ -1201,6 +1233,7 @@ window_customize_draw_option(struct window_customize_modedata *data,
|
|||||||
is_hook = (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_HOOK));
|
is_hook = (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_HOOK));
|
||||||
is_monitor = (options_get_monitor_data(o) != NULL);
|
is_monitor = (options_get_monitor_data(o) != NULL);
|
||||||
is_user_hook = (*name == '@' && hooks_is_event(name));
|
is_user_hook = (*name == '@' && hooks_is_event(name));
|
||||||
|
is_any_hook = (is_hook || is_monitor || is_user_hook);
|
||||||
|
|
||||||
if (oe != NULL && oe->unit != NULL) {
|
if (oe != NULL && oe->unit != NULL) {
|
||||||
space = " ";
|
space = " ";
|
||||||
@@ -1267,8 +1300,16 @@ monitor:
|
|||||||
}
|
}
|
||||||
if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_ARRAY)) {
|
if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_ARRAY)) {
|
||||||
if (is_hook) {
|
if (is_hook) {
|
||||||
if (array_key == NULL)
|
if (array_key == NULL) {
|
||||||
|
if (!screen_write_text(ctx, cx, sx,
|
||||||
|
sy - (s->cy - cy), 0, &grid_default_cell,
|
||||||
|
"This is an array hook."))
|
||||||
|
goto out;
|
||||||
|
if (!window_customize_write_hook_fire(ctx, cx,
|
||||||
|
sx, sy - (s->cy - cy), o))
|
||||||
|
goto out;
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
} else if (array_key != NULL) {
|
} else if (array_key != NULL) {
|
||||||
if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy),
|
if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy),
|
||||||
0, &grid_default_cell,
|
0, &grid_default_cell,
|
||||||
@@ -1294,10 +1335,13 @@ monitor:
|
|||||||
default_value = NULL;
|
default_value = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_hook || is_monitor || is_user_hook) {
|
if (is_any_hook) {
|
||||||
if (!window_customize_write_value(ctx, cx, sx, sy - (s->cy - cy),
|
if (!window_customize_write_value(ctx, cx, sx, sy - (s->cy - cy),
|
||||||
0, "Hook command: ", "%s%s%s", value, space, unit))
|
0, "Hook command: ", "%s%s%s", value, space, unit))
|
||||||
goto out;
|
goto out;
|
||||||
|
if (!window_customize_write_hook_fire(ctx, cx, sx,
|
||||||
|
sy - (s->cy - cy), o))
|
||||||
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
if (!window_customize_write_value(ctx, cx, sx, sy - (s->cy - cy),
|
if (!window_customize_write_value(ctx, cx, sx, sy - (s->cy - cy),
|
||||||
0, "Option value: ", "%s%s%s", value, space, unit))
|
0, "Option value: ", "%s%s%s", value, space, unit))
|
||||||
|
|||||||
Reference in New Issue
Block a user