Browse Source

fix issues with text not fitting terminal dimensions

Benton Edmondson 1 year ago
parent
commit
7eb6c51056
3 changed files with 11 additions and 2 deletions
  1. 1 1
      ansi/ansi.go
  2. 9 0
      ansi/ansi_test.go
  3. 1 1
      ui/ui.go

+ 1 - 1
ansi/ansi.go

@@ -285,7 +285,7 @@ func Height(text string) uint {
 
 func CenterVertically(prefix, centered, suffix string, height uint) string {
 	prefixHeight, centeredHeight, suffixHeight := Height(prefix), Height(centered), Height(suffix)
-	if height < centeredHeight {
+	if height <= centeredHeight {
 		return strings.Join(strings.Split(centered, "\n")[:height], "\n")
 	}
 	totalBufferSize := height - centeredHeight

+ 9 - 0
ansi/ansi_test.go

@@ -263,6 +263,15 @@ func TestCenterVertically(t *testing.T) {
 			2,
 			"middle\nis",
 		},
+
+		// perfect center
+		{
+			"top",
+			"middle\nis\nbig",
+			"bottom",
+			3,
+			"middle\nis\nbig",
+		},
 	}
 
 	for i, test := range tests {

+ 1 - 1
ui/ui.go

@@ -55,7 +55,7 @@ func (s *State) view() string {
 		if i == 0 {
 			serialized = s.h.Current().feed.Get(i).String(s.width - 4)
 		} else if i > 0 {
-			serialized = "→ " + ansi.Indent(s.h.Current().feed.Get(i).Preview(s.width-4), "  ", false)
+			serialized = "→ " + ansi.Indent(s.h.Current().feed.Get(i).Preview(s.width-8), "  ", false)
 		} else {
 			serialized = s.h.Current().feed.Get(i).Preview(s.width - 4)
 		}