@@ -28,6 +28,7 @@ type FSSize struct {
28
28
files []File
29
29
folders []File
30
30
packages []File // path = package name, sizeBytes = estimated size in kibibytes
31
+ dpkgQueryWorked bool
31
32
maxCount int
32
33
ignoreHiddenFiles bool
33
34
accumulating bool
@@ -41,8 +42,9 @@ type File struct {
41
42
42
43
func NewFSSize () * FSSize {
43
44
return & FSSize {
44
- Box : tview .NewBox ().SetBackgroundColor (tcell .NewRGBColor (46 , 52 , 54 )),
45
- currentTab : Files ,
45
+ Box : tview .NewBox ().SetBackgroundColor (tcell .NewRGBColor (46 , 52 , 54 )),
46
+ currentTab : Files ,
47
+ dpkgQueryWorked : true ,
46
48
}
47
49
}
48
50
@@ -78,6 +80,7 @@ func (fssize *FSSize) Draw(screen tcell.Screen) {
78
80
}
79
81
80
82
tview .Print (screen , filesStyle + " Files [-:-:-:-]" + folderStyle + " Folders [-:-:-:-]" + packagesStyle + " Packages (dpkg-query) [-:-:-:-]" , 0 , 0 , w , tview .AlignLeft , tcell .ColorDefault )
83
+ tview .Print (screen , "<- Press Tab or Shift+Tab to switch " , 0 , 0 , w , tview .AlignRight , tcell .ColorDefault )
81
84
82
85
ptr := & fssize .files
83
86
if fssize .currentTab == Folders {
@@ -86,46 +89,47 @@ func (fssize *FSSize) Draw(screen tcell.Screen) {
86
89
ptr = & fssize .packages
87
90
}
88
91
89
- for i := 0 ; i < len (* ptr ); i ++ {
90
- if i + 1 >= h - 1 { // The bottom row is occupied by the bottom bar
91
- break
92
- }
92
+ if fssize .currentTab == Packages && len (* ptr ) == 0 {
93
+ tview .Print (screen , "[::b]Failed to run dpkg-query" , 0 , h / 2 , w , tview .AlignCenter , tcell .ColorDefault )
94
+ } else {
95
+ for i := 0 ; i < len (* ptr ); i ++ {
96
+ if i + 1 >= h - 1 { // The bottom row is occupied by the bottom bar
97
+ break
98
+ }
93
99
94
- styleText := ""
95
- if i % 2 == 0 {
96
- styleText = "[:#141414:]"
97
- }
100
+ styleText := ""
101
+ if i % 2 == 0 {
102
+ styleText = "[:#141414:]"
103
+ }
98
104
99
- var relPath string
100
- if fssize .rootFolderPath == "/" {
101
- relPath = (* ptr )[i ].path
102
- } else {
103
- var err error
104
- relPath , err = filepath .Rel (fssize .rootFolderPath , (* ptr )[i ].path )
105
- if err != nil {
105
+ var relPath string
106
+ if fssize .rootFolderPath == "/" {
106
107
relPath = (* ptr )[i ].path
108
+ } else {
109
+ var err error
110
+ relPath , err = filepath .Rel (fssize .rootFolderPath , (* ptr )[i ].path )
111
+ if err != nil {
112
+ relPath = (* ptr )[i ].path
113
+ }
107
114
}
108
- }
109
-
110
- prefix := ""
111
- if fssize .currentTab == Packages {
112
- prefix = "~"
113
- }
114
- _ , sizePrintedLength := tview .Print (screen , styleText + "[::b]" + prefix + BytesToHumanReadableUnitString (uint64 ((* ptr )[i ].sizeBytes ), 3 ), 0 , i + 1 , w , tview .AlignRight , tcell .ColorWhite )
115
- // Flawed when FilenameInvisibleCharactersAsCodeHighlighted does anything
116
- if len (relPath ) > w - sizePrintedLength - 1 {
117
- relPath = relPath [:max (0 , w - sizePrintedLength - 1 - 3 )] + "[#606060]..."
118
- }
119
115
120
- filenameText := FilenameInvisibleCharactersAsCodeHighlighted (relPath , styleText )
116
+ prefix := ""
117
+ if fssize .currentTab == Packages {
118
+ prefix = "~"
119
+ }
120
+ _ , sizePrintedLength := tview .Print (screen , styleText + "[::b]" + prefix + BytesToHumanReadableUnitString (uint64 ((* ptr )[i ].sizeBytes ), 3 ), 0 , i + 1 , w , tview .AlignRight , tcell .ColorWhite )
121
+ // Flawed when FilenameInvisibleCharactersAsCodeHighlighted does anything
122
+ if len (relPath ) > w - sizePrintedLength - 1 {
123
+ relPath = relPath [:max (0 , w - sizePrintedLength - 1 - 3 )] + "[#606060]..."
124
+ }
121
125
122
- _ , pathPrintedLength := tview .Print (screen , styleText + filenameText , 0 , i + 1 , w - sizePrintedLength , tview .AlignLeft , tcell .NewRGBColor (200 , 200 , 200 ))
123
- //bruh := int32(max(20, 255-(i*8)))
124
- //tview.Print(screen, styleText+(*ptr)[i].path, 0, i, w, tview.AlignLeft, tcell.NewRGBColor(bruh, bruh, bruh))
126
+ filenameText := FilenameInvisibleCharactersAsCodeHighlighted (relPath , styleText )
127
+ _ , pathPrintedLength := tview .Print (screen , styleText + filenameText , 0 , i + 1 , w - sizePrintedLength , tview .AlignLeft , tcell .NewRGBColor (200 , 200 , 200 ))
125
128
126
- if i % 2 == 0 {
127
- for j := pathPrintedLength ; j < w - sizePrintedLength ; j ++ {
128
- screen .SetContent (j , i + 1 , ' ' , nil , tcell .StyleDefault .Background (tcell .NewRGBColor (0x14 , 0x14 , 0x14 )))
129
+ if i % 2 == 0 {
130
+ for j := pathPrintedLength ; j < w - sizePrintedLength ; j ++ {
131
+ screen .SetContent (j , i + 1 , ' ' , nil , tcell .StyleDefault .Background (tcell .NewRGBColor (0x14 , 0x14 , 0x14 )))
132
+ }
129
133
}
130
134
}
131
135
}
@@ -145,6 +149,7 @@ func (fssize *FSSize) Draw(screen tcell.Screen) {
145
149
tview .Print (screen , "[:#00ff00:] Finished " , 0 , h - 1 , w , tview .AlignLeft , tcell .ColorBlack )
146
150
}
147
151
152
+ tview .Print (screen , programName + " " + version , 0 , h - 1 , w , tview .AlignCenter , tcell .ColorBlack )
148
153
tview .Print (screen , "Press 'q' to quit " , 0 , h - 1 , w , tview .AlignRight , tcell .ColorBlack )
149
154
}
150
155
@@ -271,6 +276,7 @@ func (fssize *FSSize) AccumulatePackages() error {
271
276
// According to the man page, --showformat has a short option '-f' since dpkg 1.13.1, so let's use the long option
272
277
output , err := exec .Command ("dpkg-query" , "--show" , "--showformat=${Installed-Size},${Package}\n " ).Output ()
273
278
if err != nil {
279
+ fssize .dpkgQueryWorked = false
274
280
return err
275
281
}
276
282
0 commit comments