Question Terminal.Gui (Gui.cs) - previous window should disappear

benjm-ma

Member
Joined
Jun 2, 2020
Messages
14
Programming Experience
1-3
Hey guys,

Want to know if anyone has worked with this curses like TUI library. What I am trying to do is super basic but I haven't figured out how it's done using this library:
User is presented with a window with button elements. Once you click one of these buttons a new window should appear with a new interface. The previous window should disappear.
However I cannot figure out how to toggle the display of the origin window as the new window is simply drawn over the origin window. I've been reading through the API reference and looking
through examples but can't seem to figure it out.

Any help would be appreciated!
 

benjm-ma

Member
Joined
Jun 2, 2020
Messages
14
Programming Experience
1-3
Not sure what library you're referring to. A relevant link would be nice.
Github : migueldeicaza/gui.cs
Documentation : Namespace Terminal.Gui

I was reaching out to anyone who might have used the library. Nonetheless, I can whip up an actual coded example as well if you're interested in looking into this so you can see exactly what I am attempting to do. I really appreciate the help.
 

benjm-ma

Member
Joined
Jun 2, 2020
Messages
14
Programming Experience
1-3
This is the closest I have gotten to what I want by clearing the screen and calling the application main loop on a new window instance. However It doesn't seem like I have control as to what colour I clear the terminal with.

Here's the code:


C#:
using System;
using Terminal.Gui;
using System.Collections.Generic;

namespace example
{
  class Tui
  {
  
    // Collection of windows
      static Dictionary<string,Window> _windows =
          new Dictionary<string,Window>();

    static void Main ()
    {
        // Start Gui.cs
        Application.Init ();

        // Initialize Windows
        _windows.Add ("window_A", CreateWindow_A());
        _windows.Add ("window_B", CreateWindow_B());

        // Start main loop on window_A
        Application.Run (_windows["window_A"]);
    }


    static Window CreateWindow_A ()
    {
        // Create container
        var win = new Window ("Window A") {
            X = Pos.Center (),
            Y = Pos.Center (),
            Height = 40,
            Width  = 25
        };

        // Add components
        win.Add (
            new Button ("_Open Window B") {
                X = Pos.Center (),
                Y = Pos.Center (),
                Clicked = () => {
                    // "Close" window_A
                    Application.Top.Clear();
                    // "Open" window_B by running main loop on window
                    Application.Run (_windows["window_B"]);
                }
            },
            new Button ("_Quit") {
                X = Pos.Center (),
                Y = Pos.Center () + 1,
                Clicked = () => {
                    // This doesn't actually exit the program.
                    Application.RequestStop ();
                }
            }
        );

        return win;
    }

    static Window CreateWindow_B ()
    {
        // Create container
        var win = new Window ("Window B") {
            X = Pos.Center (),
            Y = Pos.Center (),
            Height = 25,
            Width  = 40
        };

        // Add components
        win.Add (
            new Button ("_Back to Window A") {
                X = Pos.Center (),
                Y = Pos.Center (),
                Clicked = () => {
                    // "Close" window_B
                    Application.Top.Clear();
                    // "Open" window_A by running main loop on window
                    Application.Run (_windows["window_A"]);
                }
            }
        );

        return win;
    }
  }
}

Note that if you wish to build and run this, there is not way of exiting the program from within the program.
 
Last edited:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,698
Location
Chesapeake, VA
Programming Experience
10+
I'm just speed reading through the documentation's overview and seems to me, you are actually looking for a Dialog not a Window.

 

benjm-ma

Member
Joined
Jun 2, 2020
Messages
14
Programming Experience
1-3
I'm just speed reading through the documentation's overview and seems to me, you are actually looking for a Dialog not a Window.


Well this was my impression as well. However the containers I am thinking behave modally, but have components and functionality you might find in a window. To be honest, perhaps the container I am thinking may not be something that is directly offered.
Nonetheless I may just be able to get away with using a dialogue as opposed to a window as it behaves more or less how I would like it to. But I'll have to spend more time sifting through the documentation.
 
Top Bottom