Add --no-clock option to hide status bar clock
This commit is contained in:
parent
2fef459237
commit
0ffb02a954
2 changed files with 35 additions and 17 deletions
|
|
@ -11,6 +11,8 @@ make -B CC=clang
|
||||||
./moerx --prefix x work # same as -p x
|
./moerx --prefix x work # same as -p x
|
||||||
./moerx -s bottom work # show the session status line at the bottom
|
./moerx -s bottom work # show the session status line at the bottom
|
||||||
./moerx --status bottom work # same as -s bottom
|
./moerx --status bottom work # same as -s bottom
|
||||||
|
./moerx --no-cwd work # show [moerx] instead of the directory
|
||||||
|
./moerx --no-clock work # hide the status bar clock
|
||||||
./moerx --help # all shortcuts
|
./moerx --help # all shortcuts
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -39,6 +41,10 @@ existing session for all attached clients; omitting the option preserves its
|
||||||
position. Prompts and messages follow the status line. Restart servers from
|
position. Prompts and messages follow the status line. Restart servers from
|
||||||
older versions once before using this option.
|
older versions once before using this option.
|
||||||
|
|
||||||
|
Use `--no-cwd` to show `[moerx]` on the left of the status bar instead of the
|
||||||
|
current directory, and `--no-clock` to hide the clock on the right. These
|
||||||
|
options apply when starting a new session.
|
||||||
|
|
||||||
## What it does
|
## What it does
|
||||||
|
|
||||||
- One persistent server per session (a Unix socket in
|
- One persistent server per session (a Unix socket in
|
||||||
|
|
|
||||||
30
moerx.c
30
moerx.c
|
|
@ -1127,6 +1127,7 @@ struct Session {
|
||||||
int w, h;
|
int w, h;
|
||||||
int status_bottom;
|
int status_bottom;
|
||||||
int show_cwd;
|
int show_cwd;
|
||||||
|
int show_clock;
|
||||||
Window *windows;
|
Window *windows;
|
||||||
Window *cur, *last;
|
Window *cur, *last;
|
||||||
int nwin;
|
int nwin;
|
||||||
|
|
@ -1797,17 +1798,21 @@ static void status_draw(Grid *g, Session *s, Client *c) {
|
||||||
scr_put(g, x, y, ' ', P_STATUS, DEFAULT_COLOR, 0);
|
scr_put(g, x, y, ' ', P_STATUS, DEFAULT_COLOR, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char clockbuf[32];
|
||||||
|
clockbuf[0] = '\0';
|
||||||
|
int right_len = 0;
|
||||||
|
int rx = s->w;
|
||||||
|
if (s->show_clock) {
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm tmv;
|
struct tm tmv;
|
||||||
localtime_r(&t, &tmv);
|
localtime_r(&t, &tmv);
|
||||||
char clockbuf[32];
|
|
||||||
strftime(clockbuf, sizeof clockbuf, "%H:%M:%S", &tmv);
|
strftime(clockbuf, sizeof clockbuf, "%H:%M:%S", &tmv);
|
||||||
|
right_len = text_width(clockbuf) + 2;
|
||||||
int right_len = text_width(clockbuf) + 2;
|
|
||||||
if (right_len > s->w) right_len = s->w;
|
if (right_len > s->w) right_len = s->w;
|
||||||
int rx = s->w - right_len;
|
rx = s->w - right_len;
|
||||||
if (rx < 0) rx = 0;
|
if (rx < 0) rx = 0;
|
||||||
status_right_draw(g, rx, y, clockbuf);
|
status_right_draw(g, rx, y, clockbuf);
|
||||||
|
}
|
||||||
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (Window *w = s->windows; w; w = w->next) {
|
for (Window *w = s->windows; w; w = w->next) {
|
||||||
|
|
@ -1877,8 +1882,10 @@ static void status_draw(Grid *g, Session *s, Client *c) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s->show_clock) {
|
||||||
/* keep the clock visible even if a message or window list is long */
|
/* keep the clock visible even if a message or window list is long */
|
||||||
status_right_draw(g, rx, y, clockbuf);
|
status_right_draw(g, rx, y, clockbuf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void menu_draw(Grid *g, Session *s, Client *c) {
|
static void menu_draw(Grid *g, Session *s, Client *c) {
|
||||||
|
|
@ -3483,7 +3490,7 @@ static void server_fail(int readyfd, const char *stage, int err) {
|
||||||
close(readyfd);
|
close(readyfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void server_start(const char *path, const char *name, int readyfd, int show_cwd) {
|
static void server_start(const char *path, const char *name, int readyfd, int show_cwd, int show_clock) {
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
|
|
@ -3532,6 +3539,7 @@ static void server_start(const char *path, const char *name, int readyfd, int sh
|
||||||
s->h = 24;
|
s->h = 24;
|
||||||
s->running = 1;
|
s->running = 1;
|
||||||
s->show_cwd = show_cwd;
|
s->show_cwd = show_cwd;
|
||||||
|
s->show_clock = show_clock;
|
||||||
s->last_status = now_ms();
|
s->last_status = now_ms();
|
||||||
|
|
||||||
Window *w = window_new(s, NULL);
|
Window *w = window_new(s, NULL);
|
||||||
|
|
@ -3611,7 +3619,7 @@ static int ensure_socket_dir(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int spawn_server(const char *path, const char *name, int show_cwd) {
|
static int spawn_server(const char *path, const char *name, int show_cwd, int show_clock) {
|
||||||
if (ensure_socket_dir() < 0) return -1;
|
if (ensure_socket_dir() < 0) return -1;
|
||||||
char dir[PATH_MAX], lockpath[PATH_MAX + 64];
|
char dir[PATH_MAX], lockpath[PATH_MAX + 64];
|
||||||
socket_dir(dir, sizeof dir);
|
socket_dir(dir, sizeof dir);
|
||||||
|
|
@ -3659,7 +3667,7 @@ static int spawn_server(const char *path, const char *name, int show_cwd) {
|
||||||
if (dn > 2) close(dn);
|
if (dn > 2) close(dn);
|
||||||
}
|
}
|
||||||
close(lock);
|
close(lock);
|
||||||
server_start(path, name, p[1], show_cwd);
|
server_start(path, name, p[1], show_cwd, show_clock);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
|
|
@ -3916,7 +3924,7 @@ static int run_client(int fd, const char *name, unsigned char prefix, int status
|
||||||
|
|
||||||
static void print_help(FILE *out) {
|
static void print_help(FILE *out) {
|
||||||
fprintf(out,
|
fprintf(out,
|
||||||
"usage: moerx [-p letter] [-s top|bottom] [--no-cwd] [session]\n"
|
"usage: moerx [-p letter] [-s top|bottom] [--no-cwd] [--no-clock] [session]\n"
|
||||||
" moerx -h | --help\n"
|
" moerx -h | --help\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Attach to a running session, or start it if it is not running.\n"
|
"Attach to a running session, or start it if it is not running.\n"
|
||||||
|
|
@ -3926,6 +3934,7 @@ static void print_help(FILE *out) {
|
||||||
"New sessions default to top; an explicit choice updates all attached clients.\n"
|
"New sessions default to top; an explicit choice updates all attached clients.\n"
|
||||||
"Without -s, keep the session position.\n"
|
"Without -s, keep the session position.\n"
|
||||||
"Use --no-cwd to hide the current directory in the status bar.\n"
|
"Use --no-cwd to hide the current directory in the status bar.\n"
|
||||||
|
"Use --no-clock to hide the clock in the status bar.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Use -p x (or --prefix x) to choose Ctrl-X as this client's prefix.\n"
|
"Use -p x (or --prefix x) to choose Ctrl-X as this client's prefix.\n"
|
||||||
"Letters a through z are supported (case-insensitive); the default is a (Ctrl-A).\n"
|
"Letters a through z are supported (case-insensitive); the default is a (Ctrl-A).\n"
|
||||||
|
|
@ -4001,6 +4010,7 @@ int main(int argc, char **argv) {
|
||||||
unsigned char prefix = DEFAULT_PREFIX;
|
unsigned char prefix = DEFAULT_PREFIX;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
int show_cwd = 1;
|
int show_cwd = 1;
|
||||||
|
int show_clock = 1;
|
||||||
while (argi < argc && argv[argi][0] == '-' && argv[argi][1]) {
|
while (argi < argc && argv[argi][0] == '-' && argv[argi][1]) {
|
||||||
const char *option = argv[argi++];
|
const char *option = argv[argi++];
|
||||||
if (strcmp(option, "--") == 0) break;
|
if (strcmp(option, "--") == 0) break;
|
||||||
|
|
@ -4010,6 +4020,8 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
if (strcmp(option, "--no-cwd") == 0) {
|
if (strcmp(option, "--no-cwd") == 0) {
|
||||||
show_cwd = 0;
|
show_cwd = 0;
|
||||||
|
} else if (strcmp(option, "--no-clock") == 0) {
|
||||||
|
show_clock = 0;
|
||||||
} else if (strcmp(option, "-p") == 0 || strcmp(option, "--prefix") == 0) {
|
} else if (strcmp(option, "-p") == 0 || strcmp(option, "--prefix") == 0) {
|
||||||
if (argi >= argc || !parse_prefix(argv[argi], &prefix)) {
|
if (argi >= argc || !parse_prefix(argv[argi], &prefix)) {
|
||||||
fprintf(stderr, "moerx: %s requires a letter from a through z\n", option);
|
fprintf(stderr, "moerx: %s requires a letter from a through z\n", option);
|
||||||
|
|
@ -4046,7 +4058,7 @@ int main(int argc, char **argv) {
|
||||||
make_socket_path(name, path, sizeof path);
|
make_socket_path(name, path, sizeof path);
|
||||||
|
|
||||||
int fd = connect_session(path);
|
int fd = connect_session(path);
|
||||||
if (fd < 0) fd = spawn_server(path, name, show_cwd);
|
if (fd < 0) fd = spawn_server(path, name, show_cwd, show_clock);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, "moerx: cannot start or attach session '%s': %s\n",
|
fprintf(stderr, "moerx: cannot start or attach session '%s': %s\n",
|
||||||
name, strerror(errno));
|
name, strerror(errno));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue