Skip to content
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 @@ -15,6 +15,7 @@ require (
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/google/uuid v1.6.0
github.com/modelcontextprotocol/go-sdk v1.6.1
golang.org/x/text v0.41.0
modernc.org/sqlite v1.56.0
)

Expand Down Expand Up @@ -57,7 +58,6 @@ require (
golang.org/x/oauth2 v0.35.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.40.0 // indirect
modernc.org/libc v1.74.4 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ github.com/yuin/goldmark-emoji v1.0.5 h1:EMVWyCGPlXJfUXBXpuMu+ii3TIaxbVBnEX9uaDC
github.com/yuin/goldmark-emoji v1.0.5/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk=
golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40=
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ=
Expand All @@ -117,10 +117,10 @@ golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs=
golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY=
golang.org/x/tools v0.47.0 h1:7Kn5x/d1svx/PzryTsqeoZN4TZwqeH5pGWjefhLi/1Q=
golang.org/x/tools v0.47.0/go.mod h1:dFHnyTvFWY212G+h7ZY4Vsp/K3U4/7W9TyVaAul8uCA=
golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8=
golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M=
golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE=
golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk=
modernc.org/cc/v4 v4.29.1 h1:MKgdCV3WykTSPqpVrnxdEDS0HEd2FHpKZDzxzU5LyeI=
modernc.org/cc/v4 v4.29.1/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
modernc.org/ccgo/v4 v4.34.6 h1:sBgfIwyN0TQ9C5hwIeuqyeAKyMWnbvj2fvpF4L11uzU=
Expand Down
204 changes: 186 additions & 18 deletions internal/tui/board_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,38 @@

type boardCardClickedMsg struct{ taskID string }
type boardColumnClickedMsg struct{ status board.Status }
type filterTextClickedMsg struct{}
type filterLabelClickedMsg struct{ tag string }
type filterClearClickedMsg struct{}

type boardHitKind uint8

const (
boardHitDefault boardHitKind = iota
boardHitFilterText
boardHitFilterLabel
boardHitFilterClear
)

type boardHit struct {
x0, x1 int
y0, y1 int
status board.Status
taskID string
kind boardHitKind
tag string
}

type renderedColumn struct {
lines []string
hits []boardHit
}

type labelSpan struct {
x0, x1 int
tag string
}

func (s boardViewState) visibleStatuses() []board.Status {
limit := len(boardStatuses)
if !s.showCancelled {
Expand Down Expand Up @@ -191,7 +210,7 @@

// selectedTask is the narrow handoff used by the card-detail overlay.
func (m Model) selectedTask() (board.Task, bool) {
return m.boardView.selectedTask(m.board)
return m.boardView.selectedTask(m.filteredBoard())
}

func taskCount(current board.Board, status board.Status) int {
Expand Down Expand Up @@ -226,22 +245,24 @@
title = "Board"
}
header := fitLine(fmt.Sprintf("kb / %s / %s", title, m.user), width)
filterLine, filterHits := m.renderFilterBar(width)

statuses := m.boardView.visibleStatuses()
if width < wideBoardWidth {
statuses = statuses[m.boardView.column : m.boardView.column+1]
}
bodyHeight := height - 2
bodyHeight := height - 4
columnWidths := splitWidths(width, len(statuses))
columns := make([]renderedColumn, 0, len(statuses))
for i, status := range statuses {
columns = append(columns, m.renderBoardColumn(status, columnWidths[i], bodyHeight))
}
body, hits := joinColumns(columns)
for i := range hits {
hits[i].y0++
hits[i].y1++
hits[i].y0 += 3
hits[i].y1 += 3
}
hits = append(filterHits, hits...)

state := "ready"
if m.loading || (m.watcher != nil && !m.haveVersion) {
Expand All @@ -261,15 +282,90 @@
help := "j/k cards | h/l/tab columns | 1-4 jump | c cancelled:" + cancelled + " | q quit"
if m.settingsNew != nil {
footer := settingsBoardFooter(state, cancelled, width)
return strings.Join([]string{header, body, footer}, "\n"), hits
return strings.Join([]string{header, filterLine, body, footer}, "\n"), hits
}
footer := fitLine(state+" | "+help, width)
return strings.Join([]string{header, body, footer}, "\n"), hits
return strings.Join([]string{header, filterLine, body, footer}, "\n"), hits
}

func (m Model) renderFilterBar(width int) (string, []boardHit) {

Check failure on line 291 in internal/tui/board_view.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 26 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=RandomCodeSpace_kb&issues=AaAQdXRYm5o4Wyi5p5u3&open=AaAQdXRYm5o4Wyi5p5u3&pullRequest=106
width = max(width, 1)
hits := make([]boardHit, 0, 2+len(m.filterLabels()))
lines := [2][]string{}
appendPart := func(row int, part string, kind boardHitKind, tag string) {
x := ansi.StringWidth(strings.Join(lines[row], ""))
if len(lines[row]) > 0 {
lines[row] = append(lines[row], " | ")
x += 3
}
start := x
lines[row] = append(lines[row], part)
x += ansi.StringWidth(part)
if kind != boardHitDefault && start < width {
hits = append(hits, boardHit{x0: start, x1: min(x, width), y0: row + 1, y1: row + 2, kind: kind, tag: tag})
}
}

value := sanitizeTerminal(m.filter.input.Value())
if value == "" {
value = "Filter cards"
}
text := "/ " + value
if m.filter.focus == filterText {
text = "> " + settingsInputDisplay(m.filter.input, false, true, max(min(width-2, 40), 1))
}
labels := m.filterLabels()
focusTag := ""
if m.filter.focus == filterLabels && len(labels) > 0 {
focusTag = labels[min(max(m.filter.labelIndex, 0), len(labels)-1)]
}
appendLabel := func(tag string) {
marker := "+"
if m.filter.hasTag(tag) {
marker = "x"
}
label := "[" + marker + " " + sanitizeTerminal(tag) + "]"
if tag == focusTag {
label = ">" + label + "<"
}
appendPart(0, label, boardHitFilterLabel, tag)
}
if focusTag != "" {
appendLabel(focusTag)
}
appendPart(0, text, boardHitFilterText, "")
if m.filter.active() {
appendPart(1, fmt.Sprintf("%d of %d cards", len(m.filteredBoard().Tasks), len(m.board.Tasks)), boardHitDefault, "")
}
appendLabelOnControls := func(tag string) {
marker := "+"
if m.filter.hasTag(tag) {
marker = "x"
}
appendPart(1, "["+marker+" "+sanitizeTerminal(tag)+"]", boardHitFilterLabel, tag)
}
for _, tag := range labels {
if tag != focusTag && m.filter.hasTag(tag) {
appendLabelOnControls(tag)
}
}
if m.filter.active() {
appendPart(1, "[clear]", boardHitFilterClear, "")
}
for _, tag := range labels {
if tag != focusTag && !m.filter.hasTag(tag) {
appendLabelOnControls(tag)
}
}
return strings.Join([]string{
fitLine(strings.Join(lines[0], ""), width),
fitLine(strings.Join(lines[1], ""), width),
}, "\n"), hits
}

func settingsBoardFooter(state, cancelled string, width int) string {
candidates := [][]string{
{"s settings", "j/k cards", "h/l/tab columns", "1-4 jump", "c cancelled:" + cancelled, "q quit"},

Check failure on line 368 in internal/tui/board_view.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "q quit" 10 times.

See more on https://sonarcloud.io/project/issues?id=RandomCodeSpace_kb&issues=AaAQdXRYm5o4Wyi5p5uy&open=AaAQdXRYm5o4Wyi5p5uy&pullRequest=106

Check failure on line 368 in internal/tui/board_view.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "h/l/tab columns" 3 times.

See more on https://sonarcloud.io/project/issues?id=RandomCodeSpace_kb&issues=AaAQdXRYm5o4Wyi5p5u0&open=AaAQdXRYm5o4Wyi5p5u0&pullRequest=106

Check failure on line 368 in internal/tui/board_view.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "j/k cards" 3 times.

See more on https://sonarcloud.io/project/issues?id=RandomCodeSpace_kb&issues=AaAQdXRYm5o4Wyi5p5uz&open=AaAQdXRYm5o4Wyi5p5uz&pullRequest=106

Check failure on line 368 in internal/tui/board_view.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "s settings" 5 times.

See more on https://sonarcloud.io/project/issues?id=RandomCodeSpace_kb&issues=AaAQdXRYm5o4Wyi5p5u2&open=AaAQdXRYm5o4Wyi5p5u2&pullRequest=106
{"s settings", "j/k cards", "h/l/tab columns", "c cancelled:" + cancelled, "q quit"},
{"s settings", "j/k cards", "h/l/tab columns", "q quit"},
{"s settings", "j/k", "h/l/tab", "q quit"},
Expand Down Expand Up @@ -320,7 +416,7 @@
return renderedColumn{lines: lines, hits: []boardHit{{x1: width, y1: height, status: status}}}
}
inner := width - 2
tasks := tasksInStatus(m.board, status)
tasks := tasksInStatus(m.filteredBoard(), status)
focused := m.boardView.column == statusIndex(status)
heading := fmt.Sprintf("%d %s %d", statusIndex(status)+1, statusLabel(status), len(tasks))
if focused {
Expand All @@ -330,7 +426,7 @@
hits := []boardHit{{x1: width, y1: height, status: status}}

contentHeight := max(height-2, 0)
cardLines, owners := m.renderTaskLines(tasks, status, inner)
cardLines, owners, labelSpans := m.renderTaskLines(tasks, status, inner)
start := visibleCardStart(cardLines, owners, m.boardView.rows[statusIndex(status)], contentHeight)
for row := 0; row < contentHeight; row++ {
source := start + row
Expand All @@ -342,17 +438,27 @@
if source < len(owners) && owners[source] != "" {
hits = append(hits, boardHit{x1: width, y0: row + 1, y1: row + 2, status: status, taskID: owners[source]})
}
if source < len(labelSpans) {
for _, span := range labelSpans[source] {
hits = append(hits, boardHit{
x0: 1 + span.x0, x1: min(1+span.x1, width-1),
y0: row + 1, y1: row + 2, status: status,
kind: boardHitFilterLabel, tag: span.tag,
})
}
}
}
lines = append(lines, "└"+strings.Repeat("─", inner)+"┘")
return renderedColumn{lines: lines, hits: hits}
}

func (m Model) renderTaskLines(tasks []board.Task, status board.Status, width int) ([]string, []string) {
func (m Model) renderTaskLines(tasks []board.Task, status board.Status, width int) ([]string, []string, [][]labelSpan) {

Check failure on line 455 in internal/tui/board_view.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=RandomCodeSpace_kb&issues=AaAQdXRYm5o4Wyi5p5u4&open=AaAQdXRYm5o4Wyi5p5u4&pullRequest=106
if len(tasks) == 0 {
return []string{"(empty)"}, []string{""}
return []string{"(empty)"}, []string{""}, [][]labelSpan{nil}
}
lines := make([]string, 0, len(tasks)*3)
owners := make([]string, 0, len(tasks)*3)
spans := make([][]labelSpan, 0, len(tasks)*3)
selected := m.boardView.rows[statusIndex(status)]
for i, task := range tasks {
marker := " "
Expand All @@ -367,17 +473,27 @@
}
lines = append(lines, prefix+line)
owners = append(owners, task.ID)
spans = append(spans, nil)
}
for _, line := range wrapTokens(cardMeta(task, m.now()), max(width-2, 1)) {
metaLines, metaSpans := wrapMeta(cardMetaEntries(task, m.now()), max(width-2, 1))
for lineIndex, line := range metaLines {
lines = append(lines, " "+line)
owners = append(owners, task.ID)
lineSpans := make([]labelSpan, len(metaSpans[lineIndex]))
for spanIndex, span := range metaSpans[lineIndex] {
span.x0 += 2
span.x1 += 2
lineSpans[spanIndex] = span
}
spans = append(spans, lineSpans)
}
if i+1 < len(tasks) {
lines = append(lines, "")
owners = append(owners, "")
spans = append(spans, nil)
}
}
return lines, owners
return lines, owners, spans
}

func visibleCardStart(lines, owners []string, selected, height int) int {
Expand Down Expand Up @@ -443,6 +559,14 @@
if mouse.X < hit.x0 || mouse.X >= hit.x1 || mouse.Y < hit.y0 || mouse.Y >= hit.y1 {
continue
}
switch hit.kind {
case boardHitFilterText:
return func() tea.Msg { return filterTextClickedMsg{} }
case boardHitFilterLabel:
return func() tea.Msg { return filterLabelClickedMsg{tag: hit.tag} }
case boardHitFilterClear:
return func() tea.Msg { return filterClearClickedMsg{} }
}
if hit.taskID != "" {
return func() tea.Msg { return boardCardClickedMsg{taskID: hit.taskID} }
}
Expand Down Expand Up @@ -493,28 +617,72 @@
return tokens
}

func cardMeta(task board.Task, now time.Time) []string {
tokens := []string{priorityChip(task.Prio)}
type metaEntry struct {
text string
tag string
}

func cardMetaEntries(task board.Task, now time.Time) []metaEntry {
tokens := []metaEntry{{text: priorityChip(task.Prio)}}
if task.Blocked {
tokens = append(tokens, chip("⛔ blocked", lipgloss.Color("#ffb020")))
tokens = append(tokens, metaEntry{text: chip("⛔ blocked", lipgloss.Color("#ffb020"))})

Check failure on line 628 in internal/tui/board_view.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "#ffb020" 3 times.

See more on https://sonarcloud.io/project/issues?id=RandomCodeSpace_kb&issues=AaAQdXRYm5o4Wyi5p5u1&open=AaAQdXRYm5o4Wyi5p5u1&pullRequest=106
}
if task.Due != "" {
label, overdue := dueChip(task.Due, now)
color := lipgloss.Color("#e2f4e0")
if overdue {
color = lipgloss.Color("#ffe0dc")
}
tokens = append(tokens, chip(label, color))
tokens = append(tokens, metaEntry{text: chip(label, color)})
}
if task.Effort != "" {
tokens = append(tokens, "["+task.Effort+"]")
tokens = append(tokens, metaEntry{text: "[" + task.Effort + "]"})
}
for _, tag := range task.Tags {
tokens = append(tokens, labelChip(tag))
tokens = append(tokens, metaEntry{text: labelChip(tag), tag: tag})
}
return tokens
}

func wrapMeta(entries []metaEntry, width int) ([]string, [][]labelSpan) {
if width <= 0 {
return []string{""}, [][]labelSpan{nil}
}
lines := make([]string, 0, 2)
spans := make([][]labelSpan, 0, 2)
line := ""
lineSpans := make([]labelSpan, 0)
flush := func() {
lines = append(lines, line)
spans = append(spans, lineSpans)
line = ""
lineSpans = nil
}
for _, entry := range entries {
if entry.text == "" {
continue
}
separator := ""
if line != "" {
separator = " "
}
if line != "" && ansi.StringWidth(line+separator+entry.text) > width {
flush()
separator = ""
}
start := ansi.StringWidth(line) + ansi.StringWidth(separator)
visible := ansi.Truncate(entry.text, max(width-start, 0), "")
line += separator + visible
if entry.tag != "" && ansi.StringWidth(visible) > 0 {
lineSpans = append(lineSpans, labelSpan{x0: start, x1: start + ansi.StringWidth(visible), tag: entry.tag})
}
}
if line != "" || len(lines) == 0 {
flush()
}
return lines, spans
}

var priorityColors = map[int]color.Color{
1: lipgloss.Color("#ff5a48"),
2: lipgloss.Color("#ffb020"),
Expand Down
Loading