summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-04 08:04:47 -0500
committerJeff Carr <[email protected]>2025-09-04 08:04:47 -0500
commit242e30e543a5a37c9e4149d970d6fb1170f586c5 (patch)
treed75e519ccac40214481c2442bed63904d6dbc5f4
parent041d8945c97e4045e887785b6e0d0cc2ff57183e (diff)
add TerminalChomp() in honor of Larry Wall & Perlv0.0.5v0.0.4v0.0.3
-rw-r--r--termSize.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/termSize.go b/termSize.go
index 133bba7..cc9d5af 100644
--- a/termSize.go
+++ b/termSize.go
@@ -1,9 +1,11 @@
package cobol
import (
- "log"
"os"
+ "strings"
+ "unicode"
+ "go.wit.com/log"
"golang.org/x/term"
)
@@ -31,7 +33,18 @@ func getTerminalWidth() (int, bool) {
return WIDTH, false
}
-func TerminalCut(cut string) {
+// like the perl Chomp but with the terminal width
+func TerminalChomp(cut string) string {
i, _ := getTerminalWidth()
- log.Printf("%s\n", cut[0:i])
+ // log.Info("cobol.TerminalCut() at ", i)
+
+ // TrimRightFunc removes all trailing runes r from the string s that satisfy f(r).
+ // unicode.IsSpace reports whether the rune is a space character.
+ cut = strings.TrimRightFunc(cut, unicode.IsSpace)
+
+ if i >= len(cut) {
+ return cut
+ } else {
+ return log.Sprintf("%s", cut[0:i])
+ }
}