Skip to content

infinityabundance/ncurses-native

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ncurses-native

ncurses-native animating colour, SGR attributes, a progress bar and cursor-positioned text — byte-for-byte the same escape stream as ncurses

Live render of the published crate (the static frame is assets/ncurses-native.png).

A clean-room, dependency-free Rust reproduction of the observable terminal byte output of ncurses 6.4. The output engines are terminfo-driven and verified byte-for-byte against real ncurses across the entire compiled terminfo database — 2,563 terminal types, not just xterm. Reverse-engineered from captured behaviour, not ported from ncurses C source — there is zero ncurses C source in this repo.

#![forbid(unsafe_code)], std-only, no dependencies, ASCII-only source.

Byte-parity (verified across the whole terminfo database)

The output engines are measured byte-for-byte against real ncurses across the entire 2,563-entry compiled terminfo database (tools/db-coverage/sweep.py, run live — not a cached number):

engine byte-exact across the DB
cursor-movement optimizer (mvcur) 2559 / 2563 — 99.84%
doupdate (full screen update) 2549 / 2563 — 99.45%
incremental update 2536 / 2563 — 98.95%
colour (setaf/setab, toggled, bce) 2535 / 2563 — 98.91%
SGR attributes (sgr/mode-caps) 2345 / 2563 — 91.49%

The infocmp decompiler and tic compiler are 100.000% byte-exact across the full database (both -1 and -1 -x). A real curses C program (initscr/init_pair/ mvaddstr/attron/windows/pads/panel/menu/form/getch) linked against the native C-ABI (crates/ncurses-cabi, libncurses_cabi.{so,a}) draws byte-identically to the system libncursesw, and the cdylib is a working libtinfo.so.6 drop-in.

The remaining tails are understood and bounded (the SGR tail is dominated by the obsolete magic-cookie xmc terminals); see docs/capabilities.md.

Use it

[dependencies]
ncurses-native = "0.1"
use ncurses_native::{mvcur, sgr_on, sgr_off, Attr};

// The cursor-movement optimizer picks the cheapest escape sequence, like ncurses.
let bytes = mvcur((0, 0), (5, 10));            // -> b"\x1b[5;10H"
std::io::Write::write_all(&mut std::io::stdout(), &bytes).unwrap();

// SGR attributes:
print!("{}bold{}", String::from_utf8_lossy(&sgr_on(Attr::Bold)),
                    String::from_utf8_lossy(&sgr_off()));

Higher-level surfaces are available too: Window (cells/attrs/geometry), Screen (doupdate-style updates), Terminfo (tigetstr/tparm/tputs/tgoto), colour and key decoding. The macro-style C API maps to methods (getyxwin.getyx()).

Scope and bounds (honest non-claims)

This is a seed grown toward parity, not a finished library, and not a replacement for ncurses:

  • The terminfo-driven engines (cursor optimizer, doupdate, colour, attributes) and the infocmp/tic tools are verified against the admitted ncurses 6.4 oracle across the whole 2,563-entry terminfo database — thousands of terminal types — at the percentages in the table above (tools/db-coverage/sweep.py, re-runnable). The remaining few-percent tails are enumerated per-terminal, not hidden.
  • The one xterm-specific piece is the live-pty composite framing capture (initscrendwin whole-stream), pinned to TERM=xterm, 80×24, C.UTF-8 — proven by the receipts under reports/oracle/. Other ncurses builds are a non-claim.
  • It reproduces terminal output; functions with no terminal-output contract (interactive input reads, pure queries, global state) are classified, not byte-claimed.
  • Wide-char/double-width breadth is in progress.

Documentation

License

Apache-2.0. See LICENSE.

About

Clean-room, dependency-free Rust reproduction of ncurses terminal output (cursor optimizer, SGR, color, screen framing) for xterm/ncurses 6.4. A byte-exact seed toward native-Rust curses output parity.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors