Skip to content

Commit 5faa7bd

Browse files
committed
hints kitten: Preserve line breaks when the hint is over a line break
Fixes #8674
1 parent 8e720cc commit 5faa7bd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Detailed list of changes
115115

116116
- Remote control: Fix holding a remote control socket open causing the kitty I/O thread to go into a loop and not respond on other remote control sockets (:disc:`8670`)
117117

118+
- hints kitten: Preserve line breaks when the hint is over a line break (:iss:`8674`)
119+
118120
0.42.1 [2025-05-17]
119121
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120122

kittens/hints/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,27 @@ func main(_ *cli.Command, o *Options, args []string) (rc int, err error) {
203203
if len(mark_text) <= len(hint) {
204204
mark_text = ""
205205
} else {
206+
replaced_text := mark_text[:len(hint)]
207+
replaced_text = strings.ReplaceAll(replaced_text, "\r", "\n")
208+
if strings.Contains(replaced_text, "\n") {
209+
buf := strings.Builder{}
210+
buf.Grow(2 * len(hint))
211+
h := hint
212+
parts := strings.Split(replaced_text, "\n")
213+
for i, x := range parts {
214+
if x != "" {
215+
buf.WriteString(h[:len(x)])
216+
h = h[len(x):]
217+
}
218+
if i != len(parts)-1 {
219+
buf.WriteString("\n")
220+
}
221+
}
222+
if h != "" {
223+
buf.WriteString(h)
224+
}
225+
hint = buf.String()
226+
}
206227
mark_text = mark_text[len(hint):]
207228
}
208229
ans := hint_style(hint) + text_style(mark_text)

0 commit comments

Comments
 (0)