diff options
author | Jakob Kaivo <jkk@ung.org> | 2018-10-14 14:12:59 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2018-10-14 14:12:59 -0400 |
commit | 773f948a2b2b6cd54a50a9f3eed8b12f4746be6d (patch) | |
tree | ae2ec4033c85afc3f8907ef3d99bc6cc641d6339 | |
parent | 07007779b8705ff37856a9c3769764025b81cd6a (diff) |
finally get columnar output working
-rwxr-xr-x | color-ls.awk | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/color-ls.awk b/color-ls.awk index 33b2211..2399736 100755 --- a/color-ls.awk +++ b/color-ls.awk @@ -35,23 +35,18 @@ BEGIN { } function columns_output() { - widest++; - column = 0; - ncolumns = columns / widest; + width = widest + 1; # include a space + printfwidth = width + 9; # account for color escape sequences + ncolumns = int(columns / width); + nrows = int(NR / ncolumns) + 1; - for (i = 1; i <= NR; i++) { - # FIXME: this is all jacked up - printf("%-*s", widest, file[(row * ncolumns) + (i % ncolumns)]); - column += widest; - if (column > columns) { - printf("\n"); - column = 0; - row++; + for (row = 0; row < nrows; row++) { + for (column = 0; column < ncolumns; column++) { + f = (column * nrows) + row + 1; + if (f <= NR) { + printf("%-*s", printfwidth, file[f]); + } } - i++; - } - - if (column != 0) { printf("\n"); } } |