From 50142e9bbcfc2ab2c83c99bae5669cf606c47014 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 8 Mar 2023 14:14:51 -0600 Subject: Fix arithmetic error in scroll causing crash --- vellum | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/vellum b/vellum index aee12d5..8cd03c2 100755 --- a/vellum +++ b/vellum @@ -1,8 +1,8 @@ -#!/bin/sh +set +x readc() { # arg: # adapted from https://unix.stackexchange.com/a/464963 - if [ -t 0 ]; then + if test -t 0 ; then # if stdin is a tty device, put it out of icanon, set min and # time to sane value, but don't otherwise touch other input or # or local settings (echo, isig, icrnl...). Take a backup of the @@ -97,8 +97,9 @@ notify_flush() { # notify_flush } scroll() { # scroll nlines -- MUTATES GLOBAL STATE - case "${1:-0}" in - \+*|\-*) n=$((n+$1)) ;; + arg="${1:-0}" + case "$arg" in + +*|-*) n=$((n+${arg#+})) ;; 0) ;; *) n=$1 ;; esac @@ -116,7 +117,7 @@ scroll() { # scroll nlines -- MUTATES GLOBAL STATE fi m=$((n+l)) - if $m -ge $max + if test $m -ge $max then m=$max fi @@ -125,8 +126,13 @@ scroll() { # scroll nlines -- MUTATES GLOBAL STATE ctty() { # ctty ## Get the controlling TTY interface. - tty <&2 || # only works if not redirecting stderr + if test -t 2 + then + # only works if not redirecting stderr + tty <&2 + else echo /proc/self/fd/1 # probably only works on linux + fi } winch() { -- cgit 1.4.1-21-gabe81