Skip to content

Commit

Permalink
add setstatus cmd to configure status bar alignment
Browse files Browse the repository at this point in the history
Add 'setstatus align <left|right>' command which allows to
change the status text alignment (default right).

Signed-off-by: Vadym Kochan <[email protected]>
  • Loading branch information
vkochan committed Jan 6, 2021
1 parent dbc7f8c commit e54a9ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ static Cmd commands[] = {
{ "setcwd", { setcwd, { NULL } } },
/* change layout by name or select next */
{ "setlayout", { setlayout, { NULL } } },
/* status bar */
{ "setstatus", { setstatus, { NULL } } },
};

/* gets executed when dvtm is started */
Expand Down
37 changes: 33 additions & 4 deletions dvtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ typedef struct {
} Cmd;

enum { BAR_TOP, BAR_BOTTOM, BAR_OFF };
enum { BAR_LEFT, BAR_RIGHT };

typedef struct {
int fd;
int pos, lastpos;
int align;
bool autohide;
unsigned short int h;
unsigned short int y;
Expand Down Expand Up @@ -228,6 +230,7 @@ static void setcwd(const char *args[]);
static void senduserevt(const char *args[]);
static void sendevtfmt(const char *fmt, ... );
static void docmd(const char *args[]);
static void setstatus(const char *args[]);

/* commands for use by mouse bindings */
static void mouse_focus(const char *args[]);
Expand Down Expand Up @@ -276,7 +279,13 @@ static unsigned int seltags;
static unsigned int tagset[2] = { 1, 1 };
static bool mouse_events_enabled = ENABLE_MOUSE;
static Layout *layout = layouts;
static StatusBar bar = { .fd = -1, .lastpos = BAR_POS, .pos = BAR_POS, .autohide = BAR_AUTOHIDE, .h = 1 };
static StatusBar bar = { .fd = -1,
.lastpos = BAR_POS,
.pos = BAR_POS,
.align = BAR_RIGHT,
.autohide = BAR_AUTOHIDE,
.h = 1
};
static CmdFifo cmdfifo = { .fd = -1 };
static EvtFifo evtfifo = { .fd = -1 };
static const char *shell;
Expand Down Expand Up @@ -421,9 +430,12 @@ drawbar(void) {
size_t numchars = mbstowcs(wbuf, bar.text, sizeof bar.text);

if (numchars != (size_t)-1 && (width = wcswidth(wbuf, maxwidth)) != -1) {
int pos;
for (pos = 0; pos + width < maxwidth; pos++)
addch(' ');
int pos = 0;

if (bar.align == BAR_RIGHT) {
for (; pos + width < maxwidth; pos++)
addch(' ');
}

for (size_t i = 0; i < numchars; i++) {
pos += wcwidth(wbuf[i]);
Expand All @@ -432,6 +444,11 @@ drawbar(void) {
addnwstr(wbuf+i, 1);
}

if (bar.align == BAR_LEFT) {
for (; pos + width < maxwidth; pos++)
addch(' ');
}

clrtoeol();
}

Expand Down Expand Up @@ -1977,6 +1994,18 @@ static void docmd(const char *args[]) {
handle_cmd(cmdbuf);
}

static void setstatus(const char *args[]) {
if (!args || !args[0] || !args[1])
return;

if (strcmp("align", args[0]) == 0) {
if (strcmp("left", args[1]) == 0)
bar.align = BAR_LEFT;
else if (strcmp("right", args[1]) == 0)
bar.align = BAR_RIGHT;
}
}

static void
handle_mouse(void) {
#ifdef CONFIG_MOUSE
Expand Down

0 comments on commit e54a9ad

Please sign in to comment.