diff options
author | matthieu <matthieu.cneude@gmail.com> | 2021-03-13 20:46:55 +0100 |
---|---|---|
committer | matthieu <matthieu.cneude@gmail.com> | 2021-03-13 20:46:55 +0100 |
commit | dec71b0ea9718713c31419a20a665634c16eeb2b (patch) | |
tree | 693544b45606a9aa91e6c8b29f43f8942ee8ba61 | |
parent | 77c6e683647b6a553d8e805b384c9790e312efad (diff) |
Finally resizing terminal work as expected
-rw-r--r-- | cmd/root.go | 10 | ||||
-rw-r--r-- | internal/platform/termui.go | 24 |
2 files changed, 15 insertions, 19 deletions
diff --git a/cmd/root.go b/cmd/root.go index d8713b4..9a4dde5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,5 +1,7 @@ package cmd +// TODO see gocket to make the command right (with possibility to use env variables) + import ( "fmt" "log" @@ -81,14 +83,6 @@ func run(args []string) { } }() - align := time.NewTicker(time.Duration(3) * time.Second) - go func() { - for range align.C { - tui.Align() - tui.Render() - } - }() - tui.Loop() } diff --git a/internal/platform/termui.go b/internal/platform/termui.go index 00618ac..6fba783 100644 --- a/internal/platform/termui.go +++ b/internal/platform/termui.go @@ -20,17 +20,17 @@ func NewTermUI(d bool) (*termUI, error) { return nil, err } - termUI := &termUI{ + termUI := termUI{ row: []*termui.Row{}, } - termUI.Clean() - return termUI, nil -} + termui.Handle("/sys/wnd/resize", func(e termui.Event) { + termUI.Align() + termUI.Render() + }) + termUI.Clean() -// Close termui. -func (termUI) Close() { - termui.Close() + return &termUI, nil } // AddCol to the termui grid system. @@ -233,6 +233,7 @@ func (t *termUI) Loop() { // Render termui and delete the instance of the widgets rendered. func (t *termUI) Render() { termui.Render(t.body) + // delete every widget for the rows / cols rendered. t.removeWidgets() } @@ -251,11 +252,12 @@ func (t *termUI) Clean() { t.body.Width = termui.TermWidth() } +// Close termui. +func (termUI) Close() { + termui.Close() +} + func (t *termUI) HotReload() { - // termui.Close() - // Re-initializes event poll... which double them each time - // TODO no visual clue that the reload happened - // _ = termui.Init() t.Clean() termui.Clear() } |