ref: 70d7fee70967e8276d6c29ca4b1d29797a3213da
parent: b985a98b4941ad9b86dbdf43ac0bf844728c7ea7
author: penny <penny@limitedideas.org>
date: Thu Jul 31 19:04:57 EDT 2025
fix some newline bullcrap with the hypenator
--- a/format.go
+++ b/format.go
@@ -4,11 +4,11 @@
import "strings"
import "github.com/chzyer/readline"
-func hyphenate(input string) (string) {+func hyphenate(input string) string {width := readline.GetScreenWidth()
result, remainder := hyphenateline(input, width)
var cresult string
- for(len(remainder) > width -1) {+ for len(remainder) > width-1 {cresult, remainder = hyphenateline(remainder, width)
result += cresult
}
@@ -16,19 +16,26 @@
}
func hyphenateline(input string, width int) (string, string) {+
+ if strings.HasPrefix(input, "\n") {+ return "\n", input[1:]
+ }
+
begin, _, _ := strings.Cut(input, "\n")
hyphenate := false
-
- if(len(begin) > width-1) {+
+ if len(begin) > width-1 {begin = begin[:width-1]
hyphenate = true
}
-
+
remainder := input[len(begin):]
-
- if(hyphenate == true && begin[width-2] != ' ') {+
+ if hyphenate == true && begin[width-2] != ' ' {begin += "-"
}
- begin += "\n"
+ if len(remainder) > width-1 {+ begin += "\n"
+ }
return begin, remainder
-}
\ No newline at end of file
+}
--
⑨