Modern, thread-safe terminal UI support for Qore 2.3 using the system ncurses library.
This module is a complete redesign with a clean, high-level API. It is not backward-compatible with the legacy module.
- Qore 2.3 (development branch)
- ncurses (with panel support)
- CMake 3.21+ (Alpine CI uses CMake 4)
mkdir -p build
cd build
cmake ..
make%modern
%requires ncurses
Ncurses::Session s();
Ncurses::Window w = s.screen();
w.clear();
w.drawText(1, 2, "Hello, Ncurses!", {fg: Ncurses::Color::Cyan, attrs: Ncurses::Attr::Bold});
w.refresh();
w.readEvent();
s.close();
If you need ncurses I/O on a dedicated TTY (for example to capture stdout while still using ncurses),
create the session with use_tty: True. When use_tty is enabled, stdout/stderr are set to unbuffered
by default to keep output capture responsive; this can be disabled with unbuffered_stdio: False.
To avoid overwriting borders, use the clipped drawing helpers:
w.drawTextClipped(1, -2, "Hello"); # clipped to window bounds
w.drawTextInside(0, 0, "Title"); # clipped to inner area of a boxed window
w.drawTextInsideLine(1, "Value"); # clears the line, then draws
For low-flicker updates, use queued refreshes and a single flush:
w.noutrefresh();
s.updatePanels();
s.doupdate();
To keep the cursor in a specific window while updating others:
info.setLeaveOk(True);
You can also save and restore cursor positions around updates:
hash pos = input.saveCursor();
info.drawTextInsideLine(0, "Time: 12:00");
input.restoreCursor(pos);
The module installs a full-screen REPL frontend backed by the QoreRepl module:
qreplThe output pane supports mouse wheel scrolling and keyboard paging (click the output pane, then use the wheel, arrow keys, PgUp/PgDn, Home/End).
The NcursesUi helper module provides reusable widgets for pop-up menus and browsers:
%requires NcursesUi
NcursesUi::PanelWidget popup();
NcursesUi::MenuBarWidget menu();
These widgets are used by qrepl to provide mouse-driven menus, a reflection browser, and a filesystem browser.
Mouse input is supported via Window::readEvent() when Session is created with
mouse: True (default). Mouse events are reported as input events with
type == Ncurses::InputType::Mouse and include a mouse hash with coordinates
and button state.
All ncurses calls are serialized with a module-level recursive lock. Input calls release the lock between polling cycles to allow concurrent rendering from other threads.
Doxygen documentation is generated from the QPP sources and docs/mainpage.dox.tmpl.
MIT.