diff options
author | Michael Muré <batolettre@gmail.com> | 2019-11-03 13:09:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-03 13:09:55 +0000 |
commit | 8c7c9880b1adcf876ad63ea39e46e62bd7ebde5d (patch) | |
tree | f9c6369a6593e3c00cfb3c0b45009dfb6d055d7b /vendor/github.com/MichaelMure/go-term-text/truncate.go | |
parent | f5193cc76dd1a1c1bb55194a64ef90bae2278115 (diff) | |
parent | 912b5ca320891f2a4f1a88f1a137ce8ee46a1a03 (diff) | |
download | git-bug-8c7c9880b1adcf876ad63ea39e46e62bd7ebde5d.tar.gz |
Merge pull request #228 from ludovicm67/patch-cli-label-colors
Display label colors in termui
Diffstat (limited to 'vendor/github.com/MichaelMure/go-term-text/truncate.go')
-rw-r--r-- | vendor/github.com/MichaelMure/go-term-text/truncate.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/github.com/MichaelMure/go-term-text/truncate.go b/vendor/github.com/MichaelMure/go-term-text/truncate.go new file mode 100644 index 00000000..b51bb39e --- /dev/null +++ b/vendor/github.com/MichaelMure/go-term-text/truncate.go @@ -0,0 +1,24 @@ +package text + +import "github.com/mattn/go-runewidth" + +// TruncateMax truncate a line if its length is greater +// than the given length. Otherwise, the line is returned +// as is. If truncating occur, an ellipsis is inserted at +// the end. +// Handle properly terminal color escape code +func TruncateMax(line string, length int) string { + if length <= 0 { + return "…" + } + + l := Len(line) + if l <= length || l == 0 { + return line + } + + cleaned, escapes := ExtractTermEscapes(line) + truncated := runewidth.Truncate(cleaned, length-1, "") + + return ApplyTermEscapes(truncated, escapes) + "…" +} |