ste

Једноставни уређивач табела
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 374a9c0afcc3395613d8be18ae288f5240cb6843
родитељ 6032b8dda141508002ade67021c828e3af7ace56
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Tue, 12 Sep 2023 16:01:42 +0200

Bugfix: drawing when scrolled past screenful and first shown row has less tabs

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MTODO | 23+----------------------
ATODO.done | 26++++++++++++++++++++++++++
Mste.in | 25+++++++++++++++++++------
измењених датотека: 3, додавања: 46(+), брисања: 28(-)

diff --git a/TODO b/TODO @@ -1,27 +1,6 @@ TODO ==== -[ ] Bugfix: (table?) rows having full number of cols, then some with less than - that, then again with full number, don't get drawn correctly - - Probably due to table paging - -[x] Commands to move the current row up/down by [n] rows and/or to exact row - number - [x] to exact row number - [/] by [n] - - No need; ste handles this - [x] Add command to use the script to ste - [x] Update manpage - -[x] Handle large tables - [x] Add `lines` command similar to `cols` - </> Always output header? - Would require special handling of currently - selected row. By going up from first displayed row [n] after header, - how would one go to [n-1] while keeping the ability to go to header - row? Hence, this is maybe not a good idea - header row either won't - be output when scrolled past a screen, or it would be - unselectable/uneditable. (Also, header columns are shown as comments - when editing a row anyway.) I lean towards it not being output. - - Ultimately chose not to output header. +< > Command to insert/delete a column? < > Command to replace a cell with [string]? diff --git a/TODO.done b/TODO.done @@ -0,0 +1,26 @@ +Done todos +========== + +[x] Bugfix: (table?) rows having full number of cols, then some with less than + that, then again with full number, don't get drawn correctly + - Probably due to table paging + - Confirmed and fixed. + +[x] Commands to move the current row up/down by [n] rows and/or to exact row + number + [x] to exact row number + [/] by [n] + - No need; ste handles this + [x] Add command to use the script to ste + [x] Update manpage + +[x] Handle large tables + [x] Add `lines` command similar to `cols` + </> Always output header? - Would require special handling of currently + selected row. By going up from first displayed row [n] after header, + how would one go to [n-1] while keeping the ability to go to header + row? Hence, this is maybe not a good idea - header row either won't + be output when scrolled past a screen, or it would be + unselectable/uneditable. (Also, header columns are shown as comments + when editing a row anyway.) I lean towards it not being output. + - Ultimately chose not to output header. diff --git a/ste.in b/ste.in @@ -160,6 +160,7 @@ oldrows='' redraw=1 sgi=$(printf "%b" "\033[") +maxcols=$(sed 1q "$file" | tr -dc '\t' | wc -c | awk '{print $1+1}') while [ "$continue" -eq 1 ]; do maxrows=$(wc -l "$file" | awk '{print $1}') _cols="$cols" @@ -195,16 +196,28 @@ while [ "$continue" -eq 1 ]; do if [ "$clear" -eq 1 ]; then clear fi + firstrowcols=$(tail -n+$((firstrow+1)) "$file" | sed 1q | + tr -dc '\t' | wc -c | awk '{print $1+1}') # shellcheck disable=SC2046 tail -n+$((firstrow+1)) "$file" | + awk '{ + if (NR==1) + { + printf "%s", $0; + times='$((maxcols-firstrowcols))'; + while (times-- > 0) + printf "\t"; + printf "\n"; + } + else print + }' | head -n$((_rows-3)) | ${tableprog} $(setopts) | - awk ' -{ - if (NR=='$((currow-firstrow))'+2) - print '\""$sgi"'7m'\"' $0 '\""$sgi"'0m'\"' - else print -}' + awk '{ + if (NR=='$((currow-firstrow))'+2) + print '\""$sgi"'7m'\"' $0 '\""$sgi"'0m'\"' + else print + }' redraw=0 fi