How do I clear the first two lines of the screen by using the curses library?

StackOverflow https://stackoverflow.com/questions/16809304

  •  30-05-2022
  •  | 
  •  

質問

How do I clear the first two lines of the screen by using the curses library? I see that there is a deleteln() command, however it only clears the line under the cursor.

Also, a second question, does the command clear() clear the whole screen?

役に立ちましたか?

解決

deleteln() deletes the line and moves the rest of the text up. clrtoeol() clears to the end of the current line.

You need to use int move(int y, int x) to position the cursor at the start of each of the 2 top lines and then call clrtoeol().

clear() clears the whole window

他のヒント

parkydr Said: "clrtoeol() clears to the end of the current line."

That's almost correct. clrtoeol() clears to the end of the current line from you cursor. So if your cursor isn't at the beginning of the line then it won't clear the entire line.

Here is an example:

int y, x;            // to store where you are
getyx(stdscr, y, x); // save current pos
move(0, 0);          // go to the beginning of the first line
clrtoeol();          // clear the line
move(1, 0);          // go to the beginning of the second line
clrtoeol();          // clear the line
move(y, x);          // move back to where you were
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top