在 ncurses 上重绘

发布于 2024-08-25 11:41:26 字数 531 浏览 4 评论 0原文

我正在尝试重绘一个简单循环的内容。到目前为止,它打印到 stdscr 100 行,然后使用 scrl 滚动 n 行,我得到 n 空白行。

我想要的是保持顺序。但是,我不确定如何用 n 条额外的行重新绘制 stdscr 。任何想法将不胜感激!

#include <ncurses.h>
int main(void)
{
    initscr();
    int maxy,maxx,y;
    getmaxyx(stdscr,maxy,maxx);
    scrollok(stdscr,TRUE);
    for(y=0;y<=100;y++)
        mvprintw(y,0,"This is some text written to line %d.",y);
    refresh();
    getch();
    scrl(5);
    refresh();
    getch();
    endwin();
    return(0);
}

I'm trying to redraw the content of a simple loop. So far it prints out to the stdscr 100 lines, and then by using scrl to scroll n lines I get n blank rows.

What I want is to keep with the sequence. However, I'm not sure how to redraw the stdscr with the n extra lines. Any ideas will be appreciate it!

#include <ncurses.h>
int main(void)
{
    initscr();
    int maxy,maxx,y;
    getmaxyx(stdscr,maxy,maxx);
    scrollok(stdscr,TRUE);
    for(y=0;y<=100;y++)
        mvprintw(y,0,"This is some text written to line %d.",y);
    refresh();
    getch();
    scrl(5);
    refresh();
    getch();
    endwin();
    return(0);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ら栖息 2024-09-01 11:41:26

据推测,在 scrl() 之后的 refresh() 之后,添加以下行:

for (y = 96; y <= 100; y++)
    mvprintw(y, 0, "This is some text written as line %d.", y+5);
refresh();

当然,我正在使用幻数。你应该使用类似的东西:

enum { MAX_SCR_LINE = 100 };
enum { MAX_SCROLL   =   5 };

那么循环是:

for (y = MAX_SCR_LINE - MAX_SCROLL + 1; y <= MAX_SCR_LINE; y++)
    mvprintw(y, 0, "This is some text written as line %d.", y + MAX_SCROLL);
refresh();

如果你需要一遍又一遍地重复这个过程,那么计算就变成:

enum { MAX_ITER = 10 };
for (int j = 0; j < MAX_ITER; j++)
{
    scrl(MAX_SCROLL);
    for (y = MAX_SCR_LINE - MAX_SCROLL + 1; y <= MAX_SCR_LINE; y++)
        mvprintw(y, 0, "This is the text written as line %d.",
                 y + (j + 1) * MAX_SCROLL);
 }

等等......

(代码未经测试 - 当心错误。)

Presumably, after the refresh() after scrl(), add the lines:

for (y = 96; y <= 100; y++)
    mvprintw(y, 0, "This is some text written as line %d.", y+5);
refresh();

I'm using magic numbers, of course. You should use something like:

enum { MAX_SCR_LINE = 100 };
enum { MAX_SCROLL   =   5 };

Then the loop is:

for (y = MAX_SCR_LINE - MAX_SCROLL + 1; y <= MAX_SCR_LINE; y++)
    mvprintw(y, 0, "This is some text written as line %d.", y + MAX_SCROLL);
refresh();

And if you need to repeat the process over, and over, then the calculation becomes:

enum { MAX_ITER = 10 };
for (int j = 0; j < MAX_ITER; j++)
{
    scrl(MAX_SCROLL);
    for (y = MAX_SCR_LINE - MAX_SCROLL + 1; y <= MAX_SCR_LINE; y++)
        mvprintw(y, 0, "This is the text written as line %d.",
                 y + (j + 1) * MAX_SCROLL);
 }

Etcetera...

(Code untested - beware bugs.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文