Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I save the buffer or contents of a console window for future use?

I am having fun with Console Applications and just wanted to know. What's the best way to save the current buffer of a console window for later use and provide a sort of history navigation function. I know the Diagnostics namespace provides ability to read standard output but that's only if you redirect it, so basically you will have to run process all your results in a new window which seems a little dumb.

like image 486
Chibueze Opata Avatar asked Sep 20 '11 16:09

Chibueze Opata


People also ask

What is console screen buffer?

A screen buffer is a two-dimensional array of character and color data for output in a console window. A console can have multiple screen buffers. The active screen buffer is the one that is displayed on the screen. The system creates a screen buffer whenever it creates a new console.

What is screen buffer size?

The size of a screen buffer is expressed in terms of a coordinate grid based on character cells. The width is the number of character cells in each row, and the height is the number of rows.


1 Answers

You need to read the console screen buffer.

I wrote a series of articles about accessing the Console API from .NET a few years ago. The article you're interested in is Working with Console Screen Buffers.

Full source code is available at http://mischel.com/pubs/consoledotnet/consoledotnet.zip.

like image 163
Jim Mischel Avatar answered Sep 22 '22 14:09

Jim Mischel