Skip to content

Seeking guidance: "Status" view not updating #122

Description

@psparago

If this is not the proper place for this question, my apologies (and sorry for the length of this post).

I am working on a shell UI that is legacy code (that I didn't author). It has been working for many years, but It was based on a hacked version of jroimartin/gocui and a hacked version of a widget package the author found (4 years ago, he just disappeared).

We recently moved all of our Go code to 1.18 (from 1.11) and, with that, we revised all our packages including moving our terminal GUI utility from the hacked jroimartin/gocui code to the latest release V1.1.0 of awesome-gocui (Thanks folks!).

The terminal UI app is a utility that has a main menu "page" that transfers to several "pages" of "forms". All of these "pages" are comprised of widgets from the still hacked widgets package (they seem to work OK).

Every "page" has a status view (not a widget) at the top of the page. For some reason, the status view no longer shows any text.

Relevant code:

"Pages" are represented by an unfortunately named "Window" struct. In the Layout function on the Window struct, two VIews are created: a View to hold the "form" widgets (gathered as children), and a View to show status messages:

func (w *Window) Layout(g *gocui.Gui) (err error) {

      // ... gather child widgets and create the "form" View (not shown)
      w.view, _ = g.SetView(w.name, w.x, w.y, w.x+w.width, w.y+totalHeight, 0)

	// Always creating a one line status view at the top of the screen
	_ = g.DeleteView("status")
	w.status, err = g.SetView("status", 2, 1, maxX-2, 2, 0)
	if err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		w.status.Frame = false
		w.status.Editable = false
	}

The status text is set using the SetStatus function on the "Window" struct :

func (w *Window) SetStatus(statusType int, text string) {
	if w.status != nil {
		w.gui.Update(func(g *gocui.Gui) error {
			switch statusType {
			case StatusAlert:
				w.status.BgColor = gocui.ColorRed
				w.status.FgColor = gocui.ColorBlack
			case StatusInformation:
				w.status.BgColor = gocui.ColorBlue
				w.status.FgColor = gocui.ColorWhite
			case StatusSuccess:
				w.status.BgColor = gocui.ColorGreen
				w.status.FgColor = gocui.ColorWhite
			}
			w.status.Clear()
			_, _ = fmt.Fprint(w.status, text)
			fmt.Printf(w.status.Buffer())
			return nil
		})
	}
}

Here's an example use from a test page I created:

var (
	mmWindow  *widgets.Window
	mmBtnTest widgets.WidgetInterface
)

func mainMenu(g *gocui.Gui) error {
	if mmWindow == nil {
		mmWindow = widgets.NewWindow(g, "mainMenu", 40)
		mmBtnTest = widgets.NewButtonWidget(g, mmWindow, "mmBtnTest", 0, 0, 0, "Test",
			func(g *gocui.Gui, v *gocui.View) error {
				mmWindow.SetStatus(widgets.StatusAlert, "Say Something!!!")
				return nil
			})
		mmBtnTest.SetPadding(1)
		mmWindow.AddWidget(&mmBtnTest)
	}
	_ = mmWindow.Layout(g)
	return nil
}

Note the call to SetStatus in the example code.

If you look closely at the SetStatus function you see that I am printing the View buffer to the screen after writing the status text to the buffer. The text "Say Something!!!" does indeed get printed to the screen when the Test "button" is pressed.

Any guidance would be greatly appreciated. Thank you.
gocui-test.tar.gz

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions