mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 17:52:33 +02:00
Add scroll icon on viewports
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -15,6 +15,25 @@ func NewViewport() viewport.Model {
|
||||
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(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
|
||||
|
||||
@@ -18,6 +18,7 @@ func Paint(c color.Color, s string) string {
|
||||
func HighlightHTTP(raw string) string {
|
||||
raw = strings.ReplaceAll(raw, "\r\n", "\n")
|
||||
raw = strings.ReplaceAll(raw, "\r", "\n")
|
||||
raw = strings.ReplaceAll(raw, "\t", " ")
|
||||
idx := strings.Index(raw, "\n\n")
|
||||
if idx == -1 {
|
||||
return highlightHeaders(raw)
|
||||
|
||||
@@ -58,8 +58,8 @@ func (m *Model) renderPanels(panelH int) string {
|
||||
rightBorder = s.PanelFocused
|
||||
}
|
||||
|
||||
left := style.RenderWithTitle(leftBorder, leftTitle, m.leftViewport.View(), leftW, panelH)
|
||||
right := style.RenderWithTitle(rightBorder, rightTitle, m.rightViewport.View(), rightW, panelH)
|
||||
left := style.RenderWithTitle(leftBorder, leftTitle, style.ViewportView(&m.leftViewport), leftW, panelH)
|
||||
right := style.RenderWithTitle(rightBorder, rightTitle, style.ViewportView(&m.rightViewport), rightW, panelH)
|
||||
|
||||
return lipgloss.JoinHorizontal(lipgloss.Top, left, right)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func (m *Model) renderBodyPanel(h int) string {
|
||||
if len(m.findings) > 0 {
|
||||
title = m.findings[m.cursor].Title
|
||||
}
|
||||
return style.RenderWithTitle(s.Panel, title, m.bodyViewport.View(), m.width, h)
|
||||
return style.RenderWithTitle(s.Panel, title, style.ViewportView(&m.bodyViewport), m.width, h)
|
||||
}
|
||||
|
||||
func (m *Model) renderList() string {
|
||||
|
||||
@@ -46,7 +46,7 @@ func (m *Model) renderBodyPanel(h int) string {
|
||||
if m.focusedPanel == panelResponse {
|
||||
title = icons.I.Response + "Response"
|
||||
}
|
||||
return style.RenderWithTitle(s.Panel, title, m.bodyViewport.View(), m.width, h)
|
||||
return style.RenderWithTitle(s.Panel, title, style.ViewportView(&m.bodyViewport), m.width, h)
|
||||
}
|
||||
|
||||
func (m *Model) renderStatusBar() string {
|
||||
|
||||
@@ -87,7 +87,7 @@ func (m *Model) renderBodyPanel(h int) string {
|
||||
if m.editing {
|
||||
body = m.textarea.View()
|
||||
} else {
|
||||
body = m.bodyViewport.View()
|
||||
body = style.ViewportView(&m.bodyViewport)
|
||||
}
|
||||
|
||||
border := s.Panel
|
||||
|
||||
@@ -73,7 +73,7 @@ func (m *Model) renderDetailPanel(h int) string {
|
||||
s.Faint.Render(filepath.Base(info.FilePath)),
|
||||
)
|
||||
|
||||
parts := []string{header, m.detailViewport.View()}
|
||||
parts := []string{header, style.ViewportView(&m.detailViewport)}
|
||||
|
||||
if m.hasConfig() {
|
||||
var configLabel string
|
||||
|
||||
@@ -57,7 +57,7 @@ func (m *Model) renderRequestPanel(w, h int) string {
|
||||
body = m.textarea.View()
|
||||
border = s.PanelFocused
|
||||
} else {
|
||||
body = m.requestViewport.View()
|
||||
body = style.ViewportView(&m.requestViewport)
|
||||
if m.focusedPanel == panelRequest {
|
||||
border = s.PanelFocused
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (m *Model) renderResponsePanel(w, h int) string {
|
||||
if !m.editing && m.focusedPanel == panelResponse {
|
||||
border = s.PanelFocused
|
||||
}
|
||||
return style.RenderWithTitle(border, icons.I.Response+"Response", m.responseViewport.View(), w, h)
|
||||
return style.RenderWithTitle(border, icons.I.Response+"Response", style.ViewportView(&m.responseViewport), w, h)
|
||||
}
|
||||
|
||||
func (m *Model) renderStatusBar() string {
|
||||
|
||||
Reference in New Issue
Block a user