Console Checker
Checking to see if you're working on the right console...
Sometimes, your console application might need some of the additional features, such as VT color sequences, that might not be available to all of the terminal emulators installed on your system. In this case, Terminaux provides you with a group of console checkers to ease the process of checking the features.
Checking
There are various checkers you'll be able to use with Terminaux:
Dumb console checker
Dumb consoles, in general, don't understand the concept of colors, positioning, erasing, and features other than writing to the console. However, some of them may be provided with basic color support and various other features that are simple.
The following steps are taken:
The dumb console checker checks to see if we can call the
CursorLeftproperty and theWindowWidthproperty inside the exception handler.If we can't, the console is dumb.
The checker moves on and checks for redirected output and/or error standard streams.
If redirection is done, the console is dumb.
The checker moves on and checks
isatty()on Linux.If the function doesn't return 1, the console is dumb.
If checks pass, the console is not considered as dumb. This means that Terminaux is able to use the color features and all the other features.
Use IsDumb to use this checker.
Usually, CursorLeft and WindowWidth properties throw an IOException if they can't query the terminal, but this happens when the console doesn't understand the concept of positioning, which happens on dumb consoles.
256 color support checker
This checker is a very simple checker, because it only queries the terminal type for a string containing -256col. Any terminal type that doesn't have this string is assumed to be not supporting 256-color feature, but that doesn't necessarily mean that the console doesn't support this feature, depending on your console application.
Use IsConsole256Colors() to use this checker.
Size requirement checker
The console size requirement checking has been recently added to the latest version of Terminaux. This assists your application in determining your minimum console size requirements, with the default being the standard 80x24 console size for historical reasons.
For console applications which require a specific console size, you can call the CheckConsoleSize() function. You can also make it check for sizes other than 80x24, such as 120x30, by passing the width and the height to the same function.
public static bool CheckConsoleSize(int minimumWidth = 80, int minimumHeight = 24) { }This function is found in the ConsoleChecker public class so that you can access this function easily.
Terminaux and terminal multiplexers
If you call this function, it first checks to see if there are edge cases regarding running such console application on terminal multiplexers.
TMUX: Terminaux queries the TMUX settings to get how many status lines are there, and subtracts the required height by the number of status lines.
GNU Screen: Terminaux subtracts the minimum height by one, since it doesn't use more than one line to print its status if enabled.
No multiplexer: Terminaux does nothing.
Once the terminal multiplexer check is done, it queries the current window width and the window height and compares them to the required width and height. If the requirement is not satisfied, the function returns false. Otherwise, it returns true as the requirements have been satisfied.
The CheckConsoleSizePrompt() function checks to see if the console size requirements have been satisfied. If the requirements aren't satisfied, the application tells you to resize your console window to have a better experience and to press ENTER when resized to the required size.
Last updated