diff --git a/rust/examples/direct-cursor.rs b/rust/examples/direct-cursor.rs index 49152f6a0..1394b5b5f 100644 --- a/rust/examples/direct-cursor.rs +++ b/rust/examples/direct-cursor.rs @@ -7,7 +7,7 @@ use libnotcurses_sys as nc; fn main() { unsafe { - let ncd = nc::ncdirect_start(); + let ncd = nc::ncdirect_new(); let cols = nc::ncdirect_dim_x(ncd); let rows = nc::ncdirect_dim_y(ncd); diff --git a/rust/examples/direct-image.rs b/rust/examples/direct-image.rs index b50ca7937..ea5da8e08 100644 --- a/rust/examples/direct-image.rs +++ b/rust/examples/direct-image.rs @@ -4,7 +4,7 @@ use libnotcurses_sys as nc; fn main() { unsafe { - let ncd = nc::ncdirect_start(); + let ncd = nc::ncdirect_new(); render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_1x1); render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_2x1); diff --git a/rust/examples/full-text.rs b/rust/examples/full-text.rs new file mode 100644 index 000000000..fee13c995 --- /dev/null +++ b/rust/examples/full-text.rs @@ -0,0 +1,7 @@ +//use cstr_core::CString; + +//use libnotcurses_sys as nc; + +fn main() { +} + diff --git a/rust/src/direct.rs b/rust/src/direct.rs index dad439cc0..1894efa9f 100644 --- a/rust/src/direct.rs +++ b/rust/src/direct.rs @@ -40,20 +40,31 @@ // ncdirect_vline_interp use crate as nc; -use nc::types::DirectMode; +use nc::types::{DirectMode, DirectModeFlags}; extern "C" { fn libc_stdout() -> *mut nc::_IO_FILE; } -/// A simple ncdirect_init() wrapper +/// A simple ncdirect_init() wrapper using the default options. /// /// Initialize a direct-mode notcurses context on the tty. /// /// Direct mode supports a limited subset of notcurses routines, /// and neither supports nor requires notcurses_render(). This can be /// used to add color and styling to text in the standard output paradigm. +/// /// Returns NULL on error, including any failure initializing terminfo. -pub unsafe fn ncdirect_start() -> *mut DirectMode { - nc::ncdirect_init(core::ptr::null(), libc_stdout(), 0) +pub unsafe fn ncdirect_new() -> *mut DirectMode { + ncdirect_with_flags(0) +} + +/// A simple ncdirect_init() wrapper with optional flags. +/// +/// `flags` is a bitmask over: +/// - NCDIRECT_OPTION_INHIBIT_CBREAK +/// - NCDIRECT_OPTION_INHIBIT_SETLOCALE +/// +pub unsafe fn ncdirect_with_flags(flags: DirectModeFlags) -> *mut DirectMode { + nc::ncdirect_init(core::ptr::null(), libc_stdout(), flags) } diff --git a/rust/src/types.rs b/rust/src/types.rs index 3f920db42..0ccd16c25 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -195,6 +195,7 @@ pub type EGCBackstop = u8; /// pub type StyleMask = u16; +/// Type alias of ncplane // Plane: fundamental drawing surface. unites a: // // - CellMatrix @@ -219,53 +220,86 @@ pub type Palette = nc::palette256; /// pub type IntResult = i32; -/// + +/// Type alias of ncalign_e pub type Align = nc::ncalign_e; pub const ALIGN_LEFT: Align = nc::ncalign_e_NCALIGN_LEFT; pub const ALIGN_RIGHT: Align = nc::ncalign_e_NCALIGN_RIGHT; pub const ALIGN_CENTER: Align = nc::ncalign_e_NCALIGN_CENTER; -/// + +/// Type alias of ncblitter_e pub type Blitter = nc::ncblitter_e; + /// space, compatible with ASCII pub const BLIT_1x1: Blitter = nc::ncblitter_e_NCBLIT_1x1; + /// halves + 1x1 (space) /// ▄▀ pub const BLIT_2x1: Blitter = nc::ncblitter_e_NCBLIT_2x1; + /// quadrants + 2x1 /// ▗▐ ▖▀▟▌▙ pub const BLIT_2x2: Blitter = nc::ncblitter_e_NCBLIT_2x2; + /// sextants (NOT 2x2) /// 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬉🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝🬞🬟🬠🬡🬢🬣🬤🬥🬦🬧🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻 pub const BLIT_3x2: Blitter = nc::ncblitter_e_NCBLIT_3x2; + /// four vertical levels /// █▆▄▂ pub const BLIT_4x1: Blitter = nc::ncblitter_e_NCBLIT_4x1; + /// eight vertical levels /// █▇▆▅▄▃▂▁ pub const BLIT_8x1: Blitter = nc::ncblitter_e_NCBLIT_8x1; + /// 4 rows, 2 cols (braille) /// ⡀⡄⡆⡇⢀⣀⣄⣆⣇⢠⣠⣤⣦⣧⢰⣰⣴⣶⣷⢸⣸⣼⣾⣿ pub const BLIT_BRAILLE: Blitter = nc::ncblitter_e_NCBLIT_BRAILLE; -/// automatic pick + +/// the blitter is automatically chosen pub const BLIT_DEFAULT: Blitter = nc::ncblitter_e_NCBLIT_DEFAULT; + /// 6 rows, 1 col (RGB), spotty support among terminals pub const BLIT_SIXEL: Blitter = nc::ncblitter_e_NCBLIT_SIXEL; -/// + +/// Type alias of ncscale_e pub type Scale = nc::ncscale_e; + /// Maintain original size pub const SCALE_NONE: Scale = nc::ncscale_e_NCSCALE_NONE; + /// Maintain aspect ratio pub const SCALE_SCALE: Scale = nc::ncscale_e_NCSCALE_SCALE; + /// Throw away aspect ratio pub const SCALE_STRETCH: Scale = nc::ncscale_e_NCSCALE_STRETCH; -/// + +/// Type alias of ncdirect (direct mode) pub type DirectMode = nc::ncdirect; + +/// Type alias of +pub type DirectModeFlags = u64; + +/// Avoids placing the terminal into cbreak mode (disabling echo and line buffering) +pub const DIRECTMODE_INHIBIT_CBREAK: DirectModeFlags = nc::NCDIRECT_OPTION_INHIBIT_CBREAK as DirectModeFlags; + +/// Avoids calling setlocale(LC_ALL, NULL). /// +/// If the result is either "C" or "POSIX", it will print a diagnostic to stderr, +/// and then call setlocale(LC_ALL, ""). This will attempt to set the locale based +/// off the LANG environment variable. Your program should call setlocale(3) itself, +/// usually as one of the first lines. +pub const DIRECTMODE_INHIBIT_SETLOCALE: DirectModeFlags = nc::NCDIRECT_OPTION_INHIBIT_SETLOCALE as DirectModeFlags; + + +/// Type alias of notcurses (full mode) pub type FullMode = nc::notcurses; -/// + +/// Type alias of ncinput pub type Input = nc::ncinput;