question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linux Application.Top renders only after scaling terminal window

See original GitHub issue

Description I’m trying to run my application on Debian, but my Application.Top renders only after i resize my terminal window. This works just fine on Windows. I can write to the terminal with System.Console just fine on Debian before attempting to call Application.Run(). But unlike on Windows, where the Application.Top is rendered immediately after Application.Run() is called, The terminal window stays blank on Debian until the terminal window is resized.

Program entrypoint

    static void Main(string[] args)
    {
        Application.QuitKey = Key.Esc;
        Application.Init();
        _iWnd = new AppWindow("SubTopic",_padding);
        Application.Top.Resized += Top_Resized;
        Application.Top.Add(_iWnd._top);
        Application.Run(Application.Top);
        Application.Shutdown();
    }

The class AppWindow is called just to add padding to the window drawn using a struct. AppWindow class constructor:

        public AppWindow(string title,Padding _pad) {
            Colors.Base.Normal = Application.Driver.MakeAttribute(Color.White, Color.Black);
            _padding = _pad;

            _top = new Toplevel()
            {
                X = 0,
                Y = 0,
                Width = Dim.Fill(),
                Height = Dim.Fill(),
            };

            _window = new Window()
            {
                LayoutStyle = LayoutStyle.Absolute,
                CanFocus = false,
                ColorScheme = Colors.Base,
                Title = title,
                X = _pad.Left,
                Y = _pad.Top,
                Width = Dim.Fill(_pad.Right),
                Height = Dim.Fill(_pad.Bottom),
            };
            //Resize();
            _top.Add(_window);
            _window.Add(_labels);
            Resize();
        }

And the class also includes a function to add labels to the window according to the display size when initialized:

        public void Resize()
        {
            int winHeight;
            _window.GetCurrentHeight(out winHeight);
            if (winHeight == 0) return;
            _labels = new Label[winHeight-1];
            Debug.WriteLine($"  Labels:{_labels.Length}");
            for (int y = 1; y < _labels.Length; y += 4)
            {
                _labels[y] = new Label("┤"+y) { ColorScheme = Colors.Base, X = _padding.Left, Y = y + _padding.Top, };
            }
            _top.Clear();
            _top.Add(_labels);
        }

The Resize mehod is called whenever Application.Top.Resized is invoked.

The same issue persists even with a minimal Window application setup.

Build info Target Framework: .NET7.0 Deployment mode: Self-contained Target Runtime: Linux-x86

Target OS/Shell info OS: Debian GNU/Linux 11 (WSL2) Codename: Bullseye Shell: Tested on : Bash, ZSH, TMUX

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
BDispcommented, Jun 14, 2023

@JesFo , I was playing with this and the problem isn’t TMUX, but with some others Linux terminal. You have to use both events (Resize and Loaded). First of all I have to write this command (export TERM=xterm-256color) on TMUX to have the colors. With the code bellow I could have it always working on load and resizing:

		static void Main(string[] args)
		{
			Application.QuitKey = Key.Esc;
			Application.Init ();
			_iWnd = new AppWindow ("SubTopic", _padding);
			Application.Top.Resized += Top_Resized;
			Application.Top.Loaded += Top_Loaded;
			Application.Top.Add (_iWnd._top);
			Application.Run (Application.Top);
			_iWnd.Dispose ();
			Application.Shutdown ();
		}
		
		private void Top_Loaded ()
		{
			_iWnd.Resize ();
		}

		private void Top_Resized (Size size)
		{
			_iWnd.Resize ();
		}

		public struct Padding {
			public int Left;
			public int Right;
			public int Top;
			public int Bottom;

			public Padding (int len)
			{
				Left = len;
				Right = len;
				Top = len;
				Bottom = len;
			}
		}

		public class AppWindow : Window {
			public Toplevel _top;
			private Window _window;
			private Label [] _labels;

			public AppWindow (string title, Padding _pad)
			{
				Colors.Base.Normal = Application.Driver.MakeAttribute (Color.White, Color.Black);
				_padding = _pad;

				_top = new Toplevel () {
					X = 0,
					Y = 0,
					Width = Dim.Fill (),
					Height = Dim.Fill (),
				};

				_window = new Window () {
					LayoutStyle = LayoutStyle.Absolute,
					CanFocus = false,
					ColorScheme = Colors.Base,
					Title = title,
					X = _pad.Left,
					Y = _pad.Top,
					Width = Dim.Fill (_pad.Right),
					Height = Dim.Fill (_pad.Bottom),
				};
				_top.Add (_window);
				Resize ();
			}

			public void Resize ()
			{
				int winHeight;
				_window.GetCurrentHeight (out winHeight);
				if (_labels != null) {
					foreach (var view in _labels) {
						_top.Remove (view);
						view?.Dispose ();
					}
				}
				if (winHeight == 0) return;
				_labels = new Label [(winHeight / 4) + (winHeight % 4)];
				Debug.WriteLine ($"  Labels:{_labels.Length}");
				int i = 0;
				for (int y = 1; y < winHeight; y += 4) {
					_labels [i] = new Label ("┤" + y) { ColorScheme = Colors.Base, X = _padding.Left, Y = y + _padding.Top, };
					if (y + 4 < winHeight) {
						i++;
					}
				}
				_top.Clear ();
				_top.Add (_labels);
			}
		}

tmux

0reactions
tigcommented, Jun 14, 2023

Closing as won’t fix: Use Loaded instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

x11 - How to scale the resolution/display of the desktop ...
The purpose is to keep the screen resolution unchanged (at max) while scaling the size (bigger/smaller) of the desktop/applications. x11 · gnu- ...
Read more >
HiDPI Screen + Monitor application scaling issues ...
It looks like we have to wait for better Linux support of HiDPI. Update. After about one week i gave up... Windows 10...
Read more >
Why is scaling still such an absolute train wreck on Linux?
Sometimes it renders the apps completely unusable, like with Kwrite. Mac OS and Windows handle it almost perfectly, with just a single ...
Read more >
A few HiDPI tricks for Linux
It not only will do fractional scaling but it will do display independent ... In my experience with Windows 10, it depends on...
Read more >
Steam, Linux, how to scale UI on large (2K, 4K) displays
You can do this manually, in a terminal window, until you get the right kind of scaling, and then you can make the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found