diff options
author | Jakob Kaivo <jkk@ung.org> | 2018-10-14 13:43:22 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2018-10-14 13:43:22 -0400 |
commit | 39acc8e87ff2c57e08a5b3c79f2f902ff0f862e5 (patch) | |
tree | 477bc8fd0339c690fa4ef4cc1d2892bf309688a6 | |
parent | b5756941692e2452fc0ffb7f8e9e51c95d2e9d6c (diff) |
fix up row_output()
-rwxr-xr-x | color-ls.awk | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/color-ls.awk b/color-ls.awk index 056bc9d..966ff00 100755 --- a/color-ls.awk +++ b/color-ls.awk @@ -28,20 +28,20 @@ BEGIN { if (output == "l" || output == "o" || output == "n" || output == "g") { long = 1; } + columns = ENVIRON["COLUMNS"]; + if (columns == 0) { + columns = 80; + } } function columns_output() { widest++; column = 0; - columns = ENVIRON["COLUMNS"]; - if (columns == 0) { - columns = 80; - } ncolumns = columns / widest; for (i = 1; i <= NR; i++) { # FIXME: this is all jacked up - printf("%-*s", widest, all[(row * ncolumns) + (i % ncolumns)]); + printf("%-*s", widest, file[(row * ncolumns) + (i % ncolumns)]); column += widest; if (column > columns) { printf("\n"); @@ -57,20 +57,18 @@ function columns_output() { } function row_output() { - widest++; + width = widest + 1; # include a space + printfwidth = width + 9; # account for color escape sequences column = 0; - columns = ENVIRON["COLUMNS"]; - if (columns == 0) { - columns = 80; - } + printf("Columns: %d\nWidth: %d\n", columns, width); for (i = 1; i <= NR; i++) { - printf("%-*s ", widest, file[i]); - column += widest; + column += width; if (column > columns) { printf("\n"); - column = 0; + column = width; } + printf("%-*s", printfwidth, file[i]); } if (column != 0) { |