Skip to content
Open
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/crumbyte/noxdir
go 1.24

require (
git.sr.ht/~mpldr/go-indicators v1.3.0
github.com/charmbracelet/bubbles v0.21.0
github.com/charmbracelet/bubbletea v1.3.4
github.com/charmbracelet/lipgloss v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
git.sr.ht/~mpldr/go-indicators v1.3.0 h1:GYa520SxyVMh3dRgOhxHJOjPuekfCN84J+azoO+/iag=
git.sr.ht/~mpldr/go-indicators v1.3.0/go.mod h1:LmE7FfIbTqLOyYpVyS6GzmgDcsuLg0GebU1fKhUMBKw=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand Down
6 changes: 3 additions & 3 deletions render/dir_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (dm *DirModel) updateTableData() {
dm.dirsTable.SetColumns(columns)
dm.dirsTable.SetCursor(0)

fillProgress := NewProgressBar(progressWidth, '🟥', ' ')
progBar.Width = progressWidth-1

rows := make([]table.Row, 0, len(dm.nav.Entry().Child))
dm.nav.Entry().SortChild()
Expand All @@ -326,7 +326,7 @@ func (dm *DirModel) updateTableData() {
}

parentUsage := float64(child.Size) / float64(dm.nav.ParentSize())
pgBar := fillProgress.ViewAs(parentUsage)
pgBar := progBar.GetBar(parentUsage, 1)

rows = append(
rows,
Expand All @@ -339,7 +339,7 @@ func (dm *DirModel) updateTableData() {
totalFiles,
time.Unix(child.ModTime, 0).Format("2006-01-02 15:04"),
strconv.FormatFloat(parentUsage*100, 'f', 2, 64) + " %",
pgBar,
"▕"+pgBar,
},
)
}
Expand Down
27 changes: 20 additions & 7 deletions render/drive_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/crumbyte/noxdir/drive"

"git.sr.ht/~mpldr/go-indicators/progress"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand Down Expand Up @@ -136,13 +137,16 @@ func (dm *DriveModel) updateTableData(key drive.SortKey, sortDesc bool) {
dm.drivesTable.SetColumns(columns)
dm.drivesTable.SetCursor(0)

diskFillProgress := NewProgressBar(progressWidth, '🟥', '🟩')
progBar.Width = progressWidth - 2
if progBar.Width < 0 {
progBar.Width = 0
}

allDrives := dm.nav.DrivesList().Sort(key, sortDesc)
rows := make([]table.Row, 0, len(allDrives))

for _, d := range allDrives {
pgBar := diskFillProgress.ViewAs(d.UsedPercent / 100)
pgBar := progBar.GetBar(d.UsedPercent, 100.0)
rows = append(rows, table.Row{
"⛃",
d.Path,
Expand All @@ -152,11 +156,7 @@ func (dm *DriveModel) updateTableData(key drive.SortKey, sortDesc bool) {
fmtSize(d.UsedBytes, true),
fmtSize(d.FreeBytes, true),
strconv.FormatFloat(d.UsedPercent, 'f', 2, 64) + " %",
lipgloss.JoinHorizontal(
lipgloss.Top,
strings.Repeat(" ", progressWidth-lipgloss.Width(pgBar)),
pgBar,
),
"▕" + pgBar + "▏",
})
}

Expand Down Expand Up @@ -203,3 +203,16 @@ func (dm *DriveModel) sortDrives(sortKey drive.SortKey) {
func (dm *DriveModel) resetSort() {
dm.sortState = SortState{Key: drive.TotalUsedP, Desc: false}
}

var (
progBar = &progress.Progress{
Width: 0,
}
barStyle = lipgloss.NewStyle().
Foreground(lipgloss.ANSIColor(9)).
Background(lipgloss.ANSIColor(10))
)

func init() {
progBar.SetStyle("block")
}
17 changes: 0 additions & 17 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import (
"github.com/crumbyte/noxdir/structure"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"

"github.com/muesli/termenv"
)

const Version = "v0.1.2"
Expand Down Expand Up @@ -188,20 +185,6 @@ func (vm *ViewModel) refresh() {
}()
}

func NewProgressBar(width int, full, empty rune) progress.Model {
maxCharLen := max(
lipgloss.Width(string(full)),
lipgloss.Width(string(empty)),
)

return progress.New(
progress.WithColorProfile(termenv.Ascii),
progress.WithWidth(width/maxCharLen),
progress.WithFillCharacters(full, empty),
progress.WithoutPercentage(),
)
}

func SetTeaProgram(tp *tea.Program) {
teaProg = tp
}
Expand Down