Skip to content

Commit

Permalink
tools: do not add trailing spaces on lxc-ls -1
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
  • Loading branch information
Christian Brauner authored and stgraber committed Sep 23, 2016
1 parent 8b4e6d6 commit 8d74baf
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/lxc/tools/lxc_ls.c
Expand Up @@ -144,7 +144,7 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
* Only print names of containers.
*/
static void ls_print_names(struct ls *l, struct lengths *lht,
size_t ls_arr, size_t termwidth);
size_t ls_arr, size_t termwidth, bool list);

/*
* Print default fancy format.
Expand Down Expand Up @@ -264,7 +264,7 @@ int main(int argc, char *argv[])
unsigned int cols = 0;
if (!my_args.ls_line)
cols = ls_get_term_width();
ls_print_names(ls_arr, &max_len, ls_size, cols);
ls_print_names(ls_arr, &max_len, ls_size, cols, my_args.ls_line);
}

ret = EXIT_SUCCESS;
Expand Down Expand Up @@ -743,7 +743,7 @@ static struct ls *ls_new(struct ls **ls, size_t *size)
}

static void ls_print_names(struct ls *l, struct lengths *lht,
size_t size, size_t termwidth)
size_t size, size_t termwidth, bool list)
{
/* If list is empty do nothing. */
if (size == 0)
Expand All @@ -752,14 +752,18 @@ static void ls_print_names(struct ls *l, struct lengths *lht,
size_t i, len = 0;
struct ls *m = NULL;
for (i = 0, m = l; i < size; i++, m++) {
printf("%-*s", lht->name_length, m->name ? m->name : "-");
len += lht->name_length;
if ((len + lht->name_length) >= termwidth) {
printf("\n");
len = 0;
if (list) {
printf("%s\n", m->name ? m->name : "-");
} else {
printf(" ");
len++;
printf("%-*s", lht->name_length, m->name ? m->name : "-");
len += lht->name_length;
if ((len + lht->name_length) >= termwidth) {
printf("\n");
len = 0;
} else {
printf(" ");
len++;
}
}
}
if (len > 0)
Expand Down

0 comments on commit 8d74baf

Please sign in to comment.