mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-07-06 20:42:33 +02:00
Migrate components to ilovetui
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -1,71 +1,10 @@
|
||||
package style
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"charm.land/bubbles/v2/paginator"
|
||||
"charm.land/bubbles/v2/textarea"
|
||||
"charm.land/bubbles/v2/viewport"
|
||||
"charm.land/lipgloss/v2"
|
||||
ilovetui "github.com/anotherhadi/ilovetui"
|
||||
)
|
||||
|
||||
func NewViewport() viewport.Model {
|
||||
vp := viewport.New()
|
||||
vp.MouseWheelEnabled = false
|
||||
return vp
|
||||
}
|
||||
|
||||
func ViewportView(vp *viewport.Model) string {
|
||||
v := vp.View()
|
||||
if vp.AtBottom() {
|
||||
return v
|
||||
}
|
||||
lines := strings.Split(v, "\n")
|
||||
if len(lines) == 0 {
|
||||
return v
|
||||
}
|
||||
arrow := lipgloss.NewStyle().Foreground(ilovetui.S.Subtle).Render("↓")
|
||||
arrowW := lipgloss.Width(arrow)
|
||||
inner := vp.Width() - 2*arrowW
|
||||
if inner < 0 {
|
||||
inner = 0
|
||||
}
|
||||
lines[len(lines)-1] = arrow + strings.Repeat(" ", inner) + arrow
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
func NewPaginator() paginator.Model {
|
||||
p := paginator.New()
|
||||
p.Type = paginator.Dots
|
||||
p.ActiveDot = S.PagerDotActive
|
||||
p.InactiveDot = S.PagerDotInactive
|
||||
return p
|
||||
}
|
||||
|
||||
func NewTextarea(showLineNumbers bool) textarea.Model {
|
||||
ta := textarea.New()
|
||||
ta.Prompt = ""
|
||||
ta.ShowLineNumbers = showLineNumbers
|
||||
ta.CharLimit = 0
|
||||
ta.EndOfBufferCharacter = '~'
|
||||
ts := ta.Styles()
|
||||
ts.Focused.Base = lipgloss.NewStyle()
|
||||
ts.Blurred.Base = lipgloss.NewStyle()
|
||||
ts.Focused.Text = lipgloss.NewStyle().Foreground(ilovetui.S.Text)
|
||||
ts.Focused.CursorLine = lipgloss.NewStyle().Background(ilovetui.S.Selection).Foreground(ilovetui.S.Text)
|
||||
ts.Focused.CursorLineNumber = lipgloss.NewStyle().Background(ilovetui.S.Selection).Foreground(ilovetui.S.Primary).Bold(true)
|
||||
ts.Focused.LineNumber = lipgloss.NewStyle().Foreground(ilovetui.S.Subtle)
|
||||
ts.Focused.Placeholder = lipgloss.NewStyle().Foreground(ilovetui.S.Subtle)
|
||||
ts.Focused.EndOfBuffer = lipgloss.NewStyle().Foreground(ilovetui.S.SubtleBg)
|
||||
ts.Blurred.Text = lipgloss.NewStyle().Foreground(ilovetui.S.Muted)
|
||||
ts.Blurred.LineNumber = lipgloss.NewStyle().Foreground(ilovetui.S.SubtleBg)
|
||||
ts.Blurred.Placeholder = lipgloss.NewStyle().Foreground(ilovetui.S.Subtle)
|
||||
ts.Blurred.EndOfBuffer = lipgloss.NewStyle().Foreground(ilovetui.S.SubtleBg)
|
||||
ta.SetStyles(ts)
|
||||
return ta
|
||||
}
|
||||
|
||||
func SeverityStyle(sev string) lipgloss.Style {
|
||||
base := lipgloss.NewStyle().Bold(true)
|
||||
switch sev {
|
||||
@@ -95,13 +34,3 @@ func StatusStyle(code, width int) lipgloss.Style {
|
||||
return base.Foreground(ilovetui.S.Success)
|
||||
}
|
||||
}
|
||||
|
||||
// SplitH splits totalHeight into top and bottom sections, accounting for the
|
||||
// status bar height.
|
||||
func SplitH(totalHeight int, statusBar string, ratio float64) (top, bottom int) {
|
||||
statusH := strings.Count(statusBar, "\n") + 1
|
||||
available := totalHeight - statusH
|
||||
top = int(float64(available) * ratio)
|
||||
bottom = available - top
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package style
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/help"
|
||||
"charm.land/lipgloss/v2"
|
||||
ilovetui "github.com/anotherhadi/ilovetui"
|
||||
)
|
||||
@@ -9,9 +8,6 @@ import (
|
||||
type Styles struct {
|
||||
PanelEditing lipgloss.Style
|
||||
|
||||
PagerDotActive string
|
||||
PagerDotInactive string
|
||||
|
||||
methodGet lipgloss.Style
|
||||
methodPost lipgloss.Style
|
||||
methodPutPatch lipgloss.Style
|
||||
@@ -28,9 +24,6 @@ func Init() {
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(ilovetui.S.Base0E),
|
||||
|
||||
PagerDotActive: lipgloss.NewStyle().Foreground(ilovetui.S.Primary).SetString("•").String(),
|
||||
PagerDotInactive: lipgloss.NewStyle().Foreground(ilovetui.S.Subtle).SetString("•").String(),
|
||||
|
||||
methodGet: methodBase.Foreground(ilovetui.S.Success),
|
||||
methodPost: methodBase.Foreground(ilovetui.S.Warning),
|
||||
methodPutPatch: methodBase.Foreground(ilovetui.S.Primary),
|
||||
@@ -39,18 +32,6 @@ func Init() {
|
||||
}
|
||||
}
|
||||
|
||||
func NewHelp() help.Model {
|
||||
h := help.New()
|
||||
h.Styles.ShortKey = lipgloss.NewStyle().Foreground(ilovetui.S.Primary)
|
||||
h.Styles.ShortDesc = lipgloss.NewStyle().Foreground(ilovetui.S.Muted)
|
||||
h.Styles.ShortSeparator = lipgloss.NewStyle().Foreground(ilovetui.S.Subtle)
|
||||
h.Styles.FullKey = lipgloss.NewStyle().Foreground(ilovetui.S.Primary)
|
||||
h.Styles.FullDesc = lipgloss.NewStyle().Foreground(ilovetui.S.Muted)
|
||||
h.Styles.FullSeparator = lipgloss.NewStyle().Foreground(ilovetui.S.Subtle)
|
||||
h.Styles.Ellipsis = lipgloss.NewStyle().Foreground(ilovetui.S.Subtle)
|
||||
return h
|
||||
}
|
||||
|
||||
func (s *Styles) Method(method string) lipgloss.Style {
|
||||
switch method {
|
||||
case "GET":
|
||||
|
||||
Reference in New Issue
Block a user