Added xwindow title setting, and $HOME -> ~ in the bb path area.

This commit is contained in:
Bruce Hill 2020-02-17 16:02:53 -08:00
parent 2d9eac4237
commit f9fc99d28e
2 changed files with 25 additions and 2 deletions

24
bb.c
View File

@ -239,6 +239,7 @@ void handle_next_key_binding(bb_t *bb)
restore_term(&default_termios);
run_script(bb, binding->script);
init_term();
set_title(bb);
check_cmdfile(bb);
}
if (mouse_x != -1 && mouse_y != -1) {
@ -430,6 +431,7 @@ int populate_files(bb_t *bb, const char *path)
dirty = 1;
strcpy(bb->path, pbuf);
set_title(bb);
// Clear old files (if any)
if (bb->files) {
@ -637,6 +639,7 @@ void run_bbcmd(bb_t *bb, const char *cmd)
wait_for_process(&child);
signal(SIGTTOU, SIG_DFL);
init_term();
set_title(bb);
dirty = 1;
} else if (matches_cmd(cmd, "goto:")) { // +goto:
entry_t *e = load_entry(bb, value);
@ -752,7 +755,14 @@ void render(bb_t *bb)
move_cursor(tty_out, 0, 0);
const char *color = TITLE_COLOR;
fputs(color, tty_out);
fputs_escaped(tty_out, bb->path, color);
char *home = getenv("HOME");
if (home && strncmp(bb->path, home, strlen(home)) == 0) {
fputs("~", tty_out);
fputs_escaped(tty_out, bb->path + strlen(home), color);
} else {
fputs_escaped(tty_out, bb->path, color);
}
fputs(" \033[K\033[0m", tty_out);
static const char *help = "Press '?' to see key bindings ";
@ -1098,6 +1108,18 @@ void set_sort(bb_t *bb, const char *sort)
memmove(bb->sort, sortbuf, len);
}
/*
* Set the xwindow title property to: bb - current path
*/
void set_title(bb_t *bb)
{
char *home = getenv("HOME");
if (home && strncmp(bb->path, home, strlen(home)) == 0)
fprintf(tty_out, "\033]2;bb: ~%s\007", bb->path + strlen(home));
else
fprintf(tty_out, "\033]2;bb: %s\007", bb->path);
}
/*
* If the given entry is not viewed or selected, remove it from the
* hash, free it, and return 1.

3
bb.h
View File

@ -25,7 +25,7 @@
#include "bterm.h"
// Macros:
#define BB_VERSION "0.21.0"
#define BB_VERSION "0.21.1"
#ifndef PATH_MAX
#define PATH_MAX 4096
@ -220,6 +220,7 @@ static void set_cursor(bb_t *bb, int i);
static void set_selected(bb_t *bb, entry_t *e, int selected);
static void set_scroll(bb_t *bb, int i);
static void set_sort(bb_t *bb, const char *sort);
static void set_title(bb_t *bb);
static void sort_files(bb_t *bb);
static char *trim(char *s);
static int try_free_entry(entry_t *e);