diff --git a/options-table.c b/options-table.c index e31178fa..980f8684 100644 --- a/options-table.c +++ b/options-table.c @@ -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 diff --git a/tmux.1 b/tmux.1 index 9a602927..51fb4002 100644 --- a/tmux.1 +++ b/tmux.1 @@ -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 diff --git a/window-clock.c b/window-clock.c index 8cef3f9a..51620d4a 100644 --- a/window-clock.c +++ b/window-clock.c @@ -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);