ref: e5b736cb7f152d66efcc2c8b5e33f372dd8db2f5
parent: 2fd88f28f840f56cd16c887a8e46060912d5057f
author: penny <penny@limitedideas.org>
date: Tue Aug 5 18:12:27 EDT 2025
Maybe this finally hyphenates correctly
--- a/format.go
+++ b/format.go
@@ -3,41 +3,45 @@
import (
"strings"
- "github.com/chzyer/readline"
+ //"github.com/chzyer/readline"
)
+
func hyphenate(input string) string {width := readline.GetScreenWidth()
result, remainder := hyphenateline(input, width)
var cresult string
+ var result string
for len([]rune(remainder)) > width-1 {cresult, remainder = hyphenateline(remainder, width)
result += cresult
+ if len([]rune(cresult)) == width-1 {+ if(!strings.HasSuffix(cresult, " ")) {+ result += "-"
+ } else {+ result += "\n"
+ }
+ }
+
}
return result + remainder
}
func hyphenateline(input string, width int) (string, string) {+ inputrunes := []rune(input)
if strings.HasPrefix(input, "\n") {- return "", input[1:]
+ return "\n", input[1:]
}
- begin, _, _ := strings.Cut(input, "\n")
- hyphenate := false
-
- if len([]rune(begin)) > width-1 {- begin = string([]rune(begin)[:width-1])
- hyphenate = true
+ beginstring, _, _ := strings.Cut(input, "\n")
+ begin := []rune(beginstring)
+
+ if(len(begin) > width-1) {+ begin = begin[:width-1]
}
-
- remainder := string([]rune(input)[len([]rune(begin)):])
-
- if hyphenate == true && string([]rune(begin)[width-2:]) != " " {- begin += "-"
- }
- if len(remainder) > width-1 {- begin += "\n"
- }
- return begin, remainder
+
+ remainder := inputrunes[len(begin):]
+
+ return string(begin), string(remainder)
}
--
⑨