Originally Posted by
MK27
Does it work?
I actually don't use ncurses that much, and usually via the perl API, so I keep getting object notation flashing in my mind. Using the return value of initscr() in getmaxyx() seems a little unorthodox to me, unless you are planning to call get_screen_height_and_width() BEFORE set_row_and_column_character(), since I would guess calling mvaddch() BEFORE initscr() will be a problem. And if that's all you are doing, you don't need to keep the return value of initscr(), so probably all this is fine.
Looking thru some old code you don't need to keep the initscr() return normally either, there is the predefined "stdscr":
Code:
getmaxyx(stdscr,maxy,maxx);
Again, I assume initscr() must be called first.
I still haven't found a nice indexed version of the C API beyond the man pages.
Ah, okay, thanks. So something like this then:
Code:
#include "stdlib.h" // for size_t
#if defined( WIN32 ) || defined( MSWIN )
#include "windows.h"
// zero-based indexing
void set_row_and_column_character( size_t row, size_t column, unsigned char character )
{
COORD
position;
position.X = column;
position.Y = row;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), position );
putchar( character );
}
// for resizeable screens, calculation should be done dynamically
void get_screen_height_and_width( size_t* height, size_t* width )
{
CONSOLE_SCREEN_BUFFER_INFO
info;
GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &info );
*width = info.srWindow.Right;
*height = info.srWindow.Bottom - info.srWindow.Top;
}
#elif defined( NCURSES )
#include "curses.h"
void initscr_helper_( void )
{
static WINDOW*
unused = initscr( );
}
void set_row_and_column_character( size_t row, size_t column, unsigned char character )
{
initscr_helper_( );
mvaddch( row, column, character );
}
void get_screen_height_and_width( size_t* height, size_t* width )
{
initscr_helper_( );
getmaxyx( stdscr, *height, *width );
}
#elif defined( NextPlatformNamePlaceHolder_ )
// platform implementation
#else
#error Console platform not specified
#endif