mirror of https://github.com/cjbassi/gotop.git
Fix column spacing issues
This commit is contained in:
parent
ba84728600
commit
8505b9c240
|
@ -17,7 +17,7 @@
|
|||
branch = "master"
|
||||
name = "github.com/cjbassi/termui"
|
||||
packages = ["."]
|
||||
revision = "39b79d4cffc860780782f8ca6cca4bbb9d38bbf2"
|
||||
revision = "75525ee19c41f52324024b7a2bf31edcd1428494"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
|
|
@ -5,7 +5,7 @@ A fork of [termui](https://github.com/gizak/termui) with a lot of code cleanup a
|
|||
You can see an implementation/example usage of this library [here](https://github.com/cjbassi/gotop).
|
||||
|
||||
Some usage improvements include:
|
||||
* better event/keypress names
|
||||
* better event/key-combo names
|
||||
* more convenient event handling function
|
||||
* 256 colors
|
||||
* better grid system
|
||||
|
|
|
@ -13,25 +13,6 @@ const (
|
|||
AttrReverse
|
||||
)
|
||||
|
||||
// Theme is assigned to the current theme.
|
||||
var Theme = DefaultTheme
|
||||
|
||||
// DefaultTheme implements a generic set of colors to use by default.
|
||||
var DefaultTheme = Colorscheme{
|
||||
Fg: 7,
|
||||
Bg: -1,
|
||||
|
||||
LabelFg: 7,
|
||||
LabelBg: -1,
|
||||
BorderFg: 6,
|
||||
BorderBg: -1,
|
||||
|
||||
Sparkline: 4,
|
||||
LineGraph: 0,
|
||||
TableCursor: 4,
|
||||
GaugeColor: 7,
|
||||
}
|
||||
|
||||
// A Colorscheme represents the current look-and-feel of the dashboard.
|
||||
type Colorscheme struct {
|
||||
Fg Color
|
||||
|
@ -47,3 +28,18 @@ type Colorscheme struct {
|
|||
TableCursor Color
|
||||
GaugeColor Color
|
||||
}
|
||||
|
||||
var Theme = Colorscheme{
|
||||
Fg: 7,
|
||||
Bg: -1,
|
||||
|
||||
LabelFg: 7,
|
||||
LabelBg: -1,
|
||||
BorderFg: 6,
|
||||
BorderBg: -1,
|
||||
|
||||
Sparkline: 4,
|
||||
LineGraph: 0,
|
||||
TableCursor: 4,
|
||||
GaugeColor: 7,
|
||||
}
|
||||
|
|
|
@ -8,17 +8,21 @@ import (
|
|||
// Table tracks all the attributes of a Table instance
|
||||
type Table struct {
|
||||
*Block
|
||||
Header []string
|
||||
Rows [][]string
|
||||
ColWidths []int
|
||||
CellXPos []int // column position
|
||||
Gap int // gap between columns
|
||||
Cursor Color
|
||||
|
||||
Header []string
|
||||
Rows [][]string
|
||||
|
||||
ColWidths []int
|
||||
CellXPos []int // column position
|
||||
ColResizer func() // for widgets that inherit a Table and want to overload the ColResize method
|
||||
Gap int // gap between columns
|
||||
|
||||
Cursor Color
|
||||
|
||||
UniqueCol int // the column used to identify the selected item
|
||||
SelectedItem string // used to keep the cursor on the correct item if the data changes
|
||||
SelectedRow int
|
||||
TopRow int // used to indicate where in the table we are scrolled at
|
||||
ColResizer func() // for widgets that inherit a Table and want to overload the ColResize method
|
||||
TopRow int // used to indicate where in the table we are scrolled at
|
||||
}
|
||||
|
||||
// NewTable returns a new Table instance
|
||||
|
@ -63,9 +67,9 @@ func (self *Table) Buffer() *Buffer {
|
|||
for i, h := range self.Header {
|
||||
width := self.ColWidths[i]
|
||||
if width == 0 {
|
||||
break
|
||||
continue
|
||||
}
|
||||
h = MaxString(h, self.X-6)
|
||||
h = MaxString(h, self.X-self.CellXPos[i])
|
||||
buf.SetString(self.CellXPos[i], 1, h, self.Fg|AttrBold, self.Bg)
|
||||
}
|
||||
|
||||
|
@ -89,7 +93,7 @@ func (self *Table) Buffer() *Buffer {
|
|||
bg = self.Cursor
|
||||
for _, width := range self.ColWidths {
|
||||
if width == 0 {
|
||||
break
|
||||
continue
|
||||
}
|
||||
buf.SetString(1, y, strings.Repeat(" ", self.X), self.Fg, bg)
|
||||
}
|
||||
|
@ -100,9 +104,9 @@ func (self *Table) Buffer() *Buffer {
|
|||
// prints each col of the row
|
||||
for i, width := range self.ColWidths {
|
||||
if width == 0 {
|
||||
break
|
||||
continue
|
||||
}
|
||||
r := MaxString(row[i], self.X-6)
|
||||
r := MaxString(row[i], self.X-self.CellXPos[i])
|
||||
buf.SetString(self.CellXPos[i], y, r, self.Fg, bg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,22 +8,15 @@ import (
|
|||
"time"
|
||||
|
||||
ui "github.com/cjbassi/termui"
|
||||
"github.com/mattn/go-runewidth"
|
||||
psCPU "github.com/shirou/gopsutil/cpu"
|
||||
psProc "github.com/shirou/gopsutil/process"
|
||||
)
|
||||
|
||||
var arrowWidth int
|
||||
|
||||
const (
|
||||
UP = "▲"
|
||||
DOWN = "▼"
|
||||
)
|
||||
|
||||
func init() {
|
||||
arrowWidth = runewidth.StringWidth(UP)
|
||||
}
|
||||
|
||||
// Process represents each process.
|
||||
type Process struct {
|
||||
PID int32
|
||||
|
@ -137,13 +130,7 @@ func (self *Proc) Sort() {
|
|||
func (self *Proc) ColResize() {
|
||||
copy(self.ColWidths, self.DefaultColWidths)
|
||||
|
||||
// calculate gap size based on total width
|
||||
self.Gap = 3
|
||||
if self.X < 50 {
|
||||
self.Gap = 1
|
||||
} else if self.X < 75 {
|
||||
self.Gap = 2
|
||||
}
|
||||
|
||||
self.CellXPos = []int{
|
||||
self.Gap,
|
||||
|
@ -163,7 +150,7 @@ func (self *Proc) ColResize() {
|
|||
self.ColWidths[2] = 0
|
||||
self.ColWidths[3] = 0
|
||||
} else if self.X < rowWidth {
|
||||
self.CellXPos[2] = self.CellXPos[3] - 1
|
||||
self.CellXPos[2] = self.CellXPos[3]
|
||||
self.ColWidths[3] = 0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue