aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/MichaelMure/go-term-text/align.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-05 22:03:19 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-05 22:33:03 +0100
commit1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6 (patch)
treee088b0fa43058afde1db71541d8fcb4b94905d6e /vendor/github.com/MichaelMure/go-term-text/align.go
parentf093be96e98284580d61664adecd0a2ff8b354e4 (diff)
downloadgit-bug-1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6.tar.gz
migrate to go modules
Diffstat (limited to 'vendor/github.com/MichaelMure/go-term-text/align.go')
-rw-r--r--vendor/github.com/MichaelMure/go-term-text/align.go67
1 files changed, 0 insertions, 67 deletions
diff --git a/vendor/github.com/MichaelMure/go-term-text/align.go b/vendor/github.com/MichaelMure/go-term-text/align.go
deleted file mode 100644
index 8262a4de..00000000
--- a/vendor/github.com/MichaelMure/go-term-text/align.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package text
-
-import (
- "strings"
-)
-
-type Alignment int
-
-const (
- NoAlign Alignment = iota
- AlignLeft
- AlignCenter
- AlignRight
-)
-
-// LineAlign align the given line as asked and apply the needed padding to match the given
-// lineWidth, while ignoring the terminal escape sequences.
-// If the given lineWidth is too small to fit the given line, it's returned without
-// padding, overflowing lineWidth.
-func LineAlign(line string, lineWidth int, align Alignment) string {
- switch align {
- case NoAlign:
- return line
- case AlignLeft:
- return LineAlignLeft(line, lineWidth)
- case AlignCenter:
- return LineAlignCenter(line, lineWidth)
- case AlignRight:
- return LineAlignRight(line, lineWidth)
- }
- panic("unknown alignment")
-}
-
-// LineAlignLeft align the given line on the left while ignoring the terminal escape sequences.
-// If the given lineWidth is too small to fit the given line, it's returned without
-// padding, overflowing lineWidth.
-func LineAlignLeft(line string, lineWidth int) string {
- return TrimSpace(line)
-}
-
-// LineAlignCenter align the given line on the center and apply the needed left
-// padding, while ignoring the terminal escape sequences.
-// If the given lineWidth is too small to fit the given line, it's returned without
-// padding, overflowing lineWidth.
-func LineAlignCenter(line string, lineWidth int) string {
- trimmed := TrimSpace(line)
- totalPadLen := lineWidth - Len(trimmed)
- if totalPadLen < 0 {
- totalPadLen = 0
- }
- pad := strings.Repeat(" ", totalPadLen/2)
- return pad + trimmed
-}
-
-// LineAlignRight align the given line on the right and apply the needed left
-// padding to match the given lineWidth, while ignoring the terminal escape sequences.
-// If the given lineWidth is too small to fit the given line, it's returned without
-// padding, overflowing lineWidth.
-func LineAlignRight(line string, lineWidth int) string {
- trimmed := TrimSpace(line)
- padLen := lineWidth - Len(trimmed)
- if padLen < 0 {
- padLen = 0
- }
- pad := strings.Repeat(" ", padLen)
- return pad + trimmed
-}