Skip to content
Open
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
47 changes: 44 additions & 3 deletions tui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,31 @@ func (m *Model) handleSelectorKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}

func (m *Model) handleViewportKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "q", "esc":
key := msg.String()

if m.searching {
return m.handleSearchInputMode(msg, m.updateViewportSearchMatches)
}
if m.handleSearchNavigation(key) {
return m, nil
}

switch key {
case "q":
if m.searchText != "" && len(m.searchMatches) > 0 {
m.clearSearch()
return m, nil
}
m.clearSearch()
m.viewMode = viewTable
m.viewingPatchID = 0
m.viewingCoverID = 0
m.viewComments = nil
m.viewCommentIdx = -1
m.viewportLines = nil
m.viewExpanded = false
case "esc":
m.clearSearch()
m.viewMode = viewTable
m.viewingPatchID = 0
m.viewingCoverID = 0
Expand Down Expand Up @@ -983,8 +1006,25 @@ func (m *Model) compareMinIdx() int {
func (m *Model) handleCompareKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
key := msg.String()

if m.searching {
return m.handleSearchInputMode(msg, m.updateCompareSearchMatches)
}
if m.handleSearchNavigation(key) {
return m, nil
}

switch key {
case "q", "esc":
case "q":
if m.searchText != "" && len(m.searchMatches) > 0 {
m.clearSearch()
return m, nil
}
m.clearSearch()
m.viewMode = viewTable
m.compareCount = 0
return m, nil
case "esc":
m.clearSearch()
m.viewMode = viewTable
m.compareCount = 0
return m, nil
Expand Down Expand Up @@ -1082,3 +1122,4 @@ func (m *Model) compareScrollToEnd() {
m.viewportOffset = 0
}
}

14 changes: 14 additions & 0 deletions tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package tui
import (
"fmt"
"log"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -150,6 +151,12 @@ type compareSide struct {
ver string // "v1", "v2", etc.
}

type searchMatch struct {
lineIdx int
start int
end int
}

func highlightAnimTickCmd() tea.Cmd {
return tea.Tick(
time.Duration(highlightAnimInterval)*time.Millisecond,
Expand Down Expand Up @@ -225,6 +232,13 @@ type Model struct {
viewportLoading bool
viewportOffset int
viewExpanded bool
searching bool
searchText string
searchRegex *regexp.Regexp
searchMatches []searchMatch
searchIdx int
searchHistory []string
searchHistoryIdx int // -1 = typing new query, 0+ = browsing history
listPrefix string
delegateNames map[string]string

Expand Down
141 changes: 80 additions & 61 deletions tui/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func (m *Model) renderPatchView() string {
end = total
}

// Assemble exactly `visible` lines separated by newlines.
lines := make([]string, visible)
for i := 0; i < end-start; i++ {
lines[i] = m.viewportLines[start+i]
lineIdx := start + i
lines[i] = m.highlightLineIfMatched(m.viewportLines[lineIdx], lineIdx)
}
body := strings.Join(lines, "\n")

Expand All @@ -85,47 +85,55 @@ func (m *Model) renderPatchView() string {
bright, desc, sep := m.helpStyles()

var status string
expandKey := func(hb *strings.Builder) {
hb.WriteString(helpSepStr(sep))
if m.viewExpanded {
hb.WriteString(helpKey(bright, desc, "e", "collapse"))
} else {
hb.WriteString(helpKey(bright, desc, "e", "expand"))
}
}
if len(m.viewComments) > 0 {
var hb strings.Builder
hb.WriteString(sep.Render(" "))
hb.WriteString(bright.Render("←/→"))
expandKey(&hb)
hb.WriteString(helpSepStr(sep))
hb.WriteString(bright.Render("↑/↓") +
sep.Render(" ") + bright.Render("pgup/dn"))
hb.WriteString(helpSepStr(sep))
hb.WriteString(bright.Render("esc"))
if m.logConsole {

if m.searching {
status = m.renderSearchInputHelp(bright, desc, sep)
} else {
expandKey := func(hb *strings.Builder) {
hb.WriteString(helpSepStr(sep))
hb.WriteString(helpKey(bright, desc, "tab", "log"))
if m.viewExpanded {
hb.WriteString(helpKey(bright, desc, "e", "collapse"))
} else {
hb.WriteString(helpKey(bright, desc, "e", "expand"))
}
}
hb.WriteString(desc.Render(fmt.Sprintf(" %d%%", pct)))
helpText := hb.String()
barWidth := m.width - lipgloss.Width(helpText)
commentBar := m.renderCommentBar(barWidth)
status = commentBar + helpText
} else {
var hb strings.Builder
expandKey(&hb)
hb.WriteString(helpSepStr(sep))
hb.WriteString(bright.Render("↑/↓") +
sep.Render(" ") + bright.Render("pgup/dn"))
hb.WriteString(helpSepStr(sep))
hb.WriteString(helpKey(bright, desc, "esc", "back"))
if m.logConsole {

if len(m.viewComments) > 0 {
var hb strings.Builder
hb.WriteString(sep.Render(" "))
hb.WriteString(bright.Render("←/→"))
expandKey(&hb)
hb.WriteString(m.renderSearchKeyHelp(bright, desc, sep))
hb.WriteString(helpSepStr(sep))
hb.WriteString(helpKey(bright, desc, "tab", "log"))
hb.WriteString(bright.Render("↑/↓") +
sep.Render(" ") + bright.Render("pgup/dn"))
hb.WriteString(helpSepStr(sep))
hb.WriteString(bright.Render("esc"))
if m.logConsole {
hb.WriteString(helpSepStr(sep))
hb.WriteString(helpKey(bright, desc, "tab", "log"))
}
hb.WriteString(desc.Render(fmt.Sprintf(" %d%%", pct)))
helpText := hb.String()
barWidth := m.width - lipgloss.Width(helpText)
commentBar := m.renderCommentBar(barWidth)
status = commentBar + helpText
} else {
var hb strings.Builder
expandKey(&hb)
hb.WriteString(m.renderSearchKeyHelp(bright, desc, sep))
hb.WriteString(helpSepStr(sep))
hb.WriteString(bright.Render("↑/↓") +
sep.Render(" ") + bright.Render("pgup/dn"))
hb.WriteString(helpSepStr(sep))
hb.WriteString(helpKey(bright, desc, "esc", "back"))
if m.logConsole {
hb.WriteString(helpSepStr(sep))
hb.WriteString(helpKey(bright, desc, "tab", "log"))
}
hb.WriteString(desc.Render(fmt.Sprintf(" %d%%", pct)))
status = hb.String()
}
hb.WriteString(desc.Render(fmt.Sprintf(" %d%%", pct)))
status = hb.String()
}

var statusLine string
Expand Down Expand Up @@ -172,6 +180,10 @@ func (m *Model) renderCompareView() string {
compareDiffKind(m.compare[0].kinds, idx))
right = comparePadLine(right, rightWidth,
compareDiffKind(m.compare[1].kinds, idx))

left = m.highlightLineIfMatched(left, idx)
right = m.highlightLineIfMatched(right, idx)

lines[i] = left + sep + right
}
body := strings.Join(lines, "\n")
Expand All @@ -183,29 +195,36 @@ func (m *Model) renderCompareView() string {
}

bright, desc, sepS := m.helpStyles()
var hb strings.Builder
labelL := comparePositionLabel(
m.compare[0].idx, len(m.compare[0].patches), m.compare[0].ver)
labelR := comparePositionLabel(
m.compare[1].idx, len(m.compare[1].patches), m.compare[1].ver)
hb.WriteString(desc.Render(labelL + " vs " + labelR))
hb.WriteString(helpSepStr(sepS))
hb.WriteString(bright.Render("←/→"))
hb.WriteString(helpSepStr(sepS))
hb.WriteString(helpKey(bright, desc, "1/2+←/→", "single"))
hb.WriteString(helpSepStr(sepS))
if m.viewExpanded {
hb.WriteString(helpKey(bright, desc, "e", "collapse"))

var helpText string
if m.searching {
helpText = m.renderSearchInputHelp(bright, desc, sepS)
} else {
hb.WriteString(helpKey(bright, desc, "e", "expand"))
}
hb.WriteString(helpSepStr(sepS))
hb.WriteString(bright.Render("↑/↓") +
sepS.Render(" ") + bright.Render("pgup/dn"))
hb.WriteString(helpSepStr(sepS))
hb.WriteString(helpKey(bright, desc, "esc", "back"))
hb.WriteString(desc.Render(fmt.Sprintf(" %d%%", pct)))
helpText := hb.String()
var hb strings.Builder
labelL := comparePositionLabel(
m.compare[0].idx, len(m.compare[0].patches), m.compare[0].ver)
labelR := comparePositionLabel(
m.compare[1].idx, len(m.compare[1].patches), m.compare[1].ver)
hb.WriteString(desc.Render(labelL + " vs " + labelR))
hb.WriteString(helpSepStr(sepS))
hb.WriteString(bright.Render("←/→"))
hb.WriteString(helpSepStr(sepS))
hb.WriteString(helpKey(bright, desc, "1/2+←/→", "single"))
hb.WriteString(helpSepStr(sepS))
if m.viewExpanded {
hb.WriteString(helpKey(bright, desc, "e", "collapse"))
} else {
hb.WriteString(helpKey(bright, desc, "e", "expand"))
}
hb.WriteString(m.renderSearchKeyHelp(bright, desc, sepS))
hb.WriteString(helpSepStr(sepS))
hb.WriteString(bright.Render("↑/↓") +
sepS.Render(" ") + bright.Render("pgup/dn"))
hb.WriteString(helpSepStr(sepS))
hb.WriteString(helpKey(bright, desc, "esc", "back"))
hb.WriteString(desc.Render(fmt.Sprintf(" %d%%", pct)))
helpText = hb.String()
}

var statusLine string
msg, spinning := m.Status.Active()
Expand Down
Loading