add TerminalChomp() in honor of Larry Wall & Perl
This commit is contained in:
parent
041d8945c9
commit
242e30e543
19
termSize.go
19
termSize.go
|
@ -1,9 +1,11 @@
|
||||||
package cobol
|
package cobol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,7 +33,18 @@ func getTerminalWidth() (int, bool) {
|
||||||
return WIDTH, false
|
return WIDTH, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func TerminalCut(cut string) {
|
// like the perl Chomp but with the terminal width
|
||||||
|
func TerminalChomp(cut string) string {
|
||||||
i, _ := getTerminalWidth()
|
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])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue