diff options
author | Caleb Bassi <calebjbassi@gmail.com> | 2018-04-19 20:24:14 -0700 |
---|---|---|
committer | Caleb Bassi <calebjbassi@gmail.com> | 2018-04-19 20:24:14 -0700 |
commit | 5135d62cbe94992eec12220e7c6d5cb7044afad9 (patch) | |
tree | 9742e614df6cb10220e92da7c89ac30396296e31 /widgets | |
parent | 4da1e467d227c5acbac79193002aa44ce8f7d95d (diff) |
Fix column sizing after terminal shrinks
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/proc.go | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/widgets/proc.go b/widgets/proc.go index 24320a9..d521fcc 100644 --- a/widgets/proc.go +++ b/widgets/proc.go @@ -34,13 +34,14 @@ type Process struct { type Proc struct { *ui.Table - cpuCount int - interval time.Duration - sortMethod string - groupedProcs []Process - ungroupedProcs []Process - group bool - KeyPressed chan bool + cpuCount int + interval time.Duration + sortMethod string + groupedProcs []Process + ungroupedProcs []Process + group bool + KeyPressed chan bool + DefaultColWidths []int } func NewProc(keyPressed chan bool) *Proc { @@ -53,9 +54,10 @@ func NewProc(keyPressed chan bool) *Proc { group: true, KeyPressed: keyPressed, } - self.ColResizer = self.ColResize self.Label = "Process List" - self.ColWidths = []int{5, 10, 4, 4} + self.ColResizer = self.ColResize + self.DefaultColWidths = []int{5, 10, 4, 4} + self.ColWidths = make([]int, 4) self.UniqueCol = 0 if self.group { @@ -133,6 +135,8 @@ func (self *Proc) Sort() { // ColResize overrides the default ColResize in the termui table. func (self *Proc) ColResize() { + copy(self.ColWidths, self.DefaultColWidths) + // calculate gap size based on total width self.Gap = 3 if self.X < 50 { @@ -159,7 +163,7 @@ func (self *Proc) ColResize() { self.ColWidths[2] = 0 self.ColWidths[3] = 0 } else if self.X < rowWidth { - self.CellXPos[2] = self.CellXPos[3] + self.CellXPos[2] = self.CellXPos[3] - 1 self.ColWidths[3] = 0 } } |