Is it possible to "force" xterm-256color ? #3898
Unanswered
lzanoni-stm
asked this question in
Q&A
Replies: 1 comment
-
I think you can use PInvoke to set the env var e.g. It seems to work when I tested on WSL but also setting TERM to blank did bad things to WSL itself 😆 We must use interop because PInvoke can be seen as risky but this is an incredibly standard method in core library - and the curses driver itself is chock full of lib invoke stuff so this would just be tip of iceberg I would say. using System;
using System.Runtime.InteropServices;
using Terminal.Gui;
class Program
{
// Import setenv from libc
[DllImport("libc", EntryPoint = "setenv", SetLastError = true, CharSet = CharSet.Ansi)]
private static extern int SetEnv(string name, string value, int overwrite);
static void Main()
{
// Check if we're running on Linux
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
string termVariable = "TERM";
// Check if TERM is blank or unset
string currentTermValue = Environment.GetEnvironmentVariable(termVariable);
if (string.IsNullOrEmpty(currentTermValue))
{
string termValue = "xterm-256color"; // Default TERM value
// Set TERM environment variable
int result = SetEnv(termVariable, termValue, 1); // 1 = overwrite existing
if (result != 0)
{
Console.WriteLine($"Failed to set {termVariable} environment variable.");
return;
}
Console.WriteLine($"Set {termVariable} to {termValue}.");
}
else
{
Console.WriteLine($"{termVariable} is already set to {currentTermValue}.");
}
}
// Press a key so you get a chance to read what above step said
Console.ReadKey();
// Initialize Terminal.Gui
Application.Init();
var top = Application.Top;
// Create a simple UI
var win = new Window("Hello Terminal.Gui")
{
X = 0,
Y = 0,
Width = Dim.Fill(),
Height = Dim.Fill()
};
top.Add(win);
var label = new Label("This is a Terminal.Gui application with TERM environment variable checked!")
{
X = Pos.Center(),
Y = Pos.Center()
};
win.Add(label);
Application.Run();
Application.Shutdown();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
I'm deploying a self-contained single-file app using v1 on various Linux.
In some cases, the TERM variable says xterm, linux or screen although the underlying terminal supports xterm-256color.
I'm looking for a way to 'force' Curses to run as if xterm-256color, without requiring the user to specify TERM=xterm-256 before lauching my app.
Any suggestion ?
I'd like to avoid using a launcher script for that.
Beta Was this translation helpful? Give feedback.
All reactions