Console Buffer access?

  • Thread starter Thread starter hector santos
  • Start date Start date
H

hector santos

Guest
I have written many CRT (Console, Text) ANSI/VT100 drivers and emulators over the years and now I am porting my logic to C#. Here is the basic issue and probably the last detail I need to resolve in order to finish this particular project.


Imagine a 80x25 (80 column, 25 rows) window box. The Consoles dimensions are:


Console.WindowTop : 0
Console.WindowLeft : 0
Console.WindowHeight: 25
Console.WindowWidth : 80
Console.BufferHeight: 25
Console.BufferWidth : 80


The issue is not having access to the Console "Screen Buffer" for direct access. With .Net, the only way to display anything on the screen is to use the Console.Write or WriteLine methods. In this case, you don't want to use WriteLine because it add a EOL terminator (carriage return, linefeed) and the cursor goes to the next line. We don't want that, so you use Console.Write(). The problem is the last cell at row 25 and column 80 (bottom, right). If you try to write to that cell, what happens is the window will scroll up one line.

This issue is the same with any language who use the its language "Write/Print" to display a character at the last cell. The window will scroll.

The solution is to use the language's Console API to access the screen buffer where each cells has both the character and the color attribute. Then you fill in that last cell position without any scrolling.

I don't see how to do this with C#. The only way to avoid this in C# is well, not write to the 80,25 cell location. Limit any writing to column 79 for example. Then it won's scroll.

Suggestions?

I was thinking of importing (interop) the Win32/64 Console API functions. But I was thinking there might be an screen access violation. Maybe not, so if there is a more elegant solution, I would appreciate the know how.

Thanks


Hector Santos, CTO Santronics Software, Inc. Santronics Software, Inc.

Continue reading...
 
Back
Top