rust: add more functions and methods

- add functions: ncdirect_core_init & notcurses_core_init (methods pending)
- add functions & methods: ncdirect_readline & notcurses_can_braille
- minor fixes
pull/1516/head
joseLuís 4 years ago
parent 5492119263
commit 1c5ee9eb8c

@ -7,8 +7,8 @@ fn main() -> NcResult<()> {
// INFO
let t_rows = dm.dim_x();
let t_cols = dm.dim_y();
let t_rows = dm.dim_y();
let t_cols = dm.dim_x();
println!("Terminal rows={0}, cols={1}", t_rows, t_cols);
println!(

@ -138,6 +138,7 @@ pub use ffi::{
ncdirect_canutf8,
ncdirect_check_pixel_support,
ncdirect_clear,
ncdirect_core_init,
ncdirect_cursor_disable,
ncdirect_cursor_down,
ncdirect_cursor_enable,
@ -672,6 +673,7 @@ pub use ffi::{
// functions
notcurses_at_yx,
notcurses_bottom,
notcurses_canbraille,
notcurses_canchangecolor,
notcurses_canfade,
notcurses_canopen_images,
@ -680,6 +682,7 @@ pub use ffi::{
notcurses_cantruecolor,
notcurses_canutf8,
notcurses_check_pixel_support,
notcurses_core_init,
notcurses_cursor_disable,
notcurses_cursor_enable,
notcurses_debug,

@ -4,9 +4,9 @@ use core::ptr::{null, null_mut};
use crate::ffi::sigset_t;
use crate::{
cstring, error, error_ref_mut, NcAlign, NcBlitter, NcChannelPair, NcColor, NcDim, NcDirect,
NcDirectFlags, NcEgc, NcError, NcInput, NcPaletteIndex, NcPlane, NcResult, NcRgb, NcScale,
NcStyleMask, NcTime, NCRESULT_ERR,
cstring, error, error_ref_mut, rstring, NcAlign, NcBlitter, NcChannelPair, NcColor, NcDim,
NcDirect, NcDirectFlags, NcEgc, NcError, NcInput, NcPaletteIndex, NcPlane, NcResult, NcRgb,
NcScale, NcStyleMask, NcTime, NCRESULT_ERR,
};
/// # `NcDirect` constructors and destructors
@ -96,7 +96,9 @@ impl NcDirect {
maxy: i32,
maxx: i32,
) -> NcResult<&'a mut NcPlane> {
let res = unsafe { crate::ncdirect_render_frame(self, cstring![filename], blitter, scale, maxy, maxx) };
let res = unsafe {
crate::ncdirect_render_frame(self, cstring![filename], blitter, scale, maxy, maxx)
};
error_ref_mut![
res,
&format!(
@ -305,7 +307,6 @@ impl NcDirect {
}
}
/// Disables the terminal's cursor, if supported.
///
/// *C style function: [ncdirect_cursor_disable()][crate::ncdirect_cursor_disable].*
@ -539,6 +540,26 @@ impl NcDirect {
]
}
/// Reads a (heap-allocated) line of text using the Readline library.
///
/// Initializes Readline the first time it's called.
///
/// For input to be echoed to the terminal, it is necessary that
/// [NCDIRECT_OPTION_INHIBIT_CBREAK] be provided to [ncdirect_init]
///
/// *C style function: [ncdirect_readline()][crate::ncdirect_readline].*
pub fn readline(&mut self, prompt: &str) -> NcResult<&str> {
let res = unsafe { crate::ncdirect_readline(self, cstring![prompt]) };
if res != null_mut() {
return Ok(rstring![res]);
} else {
Err(NcError::with_msg(
NCRESULT_ERR,
&format!["NcDirect.readline({})", prompt],
))
}
}
/// Draws a box with its upper-left corner at the current cursor position,
/// having dimensions `ylen` * `xlen`.
///

@ -32,6 +32,7 @@
// fm ncdirect_canutf8
// fm ncdirect_check_pixel_support
// fm ncdirect_clear
// f~ ncdirect_core_init
// fm ncdirect_cursor_disable
// fm ncdirect_cursor_down
// fm ncdirect_cursor_enable
@ -59,6 +60,7 @@
//X ncdirect_printf_aligned
// fm ncdirect_putstr
// fm ncdirect_raster_frame
// fm ncdirect_readline
// fm ncdirect_render_frame
// fm ncdirect_render_image
// fm ncdirect_rounded_box

@ -160,6 +160,13 @@ impl Notcurses {
unsafe { &mut *crate::notcurses_bottom(self) }
}
/// Returns true if we can reliably use Unicode Braille.
///
/// *C style function: [notcurses_canbraille()][crate::notcurses_canbraille].*
pub fn canbraille(&self) -> bool {
unsafe { crate::notcurses_canbraille(self) }
}
/// Returns true if it's possible to set the "hardware" palette.
///
/// Requires the "ccc" terminfo capability.

@ -6,15 +6,15 @@
// 1 X: wont do
// 2 ~: WIP
//
// col 1: 48
// col 1: 50
// --------------
// 42 f: ffi function imported by bindgen
// 44 f: ffi function imported by bindgen
// F: ffi function wrapped safely
// 6 r: static function reimplemented in Rust
//
// col 2: 45
// col 2: 46
// --------------
// 38 m: impl as a `Notcurses` method
// 39 m: impl as a `Notcurses` method
// 7 M: impl for the `FullMode` wrapper struct too
//
// col 3: 14
@ -26,6 +26,7 @@
//
// fm notcurses_at_yx
// fm notcurses_bottom
// fm notcurses_canbraille
// fmt notcurses_canchangecolor
// fmt notcurses_canfade
// fmt notcurses_canopen_images
@ -34,6 +35,7 @@
// fmt notcurses_cantruecolor
// fmt notcurses_canutf8
// fm notcurses_check_pixel_support
// f~ notcurses_core_init
// fm notcurses_cursor_disable
// fm notcurses_cursor_enable
// fmt notcurses_debug

@ -302,7 +302,7 @@ pub const NCBLIT_BRAILLE: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_B
/// [`NcBlitter`] mode where the blitter is automatically chosen
pub const NCBLIT_DEFAULT: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_DEFAULT;
/// [`NcBlitter`] mode (not yet implemented)
/// [`NcPixel`] mode
///
/// See [Sixel in Wikipedia](https://en.wikipedia.org/wiki/Sixel).
pub const NCBLIT_PIXEL: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_PIXEL;

Loading…
Cancel
Save