ref: 1d76a2779b42ddaedb49ebc546c390ea3b295945
parent: 78e3bc4908c7b6c2d7b5e39ba485fb0f8e0113f7
author: penny <penny@limitedideas.org>
date: Thu Jul 31 16:18:38 EDT 2025
Hyphenate text to terminal width
--- /dev/null
+++ b/format.go
@@ -1,0 +1,32 @@
+package main
+
+//import "fmt"
+import "strings"
+
+func hyphenate(input string, width int) (string) {+ result, remainder := hyphenateline(input, width)
+ var cresult string
+ for(len(remainder) > width -1) {+ cresult, remainder = hyphenateline(remainder, width)
+ result += cresult
+ }
+ return result + remainder
+}
+
+func hyphenateline(input string, width int) (string, string) {+ begin, _, _ := strings.Cut(input, "\n")
+ hyphenate := false
+
+ if(len(begin) > width-1) {+ begin = begin[:width-1]
+ hyphenate = true
+ }
+
+ remainder := input[len(begin):]
+
+ if(hyphenate == true && begin[width-2] != ' ') {+ begin += "-"
+ }
+ begin += "\n"
+ return begin, remainder
+}
\ No newline at end of file
--- a/mastodon.go
+++ b/mastodon.go
@@ -194,7 +194,7 @@
for _, _ = range media {postfix = postfix + "🖼️"
}
- plaintext = fmt.Sprintf("%v %v", poststring, postfix)+ plaintext = hyphenate(fmt.Sprintf("%v %v", poststring, postfix), 80)return
}
--
⑨