shithub: hell

Download patch

ref: 54273d5c3f777e92905f5248aaab4e1755c9af9d
parent: cc7e785c8e24ddf31409fdefaf3eb26b7b90bbbf
author: penny <penny@limitedideas.org>
date: Thu Aug 7 22:45:35 EDT 2025

here we go with the hyphenator again

--- a/format.go
+++ b/format.go
@@ -6,41 +6,31 @@
 	"github.com/chzyer/readline"
 )
 
-
 func hyphenate(input string) string {
 	width := readline.GetScreenWidth()
-	remainder := input
-	var cresult string
-	var result string
-	for len([]rune(remainder)) > width-2 {
-		cresult, remainder = hyphenateline(remainder, width)
-		result += cresult
-	    if len([]rune(cresult)) == width-1 {
-	        if !strings.HasSuffix(cresult, " ") && !strings.HasPrefix(remainder, " ") {
-	            result += "-"
-	        } else {
-	            result += "\n"
-        	}
-        }
-	}	
-	return result + remainder
-}
+	var remainder = []rune(input)
+	var result []rune
 
-func hyphenateline(input string, width int) (string, string) {
-	inputrunes := []rune(input)
+	for len(remainder) > width-1 {
+		if strings.HasPrefix(string(remainder), "\n") {
+			result = append(result, '\n')
+			remainder = remainder[1:]
+			continue
+		}
 
-	if strings.HasPrefix(input, "\n") {
-		return "\n", input[1:]
-	}
+		index := strings.Index(string(remainder), "\n")
+		// If a newline is found at or before the wrap position, break there.
+		if index != -1 && index <= width-1 {
+			result = append(result, remainder[:index]...)
+			remainder = remainder[index:]
+			continue
+		}
 
-	beginstring, _, _ := strings.Cut(input, "\n")
-	begin := []rune(beginstring)
-	
-	if(len(begin) > width-1) {
-		begin = begin[:width-1]
+		// otherwise we need to break the line
+		result = append(result, remainder[:width-1]...)
+		result = append(result, '\n')
+		remainder = remainder[width-1:]
 	}
-	
-	remainder := inputrunes[len(begin):]
-	
-	return string(begin), string(remainder)
+	result = append(result, remainder...)
+	return string(result)
 }
--