Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(bugfix): fix word wrapping on logs #37

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/reflow v0.3.0
github.com/muesli/termenv v0.15.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
23 changes: 4 additions & 19 deletions pkg/charm/models/panels/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/everettraven/buoy/pkg/charm/styles"
"github.com/muesli/reflow/wrap"
"github.com/sahilm/fuzzy"
)

Expand Down Expand Up @@ -77,8 +78,9 @@ func NewLogs(keys LogsKeyMap, name string) *Logs {
searchbar := textinput.New()
searchbar.Prompt = "> "
searchbar.Placeholder = "search term"
vp := viewport.New(10, 10)
return &Logs{
viewport: viewport.New(10, 10),
viewport: vp,
searchbar: searchbar,
name: name,
mutex: &sync.Mutex{},
Expand Down Expand Up @@ -250,22 +252,5 @@ func matched(index int, matches []int) bool {
}

func wrapLogs(logs string, maxWidth int) string {
splitLogs := strings.Split(logs, "\n")
var logsBuilder strings.Builder
for _, log := range splitLogs {
if len(log) > maxWidth {
segs := (len(log) / maxWidth)
for seg := 0; seg < segs; seg++ {
logsBuilder.WriteString(log[:maxWidth])
logsBuilder.WriteString("\n")
log = log[maxWidth:]
}
//write any leftovers
logsBuilder.WriteString(log)
} else {
logsBuilder.WriteString(log)
}
logsBuilder.WriteString("\n")
}
return logsBuilder.String()
return wrap.String(logs, maxWidth)
}
5 changes: 4 additions & 1 deletion pkg/charm/models/tabber.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (t *Tabber) Init() tea.Cmd {
}

func (t *Tabber) Update(msg tea.Msg) (*Tabber, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
Expand All @@ -47,14 +46,17 @@ func (t *Tabber) Update(msg tea.Msg) (*Tabber, tea.Cmd) {
if t.selected > len(t.tabs)-1 {
t.selected = 0
}
return t, tea.ClearScreen
case key.Matches(msg, t.keyMap.TabLeft):
t.selected--
if t.selected < 0 {
t.selected = len(t.tabs) - 1
}
return t, tea.ClearScreen
}
case tea.WindowSizeMsg:
t.width = msg.Width
var cmd tea.Cmd
for i := range t.tabs {
var tempCmd tea.Cmd
t.tabs[i].Model, tempCmd = t.tabs[i].Model.Update(msg)
Expand All @@ -63,6 +65,7 @@ func (t *Tabber) Update(msg tea.Msg) (*Tabber, tea.Cmd) {
return t, cmd
}

var cmd tea.Cmd
t.tabs[t.selected].Model, cmd = t.tabs[t.selected].Model.Update(msg)
return t, cmd
}
Expand Down