NCurses initialization without clearing the screen

前端 未结 5 651
名媛妹妹
名媛妹妹 2021-01-17 20:29

I am writing a program that\'s similar to a shell. Once started up, there\'s a prompt and you enter in some app-specific commands.

So far this works just fine. How

相关标签:
5条回答
  • 2021-01-17 20:35

    Curses wants to fully control the screen, and to optimize writes to the screen, especially over slow serial lines. To do this, it needs to know what is on the screen, and the only reasonable way to do that with most terminals is to start from an empty screen and keep track of what you write to the terminal.

    Thus, I suspect (n)curses is the wrong tool for your shell. You probably need to go down a step on the abstraction layer and use terminfo and non-blocking reads from the terminal (standard input) instead.

    (This is not very helpful. Sorry.)

    0 讨论(0)
  • 2021-01-17 20:36

    Here is another discussion about this. The provided solutions are:

    1. "The 'filter()' function lets you use curses as a single-line."
    2. "You can write something equivalent in C, using setupterm to get the terminal data, and tparm, tputs for formatting and output."

    Of course there is the third option to get the ncurses source code and modify it so it doesn't clear the screen anymore.

    0 讨论(0)
  • You could just call your program from whithin rlwrap and have the functionality without the pain...

    0 讨论(0)
  • 2021-01-17 20:45

    Have you considered the simple expedient of creating a custom terminfo or termcap entry lacking a sequence to clear the screen and then switching your terminal setting to that right before running your program? You could also just use newterm() and set_term() in ncurses. This used to be easier with termcap, since you could include another terminal and override some of its capabilities.

    0 讨论(0)
  • 2021-01-17 20:49

    It might be simpler to use an interface like readline() rather than resorting to full-blown ncurses.

    0 讨论(0)
提交回复
热议问题