diff --git a/internal/ui/diff/model.go b/internal/ui/diff/model.go index 95f93d7..769a6dd 100644 --- a/internal/ui/diff/model.go +++ b/internal/ui/diff/model.go @@ -10,6 +10,7 @@ import ( "charm.land/lipgloss/v2" "github.com/anotherhadi/spilltea/internal/keys" "github.com/anotherhadi/spilltea/internal/style" + "github.com/anotherhadi/spilltea/internal/util" ) type slot struct { @@ -149,7 +150,7 @@ func (m *Model) refreshViewports() { placeholder := lipgloss.Place( m.leftViewport.Width(), m.leftViewport.Height(), lipgloss.Center, lipgloss.Center, - s.Faint.Render(" <(^_^)>\nsend two entries here to compare"), + s.Faint.Render(util.CenterLines("<(^_^)>", "send two entries here to compare")), ) m.leftViewport.SetContent(placeholder) m.rightViewport.SetContent("") @@ -161,7 +162,7 @@ func (m *Model) refreshViewports() { placeholder := lipgloss.Place( m.rightViewport.Width(), m.rightViewport.Height(), lipgloss.Center, lipgloss.Center, - s.Faint.Render(" (・3・)\nwaiting for second entry…"), + s.Faint.Render(util.CenterLines("(・3・)", "waiting for second entry…")), ) m.rightViewport.SetContent(placeholder) return diff --git a/internal/ui/findings/model.go b/internal/ui/findings/model.go index 764a56c..0d70824 100644 --- a/internal/ui/findings/model.go +++ b/internal/ui/findings/model.go @@ -15,6 +15,7 @@ import ( "github.com/anotherhadi/spilltea/internal/db" "github.com/anotherhadi/spilltea/internal/keys" "github.com/anotherhadi/spilltea/internal/style" + "github.com/anotherhadi/spilltea/internal/util" ) type Model struct { @@ -116,7 +117,7 @@ func (m *Model) refreshBody() { func renderMarkdown(src string, width int) string { if src == "" { - return style.S.Faint.Render(" (ㆆ _ ㆆ)\nno description") + return style.S.Faint.Render(util.CenterLines("(ㆆ _ ㆆ)", "no description")) } tmpl, err := template.New("").Parse(src) if err != nil { diff --git a/internal/ui/findings/view.go b/internal/ui/findings/view.go index 35a4f63..602b0a5 100644 --- a/internal/ui/findings/view.go +++ b/internal/ui/findings/view.go @@ -54,7 +54,7 @@ func (m *Model) renderList() string { return lipgloss.Place( m.listViewport.Width(), m.listViewport.Height(), lipgloss.Center, lipgloss.Center, - s.Faint.Render(" (҂◡_◡) ᕤ\nno findings"), + s.Faint.Render(util.CenterLines("(҂◡_◡) ᕤ", "no findings")), ) } diff --git a/internal/ui/history/update.go b/internal/ui/history/update.go index 42ded2c..91608fe 100644 --- a/internal/ui/history/update.go +++ b/internal/ui/history/update.go @@ -307,7 +307,7 @@ func (m *Model) refreshBody() { } if raw == "" { w, h := m.bodyViewport.Width(), m.bodyViewport.Height() - m.bodyViewport.SetContent(lipgloss.Place(w, h, lipgloss.Center, lipgloss.Center, style.S.Faint.Render(" (˘・_・˘)\nno response stored"))) + m.bodyViewport.SetContent(lipgloss.Place(w, h, lipgloss.Center, lipgloss.Center, style.S.Faint.Render(util.CenterLines("(˘・_・˘)", "no response stored")))) return } m.bodyViewport.SetContent(style.HighlightHTTP(raw)) diff --git a/internal/ui/history/view.go b/internal/ui/history/view.go index b55fe7a..a5d920b 100644 --- a/internal/ui/history/view.go +++ b/internal/ui/history/view.go @@ -9,6 +9,7 @@ import ( "github.com/anotherhadi/spilltea/internal/icons" "github.com/anotherhadi/spilltea/internal/keys" "github.com/anotherhadi/spilltea/internal/style" + "github.com/anotherhadi/spilltea/internal/util" ) func (m Model) View() tea.View { @@ -84,9 +85,9 @@ func (m *Model) renderList() string { ) } if len(m.entries) == 0 { - msg := " (⌐■_■)\nno history yet" + msg := util.CenterLines("(⌐■_■)", "no history yet") if m.searchKind != searchKindOff { - msg = "ʕノ•ᴥ•ʔノ ︵ ┻━┻\n no results" + msg = util.CenterLines("ʕノ•ᴥ•ʔノ ︵ ┻━┻", "no results") } return lipgloss.Place( m.listViewport.Width(), m.listViewport.Height(), diff --git a/internal/ui/intercept/view.go b/internal/ui/intercept/view.go index 26e9a05..7f87e73 100644 --- a/internal/ui/intercept/view.go +++ b/internal/ui/intercept/view.go @@ -8,6 +8,7 @@ import ( "charm.land/lipgloss/v2" "github.com/anotherhadi/spilltea/internal/icons" "github.com/anotherhadi/spilltea/internal/style" + "github.com/anotherhadi/spilltea/internal/util" ) func (m Model) View() tea.View { @@ -104,7 +105,7 @@ func (m *Model) renderStatusBar() string { func (m *Model) renderList() string { if len(m.queue) == 0 { - return lipgloss.Place(m.listViewport.Width(), m.listViewport.Height(), lipgloss.Center, lipgloss.Center, style.S.Faint.Render(" (。◕‿‿◕。)\nwaiting for a request")) + return lipgloss.Place(m.listViewport.Width(), m.listViewport.Height(), lipgloss.Center, lipgloss.Center, style.S.Faint.Render(util.CenterLines("(。◕‿‿◕。)", "waiting for a request"))) } s := style.S @@ -160,7 +161,7 @@ func (m *Model) renderList() string { func (m *Model) renderResponseList() string { if len(m.responseQueue) == 0 { - return lipgloss.Place(m.responseViewport.Width(), m.responseViewport.Height(), lipgloss.Center, lipgloss.Center, style.S.Faint.Render(" (҂◡_◡)\nno response yet")) + return lipgloss.Place(m.responseViewport.Width(), m.responseViewport.Height(), lipgloss.Center, lipgloss.Center, style.S.Faint.Render(util.CenterLines("(҂◡_◡)", "no response yet"))) } s := style.S diff --git a/internal/ui/plugins/view.go b/internal/ui/plugins/view.go index b8e92df..4abba6d 100644 --- a/internal/ui/plugins/view.go +++ b/internal/ui/plugins/view.go @@ -11,11 +11,12 @@ import ( "github.com/anotherhadi/spilltea/internal/icons" "github.com/anotherhadi/spilltea/internal/keys" "github.com/anotherhadi/spilltea/internal/style" + "github.com/anotherhadi/spilltea/internal/util" ) func (m Model) View() tea.View { if m.width == 0 || m.manager == nil { - return tea.NewView(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, style.S.Faint.Render(" (._.)~*.'\n no plugins loaded"))) + return tea.NewView(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, style.S.Faint.Render(util.CenterLines("(._.)~*.'", "no plugins loaded")))) } listH, detailH := style.SplitH(m.height, m.renderStatusBar(), 0.4) @@ -131,9 +132,9 @@ func (m *Model) renderStatusBar() string { func (m *Model) renderList() string { s := style.S if len(m.filtered) == 0 { - msg := " (ง •̀_•́)ง\nno plugins" + msg := util.CenterLines("(ง •̀_•́)ง", "no plugins", "", "spilltea --add-default-plugins") if m.filter != "" { - msg = " = _ =\nno results" + msg = util.CenterLines("= _ =", "no results") } return lipgloss.Place( m.listViewport.Width(), m.listViewport.Height(), diff --git a/internal/ui/replay/update.go b/internal/ui/replay/update.go index 0a022ce..36ea6b2 100644 --- a/internal/ui/replay/update.go +++ b/internal/ui/replay/update.go @@ -265,11 +265,11 @@ func (m *Model) refreshBody() { m.requestViewport.SetXOffset(0) if e.Sending { - m.responseViewport.SetContent(lipgloss.Place(m.responseViewport.Width(), m.responseViewport.Height(), lipgloss.Center, lipgloss.Center, style.S.Faint.Render(" (ノ◕ヮ◕)ノ*:・゚\n sending..."))) + m.responseViewport.SetContent(lipgloss.Place(m.responseViewport.Width(), m.responseViewport.Height(), lipgloss.Center, lipgloss.Center, style.S.Faint.Render(util.CenterLines("(ノ◕ヮ◕)ノ*:・゚", "sending...")))) } else if e.ResponseRaw != "" { m.responseViewport.SetContent(style.HighlightHTTP(e.ResponseRaw)) } else { - m.responseViewport.SetContent(lipgloss.Place(m.responseViewport.Width(), m.responseViewport.Height(), lipgloss.Center, lipgloss.Center, style.S.Faint.Render(" ( •_•)>⌐■\npress send to fire"))) + m.responseViewport.SetContent(lipgloss.Place(m.responseViewport.Width(), m.responseViewport.Height(), lipgloss.Center, lipgloss.Center, style.S.Faint.Render(util.CenterLines("( •_•)>⌐■", "press send to fire")))) } m.responseViewport.SetYOffset(0) m.responseViewport.SetXOffset(0) diff --git a/internal/ui/replay/view.go b/internal/ui/replay/view.go index 06ec4c2..8dddab7 100644 --- a/internal/ui/replay/view.go +++ b/internal/ui/replay/view.go @@ -8,6 +8,7 @@ import ( "charm.land/lipgloss/v2" "github.com/anotherhadi/spilltea/internal/icons" "github.com/anotherhadi/spilltea/internal/style" + "github.com/anotherhadi/spilltea/internal/util" ) func (m Model) View() tea.View { @@ -75,7 +76,7 @@ func (m *Model) renderList() string { return lipgloss.Place( m.listViewport.Width(), m.listViewport.Height(), lipgloss.Center, lipgloss.Center, - style.S.Faint.Render(" (╥﹏╥)\nsend a request from History or Intercept"), + style.S.Faint.Render(util.CenterLines("(╥﹏╥)", "send a request from History or Intercept")), ) } diff --git a/internal/util/util.go b/internal/util/util.go index 30f1c09..6c5f6d9 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -1,6 +1,10 @@ package util -import "strings" +import ( + "strings" + + "charm.land/lipgloss/v2" +) func Truncate(s string, max int) string { if len(s) <= max { @@ -9,6 +13,21 @@ func Truncate(s string, max int) string { return s[:max-1] + "…" } +// CenterLines centers each line horizontally relative to the longest one. +func CenterLines(lines ...string) string { + maxWidth := 0 + for _, l := range lines { + if w := lipgloss.Width(l); w > maxWidth { + maxWidth = w + } + } + centered := make([]string, len(lines)) + for i, l := range lines { + centered[i] = lipgloss.PlaceHorizontal(maxWidth, lipgloss.Center, l) + } + return strings.Join(centered, "\n") +} + // InferScheme returns "http" for port 80, "https" otherwise. func InferScheme(host string) string { if strings.HasSuffix(host, ":80") {