ncurses programming -- problems in Framebuffer mode?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
ncurses programming -- problems in Framebuffer mode?
I am writing a simple ncurses program in C and it displays perfectly in the X terminal (Konsole and xterm).
However, since I boot in the framebuffer mode (to display splash screen using splashy) the program doesn't display properly in the terminal mode. In particular it doesn't seem to calculate the correct screen parameters as returned by the getmaxyx() function.
Anybody else noticed this behaviour? Is this an ncurses limitation?
I thought Suse's "Yast2" was a pretty good example of an ncurses-based application ... and Yast2 works fine for me when the system is in text mode (init 3, framebuffer-only).
Could the problem lie in the particular framebuffer and/or particular ncurses implementation in your distro? Does the program exhibit the same problem when you try other distros?
Well, in the same laptop it doesn't work properly in pure text mode either, but in an X terminal it displays the border and the text in the correct location.
I have the same version of ncurses on the same distro (Debian) on my desktop. And that program worked fine in the pure terminal mode as well as in an X terminal on my desktop system.
Is there a problem with the pure text mode in laptops which cause this issue. Or is the code the problem? Here's the code:
Code:
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
/* Finishing up the ncurses proram */
static void finish (int sig)
{
endwin ();
exit (0);
}
/* Do some initializing for ncurses terminal mode */
void initialize ()
{
signal (SIGINT, finish);
initscr ();
cbreak ();
noecho ();
if (has_colors ())
{
start_color ();
init_pair (1, COLOR_WHITE, COLOR_BLACK);
init_pair (2, COLOR_WHITE, COLOR_BLUE);
bkgd (COLOR_PAIR(2));
}
}
/* Main program loop */
void main_loop ()
{
char* window_title = " poorty - not fortune ";
int x, y;
while (1)
{
getmaxyx (stdscr, y, x);
clear ();
box (stdscr, 0, 0);
mvaddstr (0, x/2 - strlen(window_title)/2, window_title);
refresh ();
int ch = getch ();
switch (ch)
{
case 'q':
case 'Q':
finish (0);
}
}
}
int main ()
{
// Initialize the curses terminal
initialize ();
// Main program loop
main_loop ();
// Clean up on terminate
finish (0);
}
In pure text mode, this program doesn't draw the border correct around the whole terminal and the text is displayed in the wrong location (not at the centre of the first line).
NOTE: the program is not yet complete. It's supposed to display a random quote.
Last edited by vharishankar; 12-12-2006 at 03:44 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.