AnsiConvertor - ANSI file convertor utility
Converts text files with ANSI escape sequences to different formats.
The screen-less VirtualTerminal class makes it easy to render the so-called ANSI files and then save it to a different format.
These formats are available:
- Plain text *
- ANSI file *
- HTML file *
- PNG image
- GIF image
- BMP image
- JPEG image
- TIFF image
This sample demonstrates:
- Using VirtualTerminal class.
- Writing a text with escape sequences to the virtual terminal.
- Saving the terminal screen in various formats.
- Resizing the terminal screen.
Sample files are included in the project.
C#
// create a new virtual (off-screen) terminal (80 columns, 50 rows) VirtualTerminal terminal = new VirtualTerminal(80, 50); // open the ANSI file for reading using (StreamReader reader = new StreamReader("ANSI_file.ans")) { // read the whole file to the string string data = reader.ReadToEnd(); // write the data to the terminal screen terminal.Screen.Write(data); } // save the terminal screen as PNG image terminal.Save("converted_ANSI_file.png", TerminalCaptureFormat.Png);
VB.NET
' create a new virtual (off-screen) terminal (80 columns, 50 rows) Dim terminal As VirtualTerminal = New VirtualTerminal(80, 50) Dim reader As StreamReader = Nothing Try ' open the ANSI file for reading reader = New StreamReader("ANSI_file.ans") ' read the whole file to the string Dim data As String = reader.ReadToEnd() ' write the data to the terminal screen terminal.Screen.Write(data) Finally ' close the stream reader If Not reader Is Nothing Then reader.Close() End Try ' save the terminal screen as PNG image terminal.Save("converted_ANSI_file.png", TerminalCaptureFormat.Png)