Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed May 26, 2024
1 parent 65af451 commit f8b7c8b
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 181 deletions.
45 changes: 20 additions & 25 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
run:
timeout: 5m
tests: false

issues:
include:
- EXC0001
- EXC0005
- EXC0011
- EXC0012
- EXC0013

max-issues-per-linter: 0
max-same-issues: 0

linters:
disable-all: true
enable:
- bodyclose
- dogsled
- errcheck
- exportloopref
- gochecknoinits
- goconst
- gocritic
- gofmt
- goprintffuncname
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- noctx
- nolintlint
- gofumpt
- goimports
- gosec
- nilerr
- predeclared
- revive
- rowserrcheck
- staticcheck
- stylecheck
- typecheck
- sqlclosecheck
- tparallel
- unconvert
- unparam
- unused
- whitespace
- wastedassign
- nilerr
- godot
- godox
- goimports
103 changes: 103 additions & 0 deletions internal/tui/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package tui

import (
"fmt"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"

"github.com/mistakenelf/fm/polish"
"github.com/mistakenelf/fm/statusbar"
)

func (m *Model) disableAllViewports() {
m.code.SetViewportDisabled(true)
m.pdf.SetViewportDisabled(true)
m.markdown.SetViewportDisabled(true)
m.help.SetViewportDisabled(true)
m.image.SetViewportDisabled(true)
m.csv.SetViewportDisabled(true)
}

func (m *Model) resetViewports() {
m.code.GotoTop()
m.pdf.GotoTop()
m.markdown.GotoTop()
m.help.GotoTop()
m.image.GotoTop()
m.csv.GotoTop()
}

func (m *Model) updateStatusBar() {
selectedItem := m.filetree[m.activeWorkspace].GetSelectedItem()

if selectedItem.Name != "" {
statusMessage := m.filetree[m.activeWorkspace].CurrentDirectory +
lipgloss.NewStyle().
Padding(0, 1).
Foreground(polish.Colors.Yellow500).
Render(selectedItem.Details)

switch {
case m.filetree[m.activeWorkspace].StatusMessage != "":
statusMessage = m.filetree[m.activeWorkspace].StatusMessage
case m.code.StatusMessage != "":
statusMessage = m.code.StatusMessage
case m.markdown.StatusMessage != "":
statusMessage = m.markdown.StatusMessage
case m.pdf.StatusMessage != "":
statusMessage = m.pdf.StatusMessage
case m.image.StatusMessage != "":
statusMessage = m.image.StatusMessage
case m.statusMessage != "":
statusMessage = m.statusMessage
case m.showTextInput:
statusMessage = m.textinput.View()
}

m.statusbar.SetContent(
selectedItem.Name,
statusMessage,
strings.Trim(strings.Join(strings.Fields(fmt.Sprint(m.workspaces)), ","), "[]"),
fmt.Sprintf("%d/%d", m.filetree[m.activeWorkspace].Cursor+1, m.filetree[m.activeWorkspace].GetTotalItems()),
fmt.Sprintf(selectedItem.FileSize),
)
} else {
statusMessage := "Directory is empty"

if m.showTextInput {
statusMessage = m.textinput.View()
}

m.statusbar.SetContent(
"N/A",
statusMessage,
fmt.Sprintf("%d", m.activeWorkspace+1),
fmt.Sprintf("%d/%d", 0, 0),
"FM",
)
}
}

func (m Model) handleWindowResizie(msg tea.WindowSizeMsg) (Model, tea.Cmd) {
var cmds []tea.Cmd

m.width = msg.Width
m.height = msg.Height
halfSize := msg.Width / 2
height := msg.Height - statusbar.Height

cmds = append(cmds, m.image.SetSizeCmd(halfSize, height))
cmds = append(cmds, m.markdown.SetSizeCmd(halfSize, height))
cmds = append(cmds, m.csv.SetSizeCmd(halfSize, height))

m.filetree[m.activeWorkspace].SetSize(halfSize, height-3)
m.secondaryFiletree.SetSize(halfSize, height-3)
m.code.SetSize(halfSize, height)
m.pdf.SetSize(halfSize, height)
m.statusbar.SetSize(msg.Width)
m.help.SetSize(halfSize, height)

return m, tea.Batch(cmds...)
}
24 changes: 4 additions & 20 deletions internal/tui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,12 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/mistakenelf/fm/polish"
"github.com/mistakenelf/fm/utilities"
)

var forbiddenExtensions = []string{
".FCStd",
".gif",
".zip",
".rar",
".webm",
".sqlite",
".sqlite-shm",
".sqlite-wal",
".DS_Store",
".db",
".data",
".plist",
".webp",
".img",
}

type statusMessageTimeoutMsg struct{}

func (m *model) openFileCmd() tea.Cmd {
func (m *Model) openFileCmd() tea.Cmd {
selectedFile := m.filetree[m.activeWorkspace].GetSelectedItem()

if !selectedFile.IsDirectory {
Expand All @@ -50,7 +34,7 @@ func (m *model) openFileCmd() tea.Cmd {
m.state = showPdfState

return m.pdf.SetFileNameCmd(selectedFile.Path)
case contains(forbiddenExtensions, selectedFile.Extension):
case utilities.Contains(forbiddenExtensions, selectedFile.Extension):
return m.newStatusMessageCmd(lipgloss.NewStyle().
Foreground(polish.Colors.Red600).
Bold(true).
Expand All @@ -67,7 +51,7 @@ func (m *model) openFileCmd() tea.Cmd {

// newStatusMessage sets a new status message, which will show for a limited
// amount of time.
func (m *model) newStatusMessageCmd(s string) tea.Cmd {
func (m *Model) newStatusMessageCmd(s string) tea.Cmd {
m.statusMessage = s

if m.statusMessageTimer != nil {
Expand Down
18 changes: 18 additions & 0 deletions internal/tui/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tui

var forbiddenExtensions = []string{
".FCStd",
".gif",
".zip",
".rar",
".webm",
".sqlite",
".sqlite-shm",
".sqlite-wal",
".DS_Store",
".db",
".data",
".plist",
".webp",
".img",
}
97 changes: 0 additions & 97 deletions internal/tui/helpers.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/tui/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Init intializes the UI.
func (m model) Init() tea.Cmd {
func (m Model) Init() tea.Cmd {
return tea.Batch(
m.filetree[m.activeWorkspace].Init(),
m.secondaryFiletree.Init(),
Expand Down
8 changes: 5 additions & 3 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
showCsvState
)

// Config represents the application configuration.
type Config struct {
StartDir string
SelectionPath string
Expand All @@ -40,7 +41,8 @@ type Config struct {
Theme theme.Theme
}

type model struct {
// Model represents all properties of the TUI.
type Model struct {
filetree []filetree.Model
secondaryFiletree filetree.Model
csv csv.Model
Expand All @@ -67,7 +69,7 @@ type model struct {
}

// New creates a new instance of the UI.
func New(cfg Config) model {
func New(cfg Config) Model {
filetreeModel := filetree.New(cfg.StartDir)
filetreeModel.SetTheme(cfg.Theme.SelectedTreeItemColor, cfg.Theme.UnselectedTreeItemColor)
filetreeModel.SetSelectionPath(cfg.SelectionPath)
Expand Down Expand Up @@ -158,7 +160,7 @@ func New(cfg Config) model {
)
helpModel.SetViewportDisabled(true)

return model{
return Model{
filetree: []filetree.Model{filetreeModel},
secondaryFiletree: secondaryFiletree,
help: helpModel,
Expand Down
Loading

0 comments on commit f8b7c8b

Please sign in to comment.