chore(merge): branch 'master' into v2-tidy

This commit is contained in:
Christian Rocha
2024-10-24 13:11:39 -04:00
11 changed files with 43 additions and 41 deletions
+1 -1
View File
@@ -385,7 +385,7 @@ func (m Model) View() string {
cursor = m.Styles.DisabledCursor.Render(m.DisabledCursor)
}
if m.selected == i {
if m.selected == i { //nolint:nestif
selected := ""
if m.ShowPermissions {
selected += " " + info.Mode().String()
+6 -4
View File
@@ -35,14 +35,14 @@ type DefaultItemStyles struct {
// if you like.
func BaseItemStyles() (s DefaultItemStyles) {
s.NormalTitle = lipgloss.NewStyle().
Padding(0, 0, 0, 2)
Padding(0, 0, 0, 2) //nolint:mnd
s.NormalDesc = s.NormalTitle
s.SelectedTitle = lipgloss.NewStyle().
Border(lipgloss.NormalBorder(), false, false, false, true).
Padding(0, 0, 0, 1)
s.SelectedDesc = s.SelectedTitle
s.DimmedTitle = lipgloss.NewStyle().
Padding(0, 0, 0, 2)
Padding(0, 0, 0, 2) //nolint:mnd
s.DimmedDesc = s.DimmedTitle
s.FilterMatch = lipgloss.NewStyle().
Underline(true)
@@ -114,11 +114,13 @@ type DefaultDelegate struct {
// NewDefaultDelegate creates a new delegate with default styles.
func NewDefaultDelegate() DefaultDelegate {
const defaultHeight = 2
const defaultSpacing = 1
return DefaultDelegate{
ShowDescription: true,
Styles: NewDefaultItemStyles(),
height: 2,
spacing: 1,
height: defaultHeight,
spacing: defaultSpacing,
}
}
+6 -6
View File
@@ -268,7 +268,7 @@ func (m *Model) SetShowTitle(v bool) {
// SetFilterText explicitly sets the filter text without relying on user input.
// It also sets the filterState to a sane default of FilterApplied, but this
// can be changed with SetFilterState
// can be changed with SetFilterState.
func (m *Model) SetFilterText(filter string) {
m.filterState = Filtering
m.FilterInput.SetValue(filter)
@@ -284,7 +284,7 @@ func (m *Model) SetFilterText(filter string) {
m.updateKeybindings()
}
// Helper method for setting the filtering state manually
// Helper method for setting the filtering state manually.
func (m *Model) SetFilterState(state FilterState) {
m.Paginator.Page = 0
m.cursor = 0
@@ -717,7 +717,7 @@ func (m Model) itemsAsFilterItems() filteredItems {
// Set keybindings according to the filter state.
func (m *Model) updateKeybindings() {
switch m.filterState {
switch m.filterState { //nolint:exhaustive
case Filtering:
m.KeyMap.CursorUp.SetEnabled(false)
m.KeyMap.CursorDown.SetEnabled(false)
@@ -1148,7 +1148,7 @@ func (m Model) statusView() string {
itemsDisplay := fmt.Sprintf("%d %s", visibleItems, itemName)
if m.filterState == Filtering {
if m.filterState == Filtering { //nolint:nestif
// Filter results
if visibleItems == 0 {
status = m.Styles.StatusEmpty.Render("Nothing matched")
@@ -1164,7 +1164,7 @@ func (m Model) statusView() string {
if filtered {
f := strings.TrimSpace(m.FilterInput.Value())
f = ansi.Truncate(f, 10, "…")
f = ansi.Truncate(f, 10, "…") //nolint:mnd
status += fmt.Sprintf("“%s” ", f)
}
@@ -1181,7 +1181,7 @@ func (m Model) statusView() string {
}
func (m Model) paginationView() string {
if m.Paginator.TotalPages < 2 { //nolint:gomnd
if m.Paginator.TotalPages < 2 { //nolint:mnd
return ""
}
+1 -3
View File
@@ -64,7 +64,7 @@ func BaseStyles() Styles {
s.PaginationStyle = lipgloss.NewStyle().
PaddingLeft(2) //nolint:gomnd
s.HelpStyle = lipgloss.NewStyle().
Padding(1, 0, 0, 2)
Padding(1, 0, 0, 2) //nolint:mnd
s.ActivePaginationDot = lipgloss.NewStyle().
SetString(bullet)
s.InactivePaginationDot = lipgloss.NewStyle().
@@ -114,8 +114,6 @@ func newStyles(isDark bool) (s Styles) {
Foreground(lightDark("#909090", "#626262"))
s.ArabicPagination = s.ArabicPagination.
Foreground(subduedColor)
s.HelpStyle = s.HelpStyle.
Padding(1, 0, 0, 2)
s.ActivePaginationDot = s.ActivePaginationDot.
Foreground(lightDark("#847A85", "#979797")).
SetString(bullet)
+1 -1
View File
@@ -173,7 +173,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
// View renders the pagination to a string.
func (m Model) View() string {
switch m.Type {
switch m.Type { //nolint:exhaustive
case Dots:
return m.dotsView()
default:
+1 -1
View File
@@ -340,7 +340,7 @@ func (m Model) percentageView(percent float64) string {
return ""
}
percent = math.Max(0, math.Min(1, percent))
percentage := fmt.Sprintf(m.PercentFormat, percent*100) //nolint:gomnd
percentage := fmt.Sprintf(m.PercentFormat, percent*100) //nolint:mnd
percentage = m.PercentageStyle.Inline(true).Render(percentage)
return percentage
}
+12 -12
View File
@@ -26,39 +26,39 @@ type Spinner struct {
var (
Line = Spinner{
Frames: []string{"|", "/", "-", "\\"},
FPS: time.Second / 10, //nolint:gomnd
FPS: time.Second / 10, //nolint:mnd
}
Dot = Spinner{
Frames: []string{"⣾ ", "⣽ ", "⣻ ", "⢿ ", "⡿ ", "⣟ ", "⣯ ", "⣷ "},
FPS: time.Second / 10, //nolint:gomnd
FPS: time.Second / 10, //nolint:mnd
}
MiniDot = Spinner{
Frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
FPS: time.Second / 12, //nolint:gomnd
FPS: time.Second / 12, //nolint:mnd
}
Jump = Spinner{
Frames: []string{"⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"},
FPS: time.Second / 10, //nolint:gomnd
FPS: time.Second / 10, //nolint:mnd
}
Pulse = Spinner{
Frames: []string{"█", "▓", "▒", "░"},
FPS: time.Second / 8, //nolint:gomnd
FPS: time.Second / 8, //nolint:mnd
}
Points = Spinner{
Frames: []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●"},
FPS: time.Second / 7, //nolint:gomnd
FPS: time.Second / 7, //nolint:mnd
}
Globe = Spinner{
Frames: []string{"🌍", "🌎", "🌏"},
FPS: time.Second / 4, //nolint:gomnd
FPS: time.Second / 4, //nolint:mnd
}
Moon = Spinner{
Frames: []string{"🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"},
FPS: time.Second / 8, //nolint:gomnd
FPS: time.Second / 8, //nolint:mnd
}
Monkey = Spinner{
Frames: []string{"🙈", "🙉", "🙊"},
FPS: time.Second / 3, //nolint:gomnd
FPS: time.Second / 3, //nolint:mnd
}
Meter = Spinner{
Frames: []string{
@@ -70,15 +70,15 @@ var (
"▰▱▱",
"▱▱▱",
},
FPS: time.Second / 7, //nolint:gomnd
FPS: time.Second / 7, //nolint:mnd
}
Hamburger = Spinner{
Frames: []string{"☱", "☲", "☴", "☲"},
FPS: time.Second / 3, //nolint:gomnd
FPS: time.Second / 3, //nolint:mnd
}
Ellipsis = Spinner{
Frames: []string{"", ".", "..", "..."},
FPS: time.Second / 3, //nolint:gomnd
FPS: time.Second / 3, //nolint:mnd
}
)
+3 -3
View File
@@ -132,7 +132,7 @@ type Option func(*Model)
func New(opts ...Option) Model {
m := Model{
cursor: 0,
viewport: viewport.New(0, 20),
viewport: viewport.New(0, 20), //nolint:mnd
KeyMap: DefaultKeyMap(),
Help: help.New(),
@@ -215,9 +215,9 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
case key.Matches(msg, m.KeyMap.PageDown):
m.MoveDown(m.viewport.Height)
case key.Matches(msg, m.KeyMap.HalfPageUp):
m.MoveUp(m.viewport.Height / 2)
m.MoveUp(m.viewport.Height / 2) //nolint:mnd
case key.Matches(msg, m.KeyMap.HalfPageDown):
m.MoveDown(m.viewport.Height / 2)
m.MoveDown(m.viewport.Height / 2) //nolint:mnd
case key.Matches(msg, m.KeyMap.GotoTop):
m.GotoTop()
case key.Matches(msg, m.KeyMap.GotoBottom):
+7 -5
View File
@@ -501,7 +501,8 @@ func (m *Model) CursorDown() {
// Move the cursor to the start of the next line so that we can get
// the line information. We need to add 2 columns to account for the
// trailing space wrapping.
m.col = min(li.StartColumn+li.Width+2, len(m.value[m.row])-1)
const trailingSpace = 2
m.col = min(li.StartColumn+li.Width+trailingSpace, len(m.value[m.row])-1)
}
nli := m.LineInfo()
@@ -535,7 +536,8 @@ func (m *Model) CursorUp() {
// This can be done by moving the cursor to the start of the line and
// then subtracting 2 to account for the trailing space we keep on
// soft-wrapped lines.
m.col = li.StartColumn - 2
const trailingSpace = 2
m.col = li.StartColumn - trailingSpace
}
nli := m.LineInfo()
@@ -1130,7 +1132,7 @@ func (m Model) View() string {
displayLine++
var ln string
if m.ShowLineNumbers {
if m.ShowLineNumbers { //nolint:nestif
if wl == 0 {
if m.row == l {
ln = style.Render(m.style.computedCursorLineNumber().Render(m.formatLineNumber(l + 1)))
@@ -1209,7 +1211,7 @@ func (m Model) View() string {
}
// formatLineNumber formats the line number for display dynamically based on
// the maximum number of lines
// the maximum number of lines.
func (m Model) formatLineNumber(x any) string {
// XXX: ultimately we should use a max buffer height, which has yet to be
// implemented.
@@ -1418,7 +1420,7 @@ func wrap(runes []rune, width int) [][]rune {
word = append(word, r)
}
if spaces > 0 {
if spaces > 0 { //nolint:nestif
if uniseg.StringWidth(string(lines[row]))+uniseg.StringWidth(string(word))+spaces > width {
row++
lines = append(lines, []rune{})
+2 -2
View File
@@ -596,7 +596,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
// Let's remember where the position of the cursor currently is so that if
// the cursor position changes, we can reset the blink.
oldPos := m.pos //nolint
oldPos := m.pos
switch msg := msg.(type) {
case tea.KeyPressMsg:
@@ -694,7 +694,7 @@ func (m Model) View() string {
pos := max(0, m.pos-m.offset)
v := styleText(m.echoTransform(string(value[:pos])))
if pos < len(value) {
if pos < len(value) { //nolint:nestif
char := m.echoTransform(string(value[pos]))
m.Cursor.SetChar(char)
v += m.Cursor.View() // cursor and text under it
+3 -3
View File
@@ -144,7 +144,7 @@ func (m *Model) HalfViewDown() {
return
}
m.LineDown(m.Height / 2)
m.LineDown(m.Height / 2) //nolint:mnd
}
// HalfViewUp moves the view up by half the height of the viewport.
@@ -153,7 +153,7 @@ func (m *Model) HalfViewUp() {
return
}
m.LineUp(m.Height / 2)
m.LineUp(m.Height / 2) //nolint:mnd
}
// LineDown moves the view down by the given number of lines.
@@ -246,7 +246,7 @@ func (m Model) updateAsModel(msg tea.Msg) Model {
break
}
switch msg.Button {
switch msg.Button { //nolint:exhaustive
case tea.MouseWheelDown:
m.LineDown(m.MouseWheelDelta)