diff options
| author | Jeff Carr <[email protected]> | 2025-09-04 08:04:47 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-04 08:04:47 -0500 |
| commit | 242e30e543a5a37c9e4149d970d6fb1170f586c5 (patch) | |
| tree | d75e519ccac40214481c2442bed63904d6dbc5f4 /termSize.go | |
| parent | 041d8945c97e4045e887785b6e0d0cc2ff57183e (diff) | |
Diffstat (limited to 'termSize.go')
| -rw-r--r-- | termSize.go | 19 |
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]) + } } |
