Add seconds options for clock mode, from augustus7613 dot mail at pm dot

me in GitHub issue 4697.
This commit is contained in:
nicm
2025-11-25 21:24:27 +00:00
parent 1d89233047
commit f0dec832b8
3 changed files with 19 additions and 9 deletions

View File

@@ -37,7 +37,7 @@ static const char *options_table_mode_keys_list[] = {
"emacs", "vi", NULL
};
static const char *options_table_clock_mode_style_list[] = {
"12", "24", NULL
"12", "24", "12-with-seconds", "24-with-seconds", NULL
};
static const char *options_table_status_list[] = {
"off", "on", "2", "3", "4", "5", NULL

2
tmux.1
View File

@@ -4925,7 +4925,7 @@ option is enabled.
Set clock colour.
.Pp
.It Xo Ic clock-mode-style
.Op Ic 12 | 24
.Op Ic 12 | 24 | 12-with-seconds | 24-with-seconds
.Xc
Set clock hour format.
.Pp

View File

@@ -45,7 +45,7 @@ const struct window_mode window_clock_mode = {
};
struct window_clock_mode_data {
struct screen screen;
struct screen screen;
time_t tim;
struct event timer;
};
@@ -142,7 +142,7 @@ window_clock_timer_callback(__unused int fd, __unused short events, void *arg)
t = time(NULL);
gmtime_r(&t, &now);
gmtime_r(&data->tim, &then);
if (now.tm_min == then.tm_min)
if (now.tm_sec == then.tm_sec)
return;
data->tim = t;
@@ -207,11 +207,12 @@ window_clock_draw_screen(struct window_mode_entry *wme)
{
struct window_pane *wp = wme->wp;
struct window_clock_mode_data *data = wme->data;
struct screen_write_ctx ctx;
struct screen_write_ctx ctx;
int colour, style;
struct screen *s = &data->screen;
struct grid_cell gc;
char tim[64], *ptr;
const char *timeformat;
time_t t;
struct tm *tm;
u_int i, j, x, y, idx;
@@ -223,14 +224,23 @@ window_clock_draw_screen(struct window_mode_entry *wme)
t = time(NULL);
tm = localtime(&t);
if (style == 0) {
strftime(tim, sizeof tim, "%l:%M ", localtime(&t));
if (style == 0 || style == 2) {
if (style == 2)
timeformat = "%l:%M:%S ";
else
timeformat = "%l:%M ";
strftime(tim, sizeof tim, timeformat, localtime(&t));
if (tm->tm_hour >= 12)
strlcat(tim, "PM", sizeof tim);
else
strlcat(tim, "AM", sizeof tim);
} else
strftime(tim, sizeof tim, "%H:%M", tm);
} else {
if (style == 3)
timeformat = "%H:%M:%S";
else
timeformat = "%H:%M";
strftime(tim, sizeof tim, timeformat, tm);
}
screen_write_clearscreen(&ctx, 8);