jroimartin / gocui

Minimalist Go package aimed at creating Console User Interfaces.
BSD 3-Clause "New" or "Revised" License
9.92k stars 608 forks source link

View not updated on resize? #128

Closed rgl closed 6 years ago

rgl commented 6 years ago

I want to show the terminal width right aligned on the first line of the terminal, but when I resize the terminal, the view does not seem to be updated. Any idea why?

The "35" text should be right aligned after I resize the terminal, but it isn't:

image

Here's the code:

package main

import (
    "fmt"
    "log"

    "github.com/jroimartin/gocui"
    "github.com/willf/pad"
)

func main() {
    g, err := gocui.NewGui(gocui.OutputNormal)
    if err != nil {
        log.Panicln(err)
    }
    defer g.Close()

    g.SetManagerFunc(layout)

    if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
        log.Panicln(err)
    }

    if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
        log.Panicln(err)
    }
}

func layout(g *gocui.Gui) error {
    mx, _ := g.Size()
    if v, err := g.SetView("title", -1, -1, mx, 1); err != nil {
        if err != gocui.ErrUnknownView {
            return err
        }
        v.Frame = false
        v.FgColor = gocui.ColorWhite
        v.BgColor = gocui.ColorBlue
        fmt.Fprintln(v, pad.Left(fmt.Sprintf("%d", mx), mx, " "))
    }
    return nil
}

func quit(g *gocui.Gui, v *gocui.View) error {
    return gocui.ErrQuit
}
rgl commented 6 years ago

Oh, sorry about this... just found https://github.com/jroimartin/gocui/blob/master/_examples/size.go which shed the light on my problem :-)