mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
fix: lint issues (#730)
This commit is contained in:
+36
-36
@@ -36,8 +36,8 @@ func New() Model {
|
|||||||
FileAllowed: true,
|
FileAllowed: true,
|
||||||
AutoHeight: true,
|
AutoHeight: true,
|
||||||
height: 0,
|
height: 0,
|
||||||
max: 0,
|
maxIdx: 0,
|
||||||
min: 0,
|
minIdx: 0,
|
||||||
selectedStack: newStack(),
|
selectedStack: newStack(),
|
||||||
minStack: newStack(),
|
minStack: newStack(),
|
||||||
maxStack: newStack(),
|
maxStack: newStack(),
|
||||||
@@ -147,8 +147,8 @@ type Model struct {
|
|||||||
selected int
|
selected int
|
||||||
selectedStack stack
|
selectedStack stack
|
||||||
|
|
||||||
min int
|
minIdx int
|
||||||
max int
|
maxIdx int
|
||||||
maxStack stack
|
maxStack stack
|
||||||
minStack stack
|
minStack stack
|
||||||
|
|
||||||
@@ -182,10 +182,10 @@ func newStack() stack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) pushView(selected, min, max int) {
|
func (m *Model) pushView(selected, minIdx, maxIdx int) {
|
||||||
m.selectedStack.Push(selected)
|
m.selectedStack.Push(selected)
|
||||||
m.minStack.Push(min)
|
m.minStack.Push(minIdx)
|
||||||
m.maxStack.Push(max)
|
m.maxStack.Push(maxIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) popView() (int, int, int) {
|
func (m *Model) popView() (int, int, int) {
|
||||||
@@ -245,72 +245,72 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
m.files = msg.entries
|
m.files = msg.entries
|
||||||
m.max = max(m.max, m.Height()-1)
|
m.maxIdx = max(m.maxIdx, m.Height()-1)
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
if m.AutoHeight {
|
if m.AutoHeight {
|
||||||
m.SetHeight(msg.Height - marginBottom)
|
m.SetHeight(msg.Height - marginBottom)
|
||||||
}
|
}
|
||||||
m.max = m.Height() - 1
|
m.maxIdx = m.Height() - 1
|
||||||
case tea.KeyPressMsg:
|
case tea.KeyPressMsg:
|
||||||
switch {
|
switch {
|
||||||
case key.Matches(msg, m.KeyMap.GoToTop):
|
case key.Matches(msg, m.KeyMap.GoToTop):
|
||||||
m.selected = 0
|
m.selected = 0
|
||||||
m.min = 0
|
m.minIdx = 0
|
||||||
m.max = m.Height() - 1
|
m.maxIdx = m.Height() - 1
|
||||||
case key.Matches(msg, m.KeyMap.GoToLast):
|
case key.Matches(msg, m.KeyMap.GoToLast):
|
||||||
m.selected = len(m.files) - 1
|
m.selected = len(m.files) - 1
|
||||||
m.min = len(m.files) - m.Height()
|
m.minIdx = len(m.files) - m.Height()
|
||||||
m.max = len(m.files) - 1
|
m.maxIdx = len(m.files) - 1
|
||||||
case key.Matches(msg, m.KeyMap.Down):
|
case key.Matches(msg, m.KeyMap.Down):
|
||||||
m.selected++
|
m.selected++
|
||||||
if m.selected >= len(m.files) {
|
if m.selected >= len(m.files) {
|
||||||
m.selected = len(m.files) - 1
|
m.selected = len(m.files) - 1
|
||||||
}
|
}
|
||||||
if m.selected > m.max {
|
if m.selected > m.maxIdx {
|
||||||
m.min++
|
m.minIdx++
|
||||||
m.max++
|
m.maxIdx++
|
||||||
}
|
}
|
||||||
case key.Matches(msg, m.KeyMap.Up):
|
case key.Matches(msg, m.KeyMap.Up):
|
||||||
m.selected--
|
m.selected--
|
||||||
if m.selected < 0 {
|
if m.selected < 0 {
|
||||||
m.selected = 0
|
m.selected = 0
|
||||||
}
|
}
|
||||||
if m.selected < m.min {
|
if m.selected < m.minIdx {
|
||||||
m.min--
|
m.minIdx--
|
||||||
m.max--
|
m.maxIdx--
|
||||||
}
|
}
|
||||||
case key.Matches(msg, m.KeyMap.PageDown):
|
case key.Matches(msg, m.KeyMap.PageDown):
|
||||||
m.selected += m.Height()
|
m.selected += m.Height()
|
||||||
if m.selected >= len(m.files) {
|
if m.selected >= len(m.files) {
|
||||||
m.selected = len(m.files) - 1
|
m.selected = len(m.files) - 1
|
||||||
}
|
}
|
||||||
m.min += m.Height()
|
m.minIdx += m.Height()
|
||||||
m.max += m.Height()
|
m.maxIdx += m.Height()
|
||||||
|
|
||||||
if m.max >= len(m.files) {
|
if m.maxIdx >= len(m.files) {
|
||||||
m.max = len(m.files) - 1
|
m.maxIdx = len(m.files) - 1
|
||||||
m.min = m.max - m.Height()
|
m.minIdx = m.maxIdx - m.Height()
|
||||||
}
|
}
|
||||||
case key.Matches(msg, m.KeyMap.PageUp):
|
case key.Matches(msg, m.KeyMap.PageUp):
|
||||||
m.selected -= m.Height()
|
m.selected -= m.Height()
|
||||||
if m.selected < 0 {
|
if m.selected < 0 {
|
||||||
m.selected = 0
|
m.selected = 0
|
||||||
}
|
}
|
||||||
m.min -= m.Height()
|
m.minIdx -= m.Height()
|
||||||
m.max -= m.Height()
|
m.maxIdx -= m.Height()
|
||||||
|
|
||||||
if m.min < 0 {
|
if m.minIdx < 0 {
|
||||||
m.min = 0
|
m.minIdx = 0
|
||||||
m.max = m.min + m.Height()
|
m.maxIdx = m.minIdx + m.Height()
|
||||||
}
|
}
|
||||||
case key.Matches(msg, m.KeyMap.Back):
|
case key.Matches(msg, m.KeyMap.Back):
|
||||||
m.CurrentDirectory = filepath.Dir(m.CurrentDirectory)
|
m.CurrentDirectory = filepath.Dir(m.CurrentDirectory)
|
||||||
if m.selectedStack.Length() > 0 {
|
if m.selectedStack.Length() > 0 {
|
||||||
m.selected, m.min, m.max = m.popView()
|
m.selected, m.minIdx, m.maxIdx = m.popView()
|
||||||
} else {
|
} else {
|
||||||
m.selected = 0
|
m.selected = 0
|
||||||
m.min = 0
|
m.minIdx = 0
|
||||||
m.max = m.Height() - 1
|
m.maxIdx = m.Height() - 1
|
||||||
}
|
}
|
||||||
return m, m.readDir(m.CurrentDirectory, m.ShowHidden)
|
return m, m.readDir(m.CurrentDirectory, m.ShowHidden)
|
||||||
case key.Matches(msg, m.KeyMap.Open):
|
case key.Matches(msg, m.KeyMap.Open):
|
||||||
@@ -349,10 +349,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.CurrentDirectory = filepath.Join(m.CurrentDirectory, f.Name())
|
m.CurrentDirectory = filepath.Join(m.CurrentDirectory, f.Name())
|
||||||
m.pushView(m.selected, m.min, m.max)
|
m.pushView(m.selected, m.minIdx, m.maxIdx)
|
||||||
m.selected = 0
|
m.selected = 0
|
||||||
m.min = 0
|
m.minIdx = 0
|
||||||
m.max = m.Height() - 1
|
m.maxIdx = m.Height() - 1
|
||||||
return m, m.readDir(m.CurrentDirectory, m.ShowHidden)
|
return m, m.readDir(m.CurrentDirectory, m.ShowHidden)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,7 +367,7 @@ func (m Model) View() string {
|
|||||||
var s strings.Builder
|
var s strings.Builder
|
||||||
|
|
||||||
for i, f := range m.files {
|
for i, f := range m.files {
|
||||||
if i < m.min || i > m.max {
|
if i < m.minIdx || i > m.maxIdx {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ import (
|
|||||||
func IsHidden(file string) (bool, error) {
|
func IsHidden(file string) (bool, error) {
|
||||||
pointer, err := syscall.UTF16PtrFromString(file)
|
pointer, err := syscall.UTF16PtrFromString(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err //nolint:wrapcheck
|
||||||
}
|
}
|
||||||
attributes, err := syscall.GetFileAttributes(pointer)
|
attributes, err := syscall.GetFileAttributes(pointer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err //nolint:wrapcheck
|
||||||
}
|
}
|
||||||
return attributes&syscall.FILE_ATTRIBUTE_HIDDEN != 0, nil
|
return attributes&syscall.FILE_ATTRIBUTE_HIDDEN != 0, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -943,13 +943,13 @@ func (m Model) LineInfo() LineInfo {
|
|||||||
// repositionView repositions the view of the viewport based on the defined
|
// repositionView repositions the view of the viewport based on the defined
|
||||||
// scrolling behavior.
|
// scrolling behavior.
|
||||||
func (m *Model) repositionView() {
|
func (m *Model) repositionView() {
|
||||||
min := m.viewport.YOffset
|
minOffset := m.viewport.YOffset
|
||||||
max := min + m.viewport.Height() - 1
|
maxOffset := minOffset + m.viewport.Height() - 1
|
||||||
|
|
||||||
if row := m.cursorLineNumber(); row < min {
|
if row := m.cursorLineNumber(); row < minOffset {
|
||||||
m.viewport.LineUp(min - row)
|
m.viewport.LineUp(minOffset - row)
|
||||||
} else if row > max {
|
} else if row > maxOffset {
|
||||||
m.viewport.LineDown(row - max)
|
m.viewport.LineDown(row - maxOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1219,7 +1219,7 @@ func (m Model) View() string {
|
|||||||
displayLine++
|
displayLine++
|
||||||
|
|
||||||
var ln string
|
var ln string
|
||||||
if m.ShowLineNumbers { //nolint:nestif
|
if m.ShowLineNumbers {
|
||||||
if wl == 0 { // normal line
|
if wl == 0 { // normal line
|
||||||
isCursorLine := m.row == l
|
isCursorLine := m.row == l
|
||||||
s.WriteString(m.lineNumberView(l+1, isCursorLine))
|
s.WriteString(m.lineNumberView(l+1, isCursorLine))
|
||||||
|
|||||||
Reference in New Issue
Block a user