Skip to content

Commit 214e85d

Browse files
authored
Update color schema.
1 parent ef1ce6e commit 214e85d

10 files changed

Lines changed: 61 additions & 25 deletions

File tree

default-color-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"cellText": "",
3636
"tableHeaderBorder": "240",
37+
"tableHeaderText": "#FFBF69",
3738
"selectedRowText": "#262626",
3839
"selectedRowBackground": "#EBBD34",
3940
"markedRowText": "#262626",
@@ -53,6 +54,9 @@
5354
"cmdInputText": "#80ed99",
5455
"cmdBarBorder": "240",
5556
"sizeUnit": {
57+
"b": "#C4FFCE",
58+
"kb": "#A1E162",
59+
"mb": "#FFEB6A",
5660
"gb": "#f48c06",
5761
"tb": "#dc2f02",
5862
"pb": "#9d0208",

render/color_schema.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ type StatusBarColors struct {
4646
}
4747

4848
type SizeUnitColors struct {
49+
B string `json:"b"`
50+
KB string `json:"kb"`
51+
MB string `json:"mb"`
4952
GB string `json:"gb"`
5053
TB string `json:"tb"`
5154
PB string `json:"pb"`
@@ -64,6 +67,7 @@ type ColorSchema struct {
6467
ChartColors ChartColors `json:"chart"`
6568
CellText string `json:"cellText"`
6669
TableHeaderBorder string `json:"tableHeaderBorder"`
70+
TableHeaderText string `json:"tableHeaderText"`
6771
SelectedRowText string `json:"selectedRowText"`
6872
SelectedRowBG string `json:"selectedRowBackground"`
6973
MarkedRowText string `json:"markedRowText"`
@@ -114,6 +118,7 @@ func DefaultColorSchema() ColorSchema {
114118
ColorProfile: 0,
115119
StartColor: "#833AB4",
116120
EndColor: "#FCB045",
121+
ShowPercent: true,
117122
},
118123
UsageProgressBar: PG{
119124
ColorProfile: 3,
@@ -155,6 +160,7 @@ func DefaultColorSchema() ColorSchema {
155160
},
156161
CellText: "",
157162
TableHeaderBorder: "240",
163+
TableHeaderText: "#FFBF69",
158164
SelectedRowText: "#262626",
159165
SelectedRowBG: "#EBBD34",
160166
MarkedRowText: "#262626",
@@ -174,6 +180,9 @@ func DefaultColorSchema() ColorSchema {
174180
CmdInputText: "#80ed99",
175181
CmdBarBorder: "240",
176182
SizeUnit: SizeUnitColors{
183+
B: "#C4FFCE",
184+
KB: "#A1E162",
185+
MB: "#FFEB6A",
177186
GB: "#f48c06",
178187
TB: "#dc2f02",
179188
PB: "#9d0208",

render/dir_model.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func NewDirModel(nav *Navigation, filters ...filter.EntryFilter) *DirModel {
120120
columns: Columns{
121121
{Title: "", Width: 5, Fixed: true},
122122
{Title: "", Hidden: func(_ int) bool { return true }},
123-
{Title: "Name", SortKey: structure.SortPath, WidthRatio: 0.25},
123+
{Title: "Name", SortKey: structure.SortPath, WidthRatio: 0.35},
124124
{
125125
Title: "Size",
126126
SortKey: structure.SortSize,
@@ -130,13 +130,13 @@ func NewDirModel(nav *Navigation, filters ...filter.EntryFilter) *DirModel {
130130
{
131131
Title: "Total Dirs",
132132
SortKey: structure.SortTotalDirs,
133-
WidthRatio: DefaultColWidthRatio,
133+
WidthRatio: 0.07,
134134
Hidden: func(fw int) bool { return fw < 100 },
135135
},
136136
{
137137
Title: "Total Files",
138138
SortKey: structure.SortTotalFiles,
139-
WidthRatio: DefaultColWidthRatio,
139+
WidthRatio: 0.07,
140140
Hidden: func(fw int) bool { return fw < 100 },
141141
},
142142
{
@@ -539,8 +539,6 @@ func (dm *DirModel) updateTableData() {
539539
}
540540

541541
nameCol, _ := dm.columns.Get(2)
542-
sizeCol, _ := dm.columns.Get(3)
543-
usageCol, _ := dm.columns.Get(7)
544542
pgCol, _ := dm.columns.Get(8)
545543

546544
dm.dirsTable.SetColumns(dm.columns.TableColumns(dm.width, dm.sortState))
@@ -574,11 +572,11 @@ func (dm *DirModel) updateTableData() {
574572
EntryIcon(child),
575573
child.Name(),
576574
WrapString(child.Name(), nameCol.Width),
577-
FmtSizeColor(child.Size, entrySizeWidth, sizeCol.Width),
578-
totalDirs,
579-
totalFiles,
580-
time.Unix(child.ModTime, 0).Format("02 Jan 2006"),
581-
FmtUsage(parentUsage, 20, usageCol.Width),
575+
FmtSizeColor(child.Size, entrySizeWidth),
576+
Faint(totalDirs),
577+
Faint(totalFiles),
578+
Faint(time.Unix(child.ModTime, 0).Format("02 Jan 2006")),
579+
FmtUsage(parentUsage, 20),
582580
pgBar,
583581
},
584582
)
@@ -645,7 +643,7 @@ func (dm *DirModel) viewTopStatusBar() string {
645643
BGColor: sbStyle.BG,
646644
},
647645
{Content: "TO FREE", BGColor: style.cs.StatusBar.Dirs.RowsCounter},
648-
{Content: FmtSizeColor(selectedSize, 0, 0), BGColor: sbStyle.BG},
646+
{Content: FmtSizeColor(selectedSize, 0), BGColor: sbStyle.BG},
649647
}...,
650648
)
651649

@@ -690,7 +688,7 @@ func (dm *DirModel) viewBottomStatusBar() string {
690688
[]*BarItem{
691689
{Content: string(dm.mode), BGColor: sbStyle.Dirs.ModeBG},
692690
{Content: "SIZE", BGColor: sbStyle.Dirs.SizeBG},
693-
{Content: FmtSizeColor(dm.summaryInfo.size, 0, 0), BGColor: sbStyle.BG},
691+
{Content: FmtSizeColor(dm.summaryInfo.size, 0), BGColor: sbStyle.BG},
694692
{Content: "DIRS", BGColor: sbStyle.Dirs.DirsBG},
695693
{Content: unitFmt(dm.summaryInfo.dirs), BGColor: sbStyle.BG},
696694
{Content: "FILES", BGColor: sbStyle.Dirs.FilesBG},

render/drive_model.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func (dm *DriveModel) View() string {
170170
func (dm *DriveModel) updateTableData(key drive.SortKey, sortDesc bool) {
171171
pathCol, _ := dm.columns.Get(2)
172172
volumeCol, _ := dm.columns.Get(3)
173-
usageCol, _ := dm.columns.Get(8)
174173
pgCol, _ := dm.columns.Get(9)
175174

176175
dm.drivesTable.SetColumns(dm.columns.TableColumns(dm.width, dm.sortState))
@@ -190,11 +189,11 @@ func (dm *DriveModel) updateTableData(key drive.SortKey, sortDesc bool) {
190189
d.Path,
191190
WrapString(d.Path, pathCol.Width),
192191
d.Volume,
193-
d.FSName,
192+
Faint(d.FSName),
194193
FmtSize(d.TotalBytes, driveSizeWidth),
195194
FmtSize(d.UsedBytes, driveSizeWidth),
196195
FmtSize(d.FreeBytes, driveSizeWidth),
197-
FmtUsage(d.UsedPercent/100, 80, usageCol.Width),
196+
FmtUsage(d.UsedPercent/100, 80),
198197
lipgloss.JoinHorizontal(
199198
lipgloss.Top,
200199
strings.Repeat(" ", max(0, pgCol.Width-lipgloss.Width(pgBar))),

render/fmt.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func FmtSize[T numeric](bytesSize T, width int) string {
2929
return fmt.Sprintf("%s%*s", size, padding, suffix)
3030
}
3131

32-
func FmtSizeColor[T numeric](bytesSize T, width, fullWidth int) string {
32+
func FmtSizeColor[T numeric](bytesSize T, width int) string {
3333
size, suffix := fmtSize(bytesSize)
3434
padding, sizeUnitStyle := 1, style.SizeUnit(suffix)
3535

@@ -41,7 +41,7 @@ func FmtSizeColor[T numeric](bytesSize T, width, fullWidth int) string {
4141
lipgloss.Left,
4242
size,
4343
strings.Repeat(" ", padding),
44-
sizeUnitStyle.Render(suffix+strings.Repeat(" ", fullWidth)),
44+
sizeUnitStyle.Render(suffix),
4545
)
4646
}
4747

@@ -82,7 +82,7 @@ func WrapString(data string, limit int) string {
8282
return wrappedData
8383
}
8484

85-
func FmtUsage(usage, threshold float64, fullWidth int) string {
85+
func FmtUsage(usage, threshold float64) string {
8686
// minWidth defines a width of longest possible usage string value 100.00 %.
8787
minWidth := 8
8888
usagePercent := max(usage, 0) * 100
@@ -95,9 +95,8 @@ func FmtUsage(usage, threshold float64, fullWidth int) string {
9595

9696
usageStr := strconv.FormatFloat(usagePercent, 'f', 2, 64)
9797
spacing := strings.Repeat(" ", max(minWidth-len(usageStr)-2, 0))
98-
suffix := " %" + strings.Repeat(" ", max(fullWidth-minWidth, 0))
9998

100-
return s.Render(usageStr + spacing + suffix)
99+
return s.Render(usageStr + spacing + " %")
101100
}
102101

103102
func WrapPath(path string, limit int) string {

render/fmt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestFmtUsage(t *testing.T) {
5151
}
5252

5353
for _, data := range tableData {
54-
require.Equal(t, data.expected, render.FmtUsage(data.usage, 80, 8))
54+
require.Equal(t, data.expected, render.FmtUsage(data.usage, 80))
5555
}
5656
}
5757

render/render.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ func buildTable() *table.Model {
232232
s.Header = *style.TableHeader()
233233
s.Selected = *style.SelectedRow()
234234
s.Marked = *style.MarkedRow()
235-
s.Cell = lipgloss.NewStyle().
236-
Foreground(lipgloss.Color(style.CS().CellText))
235+
s.Cell = lipgloss.NewStyle().Foreground(lipgloss.Color(style.CS().CellText))
237236

238237
tbl.SetStyles(s)
239238

render/style.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (s *Style) TableHeader() *lipgloss.Style {
3939
Bold(true).
4040
BorderStyle(lipgloss.ThickBorder()).
4141
BorderForeground(lipgloss.Color(s.cs.TableHeaderBorder)).
42+
Foreground(lipgloss.Color(s.cs.TableHeaderText)).
4243
BorderBottom(true)
4344

4445
s.cache["tableHeader"] = &cs
@@ -243,6 +244,9 @@ func (s *Style) SizeUnit(unit string) *lipgloss.Style {
243244
cv, ok := s.cache[ck]
244245
if !ok {
245246
sizeUnitColorsMap := map[string]string{
247+
"B": s.cs.SizeUnit.B,
248+
"KB": s.cs.SizeUnit.KB,
249+
"MB": s.cs.SizeUnit.MB,
246250
"GB": s.cs.SizeUnit.GB,
247251
"TB": s.cs.SizeUnit.TB,
248252
"PB": s.cs.SizeUnit.PB,
@@ -286,3 +290,7 @@ func (s *Style) CmdBarBorder() *lipgloss.Style {
286290

287291
return cv
288292
}
293+
294+
func Faint(content string) string {
295+
return lipgloss.NewStyle().Faint(true).Render(content)
296+
}

render/table/table.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
package table
44

55
import (
6+
"regexp"
7+
"strings"
8+
69
"github.com/charmbracelet/bubbles/help"
710
"github.com/charmbracelet/bubbles/key"
811
"github.com/charmbracelet/bubbles/viewport"
@@ -11,6 +14,8 @@ import (
1114
"github.com/mattn/go-runewidth"
1215
)
1316

17+
var ansiEscapeRegexp = regexp.MustCompile(`\x1B\[0m`)
18+
1419
type Model struct {
1520
KeyMap KeyMap
1621
styles Styles
@@ -336,6 +341,21 @@ func (m *Model) renderRow(r int) string {
336341
renderer = m.styles.Selected
337342
}
338343

344+
// filling the cell's space between text content and the escape
345+
// character so the selected style background can be applied.
346+
escapeBounds := ansiEscapeRegexp.FindStringIndex(value)
347+
348+
if len(escapeBounds) > 0 {
349+
startEscapeIdx := escapeBounds[0]
350+
351+
padding := strings.Repeat(
352+
" ",
353+
max(0, m.cols[i].Width-lipgloss.Width(value[:startEscapeIdx])),
354+
)
355+
356+
value = value[:startEscapeIdx] + padding + value[startEscapeIdx:]
357+
}
358+
339359
cell := lipgloss.NewStyle().
340360
Width(m.cols[i].Width).
341361
MaxWidth(m.cols[i].Width).

render/top_entries_model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ func (te *TopEntries) setEntries(entries heap.Interface, tm *table.Model, title
145145
EntryIcon(file),
146146
file.Path,
147147
filePath,
148-
FmtSizeColor(file.Size, entrySizeWidth, colSize),
149-
time.Unix(file.ModTime, 0).Format("Jan 02 15:04"),
148+
FmtSizeColor(file.Size, entrySizeWidth),
149+
Faint(time.Unix(file.ModTime, 0).Format("Jan 02 15:04")),
150150
}
151151
}
152152

0 commit comments

Comments
 (0)