Improve message wrapping behavior
This commit is contained in:
parent
3536438dd1
commit
437997872a
@ -16,6 +16,7 @@ import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/muesli/reflow/wordwrap"
|
||||
"github.com/muesli/reflow/wrap"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@ -647,8 +648,11 @@ func (m *chatModel) renderMessage(i int) string {
|
||||
content := strings.TrimRight(sb.String(), "\n")
|
||||
|
||||
if m.wrap {
|
||||
wrapWidth := m.content.Width - messageStyle.GetHorizontalPadding() - 2
|
||||
content = wordwrap.String(content, wrapWidth)
|
||||
wrapWidth := m.content.Width - messageStyle.GetHorizontalPadding()
|
||||
// first we word-wrap text to slightly less than desired width (since
|
||||
// wordwrap seems to have an off-by-1 issue), then hard wrap at
|
||||
// desired with
|
||||
content = wrap.String(wordwrap.String(content, wrapWidth-2), wrapWidth)
|
||||
}
|
||||
|
||||
return messageStyle.Width(0).Render(content)
|
||||
|
Loading…
Reference in New Issue
Block a user