чување c1d7868087776c1bec6588efc4a7803d6cb32f1d
родитељ 868500b6dc1f634291a2a104f4f61dd6c70d83e9
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Wed, 28 Jun 2023 15:48:47 +0200
Make cols show current table width if no argument is given
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 2, додавања: 14(+), брисања: 14(-)
diff --git a/ste.1.in b/ste.1.in
@@ -38,9 +38,12 @@ Accepted commands are:
.It Ic =
Show current row.
.
-.It Ic cols Ar amount
+.It Ic cols Op Ar amount
Set table width in screen columns to
.Ar amount .
+If
+.Ar amount
+is omitted, show current table width.
.
.It Ic delete | Ic x
Delete the current table row.
diff --git a/ste.in b/ste.in
@@ -19,7 +19,7 @@ editprog=tsvedit
insprog=tsvins
tableprog=tsvtable
-# Options which normally should not be modified by user
+# Variables which normally should not be modified by user
DATE="%DATE%"
VERSION="%VERSION%"
@@ -35,7 +35,8 @@ help()
{
case "$1" in
=) printf "= - Show current row\n";;
- cols) printf "cols [amount] - Set table width in screen columns\n";;
+ cols) printf "cols [amount] - Set table width in screen columns\n"
+ printf "cols - Show the current table width\n";;
delete|x)
printf "delete | x - Delete the current table row\n";;
edit|e) printf "edit | e - Edit the current table row\n";;
@@ -143,10 +144,7 @@ while [ "$continue" -eq 1 ]; do
${tableprog} $(setopts) "$file" \
| awk '
{
- if (NR=='$currow'+2)
- {
- print '\""$sgi"'7m'\"' $0 '\""$sgi"'0m'\"'
- }
+ if (NR=='$currow'+2) print '\""$sgi"'7m'\"' $0 '\""$sgi"'0m'\"'
else print
}'
redraw=0
@@ -162,12 +160,11 @@ while [ "$continue" -eq 1 ]; do
args="$@"
case "$cmd" in
=) printf "Current row: %d\n" "$currow";;
- cols) if [ -n "$args" ]; then
- cols="$args"
- redraw=1
- else
- error "Invalid argument: '%s'" "$args"
- fi
+ cols) case "$args" in
+ "") printf "Current table width: %d\n" "$cols";;
+ *) cols="$args"
+ redraw=1;;
+ esac
;;
delete|x)
${delprog} "$file" "$((currow + 1))"
@@ -196,7 +193,7 @@ while [ "$continue" -eq 1 ]; do
redraw=1
else
error "Row out of range: '%s'" "$args"
- fi
+ fi;;
esac
;;
help|h|"")