• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

charmbracelet / glow / 14244739488

03 Apr 2025 01:52PM UTC coverage: 3.722% (-0.007%) from 3.729%
14244739488

Pull #735

github

web-flow
chore: fix typo in error

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Pull Request #735: chore: do some basic repo maintenance (editorconfig, linting, etc)

0 of 85 new or added lines in 14 files covered. (0.0%)

1 existing line in 1 file now uncovered.

77 of 2069 relevant lines covered (3.72%)

0.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/ui/stashitem.go
1
package ui
2

3
import (
4
        "fmt"
5
        "strings"
6

7
        "github.com/charmbracelet/lipgloss"
8
        "github.com/charmbracelet/log"
9
        "github.com/muesli/reflow/truncate"
10
        "github.com/sahilm/fuzzy"
11
)
12

13
const (
14
        verticalLine         = "│"
15
        fileListingStashIcon = "• "
16
)
17

18
func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) {
×
19
        var (
×
NEW
20
                truncateTo  = uint(m.common.width - stashViewHorizontalPadding*2) //nolint:gosec
×
21
                gutter      string
×
22
                title       = truncate.StringWithTail(md.Note, truncateTo, ellipsis)
×
23
                date        = md.relativeTime()
×
24
                editedBy    = ""
×
25
                hasEditedBy = false
×
26
                icon        = ""
×
27
                separator   = ""
×
28
        )
×
29

×
30
        isSelected := index == m.cursor()
×
31
        isFiltering := m.filterState == filtering
×
32
        singleFilteredItem := isFiltering && len(m.getVisibleMarkdowns()) == 1
×
33

×
34
        // If there are multiple items being filtered don't highlight a selected
×
35
        // item in the results. If we've filtered down to one item, however,
×
36
        // highlight that first item since pressing return will open it.
×
NEW
37
        if isSelected && !isFiltering || singleFilteredItem { //nolint:nestif
×
38
                // Selected item
×
39
                if m.statusMessage == stashingStatusMessage {
×
40
                        gutter = greenFg(verticalLine)
×
41
                        icon = dimGreenFg(icon)
×
42
                        title = greenFg(title)
×
43
                        date = semiDimGreenFg(date)
×
44
                        editedBy = semiDimGreenFg(editedBy)
×
45
                        separator = semiDimGreenFg(separator)
×
46
                } else {
×
47
                        gutter = dullFuchsiaFg(verticalLine)
×
48
                        if m.currentSection().key == filterSection &&
×
49
                                m.filterState == filterApplied || singleFilteredItem {
×
50
                                s := lipgloss.NewStyle().Foreground(fuchsia)
×
51
                                title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline(true))
×
52
                        } else {
×
53
                                title = fuchsiaFg(title)
×
54
                                icon = fuchsiaFg(icon)
×
55
                        }
×
56
                        date = dimFuchsiaFg(date)
×
57
                        editedBy = dimDullFuchsiaFg(editedBy)
×
58
                        separator = dullFuchsiaFg(separator)
×
59
                }
60
        } else {
×
61
                gutter = " "
×
62
                if m.statusMessage == stashingStatusMessage {
×
63
                        icon = dimGreenFg(icon)
×
64
                        title = greenFg(title)
×
65
                        date = semiDimGreenFg(date)
×
66
                        editedBy = semiDimGreenFg(editedBy)
×
67
                        separator = semiDimGreenFg(separator)
×
68
                } else if isFiltering && m.filterInput.Value() == "" {
×
69
                        icon = dimGreenFg(icon)
×
70
                        title = dimNormalFg(title)
×
71
                        date = dimBrightGrayFg(date)
×
72
                        editedBy = dimBrightGrayFg(editedBy)
×
73
                        separator = dimBrightGrayFg(separator)
×
74
                } else {
×
75
                        icon = greenFg(icon)
×
76

×
77
                        s := lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"})
×
78
                        title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline(true))
×
79
                        date = grayFg(date)
×
80
                        editedBy = midGrayFg(editedBy)
×
81
                        separator = brightGrayFg(separator)
×
82
                }
×
83
        }
84

85
        fmt.Fprintf(b, "%s %s%s%s%s\n", gutter, icon, separator, separator, title)
×
86
        fmt.Fprintf(b, "%s %s", gutter, date)
×
87
        if hasEditedBy {
×
88
                fmt.Fprintf(b, " %s", editedBy)
×
89
        }
×
90
}
91

92
func styleFilteredText(haystack, needles string, defaultStyle, matchedStyle lipgloss.Style) string {
×
93
        b := strings.Builder{}
×
94

×
95
        normalizedHay, err := normalize(haystack)
×
96
        if err != nil {
×
97
                log.Error("error normalizing", "haystack", haystack, "error", err)
×
98
        }
×
99

100
        matches := fuzzy.Find(needles, []string{normalizedHay})
×
101
        if len(matches) == 0 {
×
102
                return defaultStyle.Render(haystack)
×
103
        }
×
104

105
        m := matches[0] // only one match exists
×
106
        for i, rune := range []rune(haystack) {
×
107
                styled := false
×
108
                for _, mi := range m.MatchedIndexes {
×
109
                        if i == mi {
×
110
                                b.WriteString(matchedStyle.Render(string(rune)))
×
111
                                styled = true
×
112
                        }
×
113
                }
114
                if !styled {
×
115
                        b.WriteString(defaultStyle.Render(string(rune)))
×
116
                }
×
117
        }
118

119
        return b.String()
×
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc