Re: switching from vga to interactive text mode without exiting

Search this archive.

From: Russell Marks (russell.marks@ntlworld.com)
Date: Fri 21 Sep 2001 - 16:53:08 IDT


Jason <jason@jnj.org> wrote:

> I have an svgalib app and I'd like, based on user input, to switch back
> to text mode do some printf's and fgets's with input from the user.
> 
> so I'm doing, basically:
> 
> /* working in a vga mode to this point */
> char tmp[256];
[...]
> scanf("%s", tmp);

I hope this is purely an example, but if not (and even if so,
frankly), you should be doing something more like:

fgets(tmp,sizeof(tmp),stdin);

> If this sounds stupid, it's a simplification.  What I really need is for
> my svgalib app to run another svgalib app, wait for it to exit, and then
> resume operations.  the second app may need user input.  Trying this has the
> same result as the above.

svgalib has a get-a-key function vga_getch() which doesn't need the
keyboard_* stuff (it predates that). It blocks, but gets chars one by
one without needing EOL. This suggests that, among other things,
svgalib puts the tty in cbreak mode (by disabling ICANON), and that
you'd need to restore the previous settings to get `normal' behaviour.

I don't think svgalib itself provides a mechanism for doing this, so
you'd probably have to play games with termios. So first, you'd save
the pre-svgalib settings (all untested):

#include <termios.h>
#include <unistd.h>

static struct termios orig;

int main(void)
{
/* before anything else, save initial tty setup */
tcgetattr(0,&orig);

vga_init();
/* etc. */
}

Then, around the bit which runs the program, you need to juggle the
settings:

void run_prog(/* whatever */)
{
struct termios svga;

tcgetattr(0,&svga);
tcsetattr(0,TCSAFLUSH,&orig);

/* your stuff to run the program here */

tcsetattr(0,TCSAFLUSH,&svga);
}

(There's no need to restore settings on exit from your program, of
course, because svgalib deals with that itself.)

Then again, I'm not sure the above would explain why a purely svgalib
program being run would have problems. Though it might explain why the
calling program would after running the other one. Anyway, try it and
see what happens. :-)

-Rus.


------------------------------------------------------------------
Unsubscribe:  To:   listbot@svgalib.org
              Body: unsubscribe linux-svgalib


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:24 IST