I'm working on making an ASCII based game, and everywhere I look people are saying to use Console.Write() from MSDN, which is dandy and all if you're using Windows, but I'm not.
And thus, I'm trying to write a function, or group of functions in C that can alternate between two screen buffers, and write them to the screen, similar to what man pages would be like, as well as pico, vim, and emacs.
I have the buffer's working, and found an old ASCII game for linux called 0verkill that uses C and putchar() to place each character on the screen, but all of my attempts to re-create that, result in a continuous flow of text, and not a window sized panel of static text. I really don't want to use any external libraries like curses (because that would reduce portability) and would like to keep to ansi standards if at all possible.
Thanks!
What? Libraries like curses and ncurses are designed to make this kind of thing more portable, because...
...there is no ANSI standard (for C at least) for what you want. Each operating system implements this kind of behavior differently, so if you want a portable way to do it, you need to use a library. Honestly, I'd hate to have to develop for a system that didn't have ncurses ported to it. Imagine all the programs you wouldn't be able to use without it.
An example header and source file illustrating a way to abstract curses from the application. Gathering dust; wrote it over 15 years ago. Caveat emptor.
cursemu.h
cursemu.c
Compiling
Requires:
I think what you are looking for is the ANSI control character
ESC[2J
which clears the screen. You would call that after any change of state to "refresh" the console screen.See this page to learn about the rest of them. Using these codes you can define colors and formatting (spacing, alignment, indenting etc) on the console.
There is an ANSI standard X3.64, also ISO/IEC 6429 which describes the DEC VT100 terminal. The standard describes certain escape sequences for color and cursor positioning that a compliant terminal-emulator will recognize, which will be basically all X terminals, but on Windows not necessarily (possibly you need the user to load ansi.sys). It is this last ugly inconsistency that illustrates why you should be using ncurses which abstracts away such detail.