I'm trying to find a way to have a simple console program run with a scrolling output section and then a single static input line at the bottom. I'm not sure how it's done. I was thinking it was probably not iostream or stdio, but I'm not that familiar with either, really.
The easiest way would probably be to use the ncurses library, if there is a windows version (I assume there is).
Here's a little sample program:
#include <ncurses.h>
#include <string.h>
WINDOW* output_window;
WINDOW* input_window;
WINDOW* create_window(int height, int width, int x, int y)
{
WINDOW* w = newwin(height, width, y, x);
box(w, 0, 0);
// now actually create a new window that is one character smaller around
// the edges than the other window
wrefresh(w);
w = newwin(height - 2, width -2, y + 1, x + 1);
return w;
}
void destroy_window(WINDOW* w)
{
// erase the bounding box
wborder(w, ' ', ' ', ' ',' ',' ',' ',' ',' ');
wrefresh(w);
delwin(w);
}
#define BUFFER_SIZE 512
char buffer[BUFFER_SIZE];
int main(int argc, char* argv[])
{
initscr();
output_window = create_window(LINES - 3, COLS, 0, 0);
input_window = create_window(3, COLS ,0 , LINES - 3);
wrefresh(input_window);
wrefresh(output_window);
while(true)
{
mvwgetnstr(input_window, 0, 0, buffer, BUFFER_SIZE);
// you should actually just figure out how many characters to print,
// but i'm lazy..,this mostly clears the input box.
wprintw(input_window, " ");
if (!strcmp(buffer, "/quit"))
break;
wprintw(output_window, "%s\n", buffer);
wrefresh(output_window);
wrefresh(input_window);
}
endwin();
return 0;
}
And the appearance would be:
(http://ucsu.colorado.edu/~ledbettj/curses-3.png)
ncurses is pretty powerful. If it seems like overkill or won't do for some reason, you could probably accomplish what you want with the Windows console functions (http://msdn2.microsoft.com/en-us/library/ms682073.aspx).
No.
ncurses is a pain to install, but I'll try it.
If you're using Win32, you might check out the console manipulation APIs like ReadConsoleOutput and ScrollConsoleScreenBuffer.
A problem I have is this
while(true)
{
output_stuff();
scanf("%s", in_buf);
}
Output only is displayed after the user enters something, but I want output to flow and do its own stuff regardless of whether the user is inputting anything or not.
That's good stuff. Hahahaha.
I didn't know you were smart. Behind all that trolling is a sense of humor and a decent ability to program. Incredible.
Quote from: Newby on May 15, 2007, 10:16 PM
That's good stuff. Hahahaha.
I didn't know you were smart. Behind all that trolling is a sense of humor and a decent ability to program. Incredible.
You know that I posted that first, right? ::)
Don't give him too much credit for being smart or clever.
Quote from: K on May 15, 2007, 10:42 PM
Quote from: Newby on May 15, 2007, 10:16 PM
That's good stuff. Hahahaha.
I didn't know you were smart. Behind all that trolling is a sense of humor and a decent ability to program. Incredible.
You know that I posted that first, right? ::)
Don't give him too much credit for being smart or clever.
I knew it was too good to be true.
Is there an edit or deleted post I missed?
Quote from: Banana fanna fo fanna on May 16, 2007, 03:55 PM
Is there an edit or deleted post I missed?
No. tumeria and Newby copied my post, so used internet voodoo to slightly modify the screenshots you can find in their posts :)
Quote from: K on May 16, 2007, 04:52 PM
No. tumeria and Newby copied my post, so used internet voodoo to slightly modify the screenshots you can find in their posts :)
Maybe there's something horridly wrong with my settings, but tumeria's post came first in this thread.
Quote
Maybe there's something horridly wrong with my settings, but tumeria's post came first in this thread.
He certainly did post first, but he edited his useless post to mirror mine.
Quote from: K on May 16, 2007, 07:13 PM
Quote
Maybe there's something horridly wrong with my settings, but tumeria's post came first in this thread.
He certainly did post first, but he edited his useless post to mirror mine.
Ahhhh. I didn't catch there. And here I thought you were just having fun. I'll edit mine now.
ohhhh ok
could you ban squeak's ip range plz
or C++
Hey, who wants to lock/split this thread?
No need, methinks. :)