开发者

Window positioning in ncurses

I'm attempting to write a simple chat application in C using ncurses, both of which I am new to with a background in PHP. (Yes, I know. Thanks. I'll take that advice to heart. Please put down the guns.)

What I've attempted to do is create two windows, one for input and one for channel text, like so:

int termwidth = getmaxy(stdscr);
int termheight = getmaxx(stdscr);

WINDOW *channel = newwin(termwidth, termheight - 1, 0, 0);
scrollok(channel, TRUE);

WINDOW *input = newwin(termwidth, 1, termheight + 1, 0);
scrollok(input, TRUE);

and then set cursor position to input:

wmove(input, 0, 0);

in order to put typed input in the second window, which should occupy a single column at the bottom of the terminal, while output appears in the first window which fills the rest of the terminal's space.

Output appears to fill the top window (channel) properly, with the input cursor flashing in t开发者_Python百科he proper place, but changing its size does not yield predictable results and typed input doesn't appear to be going into the input window at all.

The complete source is available here: http://pastebin.com/X8apHUgh

To sum up, I am asking why input is behaving unexpectedly, and why drawing the "channel" window is yielding strange results.


Oh, [expletive/deleted]! I'm an imbecile. It turns out my problem was twofold:

  1. I had inadvertently mixed my X and Y assignments, and
  2. I had also reversed the width and height parameters in the functions.

This meant that positioning worked properly, until I made certain assumptions for basic positioning math.

I should add that this is partly because I was conceiving terminal positioning in terms of X/Y position, where rows/cols is the paradigm in place. They are only partly equivalent.

slow clap for self

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜