add resize handling to log view

This commit is contained in:
Bradley Cicenas 2017-11-28 13:55:29 +00:00
parent 28389aa38c
commit 53c0f2a9df
2 changed files with 17 additions and 9 deletions

View File

@ -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()

View File

@ -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)
}
}()