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]) + } }