Check char at current/given position in PDCurses/NCurses
The inch family of functions should do that:
chtype inch(void);
chtype winch(WINDOW *win);
chtype mvinch(int y, int x);
chtype mvwinch(WINDOW *win, int y, int x);
Reading changes from screen
Curses keeps an internal map of the window, you can interrogate it with:
chtype inch(void);
chtype winch(WINDOW *win);
chtype mvinch(int y, int x);
chtype mvwinch(WINDOW *win, int y, int x);
You'll have to read each position in the window.
The chtype
contains the character and flags for effects like bold etc
How to implement a scroll or list box in NCurses/PdCurses? ( C )
scrollok
doesn't magically create a scroll box, it just allows the window to be scrolled up. You do not even need scrollok
for your purpose. Just
- maintain an index i to the topmost name which is to be displayed (initially 0)
- print height h names from index i to min(i+h-1, imax) to the window, starting at the topmost line
- when user presses "N", if i+h ≤ imax then set i to i+h, clear window box, go to print
- when user presses "P", if i > 0 then set i to i-h, clear window box, go to print
How to implement a scroll or list box in NCurses/PdCurses? ( C )
scrollok
doesn't magically create a scroll box, it just allows the window to be scrolled up. You do not even need scrollok
for your purpose. Just
- maintain an index i to the topmost name which is to be displayed (initially 0)
- print height h names from index i to min(i+h-1, imax) to the window, starting at the topmost line
- when user presses "N", if i+h ≤ imax then set i to i+h, clear window box, go to print
- when user presses "P", if i > 0 then set i to i-h, clear window box, go to print
printw() won't print a single character from a uint8_t array
You need to get rid of the carriage return (CR) characters (\r
).
When you output a CR, ncurses resets the cursor to the first column in the same row. Then when you output a NL (\n
), ncurses erases from the cursor position to the end of the row before advancing the cursor to the next row. That effectively deletes the entire row that was just printed.
This behaviour is documented, for what it's worth. From man waddch
(emphasis added):
If
ch
is a tab, newline, or backspace, the cursor is moved appropriately within the window. Backspace moves the cursor one character left; at the left edge of a window it does nothing. Newline does aclrtoeol
, then moves the cursor to the window left margin on the next line, scrolling the window if on the last line. Tabs are considered to be at every eighth column. The tab interval may be altered by setting theTABSIZE
variable.
The response to a carriage return is documented in the ncurses waddch manpage, at the end of the PORTABILITY section:
If
ch
is a carriage return, the cursor is moved to the beginning of the current row of the window. This is true of other implementations, but is not documented.
(Thanks to Thomas Dickey for pointing to the PORTABILITY section.)
Related Topics
Receiving Only Necessary Data with C++ Socket
Error: Expression Must Have a Class Type
C/C++ Counting the Number of Decimals
Why Is the Data Type Needed in Pointer Declarations
String-Interning at Compiletime for Profiling
Passing Std::String by Value or Reference
C++11: Why Does Std::Condition_Variable Use Std::Unique_Lock
Two Colours Text in Qpushbutton
Benefits and Portability of Boost Library
"_Gfortran_Pow_C8_I4" Error When Linking .O Files from G++ and Gfortran Using G++
Auto Keyword Behavior with References
Mixing Ifstream Getline and >>
C++ Passing an Array Pointer as a Function Argument
Enum Class Constructor C++ , How to Pass Specific Value
Can't Use Structure in Global Scope