Skip to content

Commit

Permalink
vis: simplify C status bar drawing code
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed May 17, 2018
1 parent 9cbe218 commit 81c8338
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions vis-lua.c
Expand Up @@ -73,11 +73,10 @@ static void window_status_update(Vis *vis, Win *win) {
if (focused && mode)
strcpy(left_parts[left_count++], mode);

snprintf(left_parts[left_count], sizeof(left_parts[left_count])-1, "%s%s%s",
snprintf(left_parts[left_count++], sizeof(left_parts[0]), "%s%s%s",
filename ? filename : "[No Name]",
text_modified(txt) ? " [+]" : "",
vis_macro_recording(vis) ? " @": "");
left_count++;

int count = vis_count_get(vis);
const char *keys = buffer_content0(&vis->input_queue);
Expand All @@ -90,9 +89,8 @@ static void window_status_update(Vis *vis, Win *win) {
if (sel_count > 1) {
Selection *s = view_selections_primary_get(view);
int sel_number = view_selections_number(s) + 1;
snprintf(right_parts[right_count], sizeof(right_parts[right_count])-1,
snprintf(right_parts[right_count++], sizeof(right_parts[0]),
"%d/%d", sel_number, sel_count);
right_count++;
}

size_t size = text_size(txt);
Expand All @@ -102,9 +100,8 @@ static void window_status_update(Vis *vis, Win *win) {
double tmp = ((double)pos/(double)size)*100;
percent = (size_t)(tmp+1);
}
snprintf(right_parts[right_count], sizeof(right_parts[right_count])-1,
snprintf(right_parts[right_count++], sizeof(right_parts[0]),
"%zu%%", percent);
right_count++;

if (!(options & UI_OPTION_LARGE_FILE)) {
Selection *sel = view_selections_primary_get(win->view);
Expand All @@ -114,12 +111,11 @@ static void window_status_update(Vis *vis, Win *win) {
options |= UI_OPTION_LARGE_FILE;
view_options_set(win->view, options);
}
snprintf(right_parts[right_count], sizeof(right_parts[right_count])-1,
snprintf(right_parts[right_count++], sizeof(right_parts[0]),
"%zu, %zu", line, col);
right_count++;
}

int left_len = snprintf(left, sizeof(left)-1, " %s%s%s%s%s%s%s",
int left_len = snprintf(left, sizeof(left), " %s%s%s%s%s%s%s",
left_parts[0],
left_parts[1][0] ? " » " : "",
left_parts[1],
Expand All @@ -128,7 +124,7 @@ static void window_status_update(Vis *vis, Win *win) {
left_parts[3][0] ? " » " : "",
left_parts[3]);

int right_len = snprintf(right, sizeof(right)-1, "%s%s%s%s%s%s%s ",
int right_len = snprintf(right, sizeof(right), "%s%s%s%s%s%s%s ",
right_parts[0],
right_parts[1][0] ? " « " : "",
right_parts[1],
Expand All @@ -146,7 +142,7 @@ static void window_status_update(Vis *vis, Win *win) {
if (spaces < 1)
spaces = 1;

snprintf(status, sizeof(status)-1, "%s%*s%s", left, spaces, " ", right);
snprintf(status, sizeof(status), "%s%*s%s", left, spaces, " ", right);
vis_window_status(win, status);
}

Expand Down

0 comments on commit 81c8338

Please sign in to comment.