Improve message wrapping behavior
This commit is contained in:
parent
3536438dd1
commit
437997872a
@ -16,6 +16,7 @@ import (
|
|||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/muesli/reflow/wordwrap"
|
"github.com/muesli/reflow/wordwrap"
|
||||||
|
"github.com/muesli/reflow/wrap"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -647,8 +648,11 @@ func (m *chatModel) renderMessage(i int) string {
|
|||||||
content := strings.TrimRight(sb.String(), "\n")
|
content := strings.TrimRight(sb.String(), "\n")
|
||||||
|
|
||||||
if m.wrap {
|
if m.wrap {
|
||||||
wrapWidth := m.content.Width - messageStyle.GetHorizontalPadding() - 2
|
wrapWidth := m.content.Width - messageStyle.GetHorizontalPadding()
|
||||||
content = wordwrap.String(content, wrapWidth)
|
// 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)
|
return messageStyle.Width(0).Render(content)
|
||||||
|
Loading…
Reference in New Issue
Block a user