writting program in its own "window"

is there a way to write a C++ program that doesn't do "clear screen" but actually has its own "window" just like vi or nano?



  • I think what you might be referring to is covered in GTK programming. This will allow you to build programs that have their own windows on the desktop instead of running in a terminal window.

    Take Care,
  • Thanks for reply, but no that's not what I'm asking. I don't even have X Windows based linux... i'm only working in command line.
  • I believe you are referring to a feature of the terminal where a program can use a "alternate" terminal screen for its output and then reset the terminal to the "main" screen when it exits. To do that your program would have to output the character sequences that tell the terminal to do the window switching.

    I wrote this test program and it works in my environment where TERM=xterm:


    int main(int argc, char *argv[])
    // switch the terminal to its alternate screen
    std::cout << "33[?1049h";

    for(int i = 0; i < 15; ++i)
    std::cout << i + 1 << ": line of text" << std::endl;


    // switch the terminal back to its main screen
    std::cout << "33[?1049l";

    return 0;

    This program should switch to the alternate screen, output some (useless) lines of text and then switch the terminal back to its main screen just before exiting. This may or may not work in your environment but give it a try. If it works you can use the same technique in your own program.

  • hey, thank you for replying!
    can you please explain what these magic numbers(characters) are ?
  • Those strings are control sequences that the terminal can recognize. I'm not very familiar with these terminal sequences but when I saw your question I had a feeling it was terminal related. For more info see what you can glean from this:

    [link=http://rtfm.etla.org/xterm/ctlseq.html]rtfm / Xterm / Escape Sequences[/link]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!