mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add resize handling to log view
This commit is contained in:
parent
28389aa38c
commit
53c0f2a9df
4
menus.go
4
menus.go
@ -160,6 +160,10 @@ func LogMenu() {
|
||||
m.BorderLabel = "Logs"
|
||||
ui.Render(m)
|
||||
|
||||
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
||||
m.Resize()
|
||||
ui.Render(m)
|
||||
})
|
||||
ui.Handle("/sys/kbd/", func(ui.Event) {
|
||||
quit <- true
|
||||
ui.StopLoop()
|
||||
|
@ -32,15 +32,19 @@ func NewTextView(lines <-chan string) *TextView {
|
||||
i.BorderFg = ui.ThemeAttr("menu.border.fg")
|
||||
i.BorderLabelFg = ui.ThemeAttr("menu.label.fg")
|
||||
|
||||
ui.Clear()
|
||||
i.Height = ui.TermHeight()
|
||||
i.Width = ui.TermWidth()
|
||||
i.Resize()
|
||||
|
||||
i.readInputLoop()
|
||||
i.renderLoop()
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *TextView) Resize() {
|
||||
ui.Clear()
|
||||
i.Height = ui.TermHeight()
|
||||
i.Width = ui.TermWidth()
|
||||
}
|
||||
|
||||
func (i *TextView) Buffer() ui.Buffer {
|
||||
|
||||
var cell ui.Cell
|
||||
@ -49,7 +53,13 @@ func (i *TextView) Buffer() ui.Buffer {
|
||||
x := i.Block.X + i.padding[0]
|
||||
y := i.Block.Y + i.padding[1]
|
||||
|
||||
maxWidth := i.Width - (i.padding[0] * 2)
|
||||
|
||||
for _, line := range i.TextOut {
|
||||
// truncate lines longer than maxWidth
|
||||
if len(line) > maxWidth {
|
||||
line = fmt.Sprintf("%s...", line[:maxWidth-3])
|
||||
}
|
||||
for _, ch := range line {
|
||||
cell = ui.Cell{Ch: ch, Fg: i.TextFgColor, Bg: i.TextBgColor}
|
||||
buf.Set(x, y, cell)
|
||||
@ -70,12 +80,6 @@ func (i *TextView) renderLoop() {
|
||||
}
|
||||
i.TextOut = i.Text[len(i.Text)-size:]
|
||||
|
||||
width := i.Width - (i.padding[0] * 2)
|
||||
for n := range i.TextOut {
|
||||
if len(i.TextOut[n]) > width {
|
||||
i.TextOut[n] = fmt.Sprintf("%s...", i.TextOut[n][:width-3])
|
||||
}
|
||||
}
|
||||
ui.Render(i)
|
||||
}
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user