gui-cs / Terminal.Gui

Cross Platform Terminal UI toolkit for .NET
MIT License
9.7k stars 690 forks source link

Terminal.GUI plugin display as black #3819

Open karqical2016 opened 1 day ago

karqical2016 commented 1 day ago

Using C# WinForms Programming:

Create a program named test.exe using the Terminal.GUI plugin. In a WinForms application, create a TerminalControl using Rebex.TerminalEmulation.TerminalControl, then use Rebex.Net.Ssh to establish an SSH connection and bind it to the TerminalControl. Input mono test.exe in this TerminalControl to execute test.exe. The current issue is that after executing mono test.exe, although the test.exe program using the Terminal.GUI plugin runs, its UI is not visible and appears as a black screen. How to address the problem of the interface being displayed as black?

public static void LoadRebexSSH(Rebex.TerminalEmulation.TerminalControl terminalControl) { Rebex.Licensing.Key = LinuxUtil.RebexKey;

 // unbind the client object from the terminal console
 terminalControl.Unbind();

 //terminalControl.ForeColor = Color.White; 
 //terminalControl.BackColor = Color.Black;
 // clear the screen
 terminalControl.Screen.Clear();

 // create a new Ssh client object
 var _ssh = new Rebex.Net.Ssh();
 _ssh.Encoding = Rebex.EncodingTools.UTF8;
 // connect to the SSH server
 _ssh.Connect(SqLiteUtil.LinuxSetting.Host, int.Parse(SqLiteUtil.LinuxSetting.Port));
 // login to the SSH server
 _ssh.Login(SqLiteUtil.LinuxSetting.Sa, SqLiteUtil.LinuxSetting.Passwd);

 //set utf8 
 terminalControl.Options.Encoding = Rebex.EncodingTools.UTF8;
 terminalControl.Options.FunctionKeysMode = FunctionKeysMode.Linux;
 // 1.changes the default selection mode to block mode
 // terminalControl.SelectionMode = TextSelectionMode.Block;
 // 2.specifies whether the right mouse button pastes text from clipboard
 // terminalControl.MousePasteEnabled = true;
 // 3.specifies whether selection a text using a mouse automatically copies the selected text into clipboard
 terminalControl.MouseSelectionCopiesToClipboard = true;
 //set font
 terminalControl.AutoAdjustTerminalSize = true;
 terminalControl.Palette = TerminalPalette.Dos;

 //terminalControl.TerminalFont = TerminalFont.FromDosFont(fontByte);
 terminalControl.TerminalFont = new Rebex.TerminalEmulation.TerminalFont(FontUtil.LoadFontFamily(), 12.00f);
 //terminalControl.TerminalFont = new Rebex.TerminalEmulation.TerminalFont("Consolas", 12.00f);
 Size cellSize = terminalControl.CellSize;
 // bind the connected and authenticated Ssh instance to the terminal console

 terminalControl.Bind(_ssh);
 terminalControl.Screen.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} Session connected.");
 RebexSSHDisconnected = true;

} image

tznind commented 1 day ago

You are running your terminal app test.exe but using mono to launch it i.e. the program for running windows programs on linux? Why do you not simply compile for linux directly?

dotnet publish --self-contained -r linux-x64

Also one thing to try is to switch to NetDriver?

Application.UseSystemConsole = true;

If this is running with the curses driver, then you may need to specify TERM environment variable in the environment that the exe is running e.g. setting it to 'xterm' .

Are you targetting version 1 or version 2 of Terminal.Gui