ste

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

чување 544fd1a167546308c1711a35359b1d5fe85d39e7
родитељ b83634bc4ea3f66c32c5c7a01771650983e93d57
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sun,  3 Sep 2023 15:42:55 +0200

Add J and K

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

Diffstat:
MTODO | 10++++++----
Mste.1.in | 16++++++++++++++++
Mste.in | 37+++++++++++++++++++++++++++++++++----
измењених датотека: 3, додавања: 55(+), брисања: 8(-)

diff --git a/TODO b/TODO @@ -1,11 +1,13 @@ TODO ==== -[~] Commands to move the current row up/down by [n] rows and/or to exact row +[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] - [ ] Add command to use the script to ste + [x] to exact row number + [/] by [n] + - No need; ste handles this + [x] Add command to use the script to ste + [x] Update manpage [ ] Handle large tables [ ] Add `lines` command similar to `cols` diff --git a/ste.1.in b/ste.1.in @@ -80,6 +80,14 @@ or after .Pq Ar + the current line, or, without arguments, to the end of table. . +.It Ic J Op Ar num +Move the current row down +.Ar num +rows. +If +.Ar num +is omitted, move the row down. +. .It Ic j Op Ar num Move the current row pointer down .Ar num @@ -88,6 +96,14 @@ If .Ar num is omitted, move the row pointer down. . +.It Ic K Op Ar num +Move the current row up +.Ar num +rows. +If +.Ar num +is omitted, move the row up. +. .It Ic k Op Ar num Move the current row pointer up .Ar num diff --git a/ste.in b/ste.in @@ -5,7 +5,7 @@ # Global options # Clear screen after update -clear=0 +clear=1 # Table output width in screen columns cols=80 # Pass -m to table @@ -17,6 +17,7 @@ noansi=1 delprog=tsvdel editprog=tsvedit insprog=tsvins +moveprog=tsvmove tableprog=tsvtable # Variables which normally should not be modified by user @@ -52,8 +53,12 @@ help() printf "insert + | i + - Add a row to the table after the " printf "current line\n" printf "insert | i - Add a row to the end of table\n";; + J) printf "J [num] - Move the current row down num rows\n" + printf "J - Move the current row down\n";; j) printf "j [num] - Move the current row pointer down num rows\n" printf "j - Move the current row pointer down\n";; + K) printf "K [num] - Move the current row up num rows\n" + printf "K - Move the current row up\n";; k) printf "k [num] - Move the current row pointer up num rows\n" printf "k - Move the current row pointer up\n";; print|p) @@ -61,7 +66,7 @@ help() set) printf "set [[no]option] - Turn option on/off\n" printf "set - Show option states\n";; "") printf "Commands: = cols delete e edit exit G g h help i " - printf "insert j k p print q set x\n" + printf "insert J j K k p print q set x\n" printf "help [command] - Show help about a command\n";; *) error "Unknown command '%s'" "$args";; esac @@ -141,8 +146,8 @@ while [ "$continue" -eq 1 ]; do clear fi # shellcheck disable=SC2046 - ${tableprog} $(setopts) "$file" \ - | awk ' + ${tableprog} $(setopts) "$file" | + awk ' { if (NR=='$currow'+2) print '\""$sgi"'7m'\"' $0 '\""$sgi"'0m'\"' else print @@ -217,6 +222,18 @@ while [ "$continue" -eq 1 ]; do *) error "Invalid argument: '%s'" "$args";; esac ;; + J) torow=$((currow + 1)) + if [ -n "$args" ]; then + torow=$((currow + args)) + fi + if [ "$torow" -lt "$rows" ]; then + ${moveprog} "$file" "$((currow+1))" "$((torow+1))" + currow="$torow" + redraw=1 + else + error "Row out of range: '%s'" "$torow" + fi + ;; j) torow=$((currow + 1)) if [ -n "$args" ]; then torow=$((currow + args)) @@ -228,6 +245,18 @@ while [ "$continue" -eq 1 ]; do error "Row out of range: '%s'" "$torow" fi ;; + K) torow=$((currow - 1)) + if [ -n "$args" ]; then + torow=$((currow - args)) + fi + if [ "$torow" -ge 0 ]; then + ${moveprog} "$file" "$((currow+1))" "$((torow+1))" + currow="$torow" + redraw=1 + else + error "Row out of range: '%s'" "$torow" + fi + ;; k) torow=$((currow - 1)) if [ -n "$args" ]; then torow=$((currow - args))