Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advanced Console IO in .NET

Tags:

.net

console

What is the best way to write data to the text console at arbitrary locations on the screen and with custom fore/background colors?

like image 202
Jimmy Avatar asked Oct 13 '08 22:10

Jimmy


People also ask

What is console application in .NET framework?

NET applications can use the System. Console class to read characters from and write characters to the console. Data from the console is read from the standard input stream, data to the console is written to the standard output stream, and error data to the console is written to the standard error output stream.

What is console type in C#?

In C#, the Console class is used to represent the standard input, output, and error streams for the console applications. You are not allowed to inherit Console class. This class is defined under System namespace. This class does not contain any constructor.


2 Answers

Console.SetCursorPosition, Console.BackgroundColor, Console.ForegroundColor, and Console.ResetColor.

Note these were added to the .NET Framework in version 2.0. Prior to that you would have needed PInvoke.

like image 97
C. Dragon 76 Avatar answered Oct 08 '22 00:10

C. Dragon 76


There are a couple of libraries that can be helpful when writing TUI based applications in C#:

  • Gui.cs is a Terminal UI toolkit for .NET by Miguel de Icaza. This is a simple UI toolkit for .NET, .NET Core and Mono and works on both Windows and Linux/Unix.
  • MonoCurses is an MIT-X11 licensed binding of curses, and it includes the minimalistic gui.cs GUI toolkit for creating console-based applications.
  • ConsoleGUI is a simple layout-driven library for creating console-based GUI applications. It provides most essential layout management utilities as well as a set of basic controls.
  • CursesSharp is a C# wrapper for curses library.
like image 33
Magnus Lindhe Avatar answered Oct 07 '22 22:10

Magnus Lindhe