rust: add *_check_pixel_support functions + example

pull/1516/head
joseLuís 3 years ago
parent 8db054ede7
commit 5492119263

@ -0,0 +1,110 @@
#![allow(unused_imports)]
use libnotcurses_sys::*;
fn main() -> NcResult<()> {
let mut dm = DirectMode::new()?;
// INFO
let t_rows = dm.dim_x();
let t_cols = dm.dim_y();
println!("Terminal rows={0}, cols={1}", t_rows, t_cols);
println!(
"Can open images: {0}\nCan UTF-8: {1}\nSupports Pixels: {2:?}",
dm.canopen_images(),
dm.canutf8(),
dm.check_pixel_support()?,
);
println!("palette_size: {}", dm.palette_size()?);
// TEXT & STYLE
// let stylesv = vec![
// ("[DIM]", Style::Dim),
// ("[UNDERLINE]", Style::Underline),
// ("[ITALIC]", Style::Italic),
// ("[BOLD]", Style::Bold),
// ("[STRUCK]", Style::Struck),
// ("[REVERSE]", Style::Reverse),
// ("[BLINK]", Style::Blink),
// ("[INVIS]", Style::Invis),
// ("[PROTECT]", Style::Protect),
// ("[STANDOUT]", Style::Standout),
// ];
//
// dm.print_colored(0, "\nSingle styles:\n")?;
//
// dm.print_colored(0, "[DEFAULT]")?;
// for (label, style) in stylesv.iter() {
// dm.styles_on(*style)?;
// dm.print_colored(0, label)?;
// dm.styles_off(*style)?;
// }
//
// dm.print_colored(0, "\nJoint styles:\n")?;
//
// dm.print_colored(0, "[DEFAULT ")?;
// for (label, style) in stylesv.iter() {
// dm.styles_on(*style)?;
// dm.print_colored(
// 0,
// &label
// .chars()
// .map(|c| match c {
// '[' | ']' => ' ',
// _ => c,
// })
// .collect::<String>(),
// )?;
// if let Style::Blink = style {
// break;
// }
// }
// dm.styles_off_all()?;
// dm.print_colored(0, "]")?;
//
// // TEXT mixing Rust's print!() & println!() and notcurses' print_colored() & print()
// //
// dm.print_colored(0, "\n\n1")?;
// println!("2 < instead of printing this concatenated AFTER, it appears BEFORE 1");
//
// dm.print_colored(0, "\n\n1 \n")?;
// println!("2 < it does work (better) with a `\\n` after 1");
//
// // TODO: more tests with styles_set & bold+italic
// //
// //dm.styles_off(Style::Bold)?;
// //dm.styles_on(Style::Italic)?;
//
// // COLORS & TEXT (WIP)
//
// dm.bg(0x00FF00 as u32)?; // FIXME: colors don't seem to work
// dm.fg(0xFF0000 as u32)?;
// println!("\nhello colors? (investigate)");
// dm.print_colored(
// sys::channels_combine(0xFF008800, 0xFFBB0099),
// "hello colors 2",
// )?;
// dm.print_colored(0, "...")?;
// TODO: should be able to use print!() & println!()
// dm.clear()?;
// dm.print_aligned(0, Align::Center, "PRINTED")?;
// dm.print_aligned(40, Align::Left, "PRINTED")?;
// dm.print_aligned(5, Align::Right, "PRINTED")?;
// WIP----------------------- ↓
// CURSOR & TEXT
// println!("Cursor position: {:?}", dm.cursor_yx()?);
// dm.cursor_move_yx(200,100)?;
// dm.cursor_move_yx(yx.0, yx.1)?;
// dm.cursor_disable()?;
// dm.cursor_enable()?;
Ok(())
}

@ -136,6 +136,7 @@ pub use ffi::{
ncdirect_box,
ncdirect_canopen_images,
ncdirect_canutf8,
ncdirect_check_pixel_support,
ncdirect_clear,
ncdirect_cursor_disable,
ncdirect_cursor_down,
@ -161,6 +162,7 @@ pub use ffi::{
ncdirect_printf_aligned,
ncdirect_putstr,
ncdirect_raster_frame,
ncdirect_readline,
ncdirect_render_frame,
ncdirect_render_image,
ncdirect_rounded_box,
@ -677,6 +679,7 @@ pub use ffi::{
notcurses_cansextant,
notcurses_cantruecolor,
notcurses_canutf8,
notcurses_check_pixel_support,
notcurses_cursor_disable,
notcurses_cursor_enable,
notcurses_debug,

@ -285,6 +285,27 @@ impl NcDirect {
unsafe { crate::ncdirect_canutf8(self) }
}
/// Checks for pixel support.
///
/// Returns `false` for no support, or `true` if pixel output is supported.
///
/// This function must successfully return before NCBLIT_PIXEL is available.
///
/// Must not be called concurrently with either input or rasterization.
///
/// *C style function: [ncdirect_check_pixel_support()][crate::ncdirect_check-pixel_support].*
pub fn check_pixel_support(&mut self) -> NcResult<bool> {
let res = unsafe { crate::ncdirect_check_pixel_support(self) };
match res {
0 => return Ok(false),
1 => return Ok(true),
NCRESULT_ERR | _ => {
return Err(NcError::with_msg(res, "NcDirect.check_pixel_support()"));
}
}
}
/// Disables the terminal's cursor, if supported.
///
/// *C style function: [ncdirect_cursor_disable()][crate::ncdirect_cursor_disable].*

@ -30,6 +30,7 @@
// fm ncdirect_box
// fm ncdirect_canopen_images
// fm ncdirect_canutf8
// fm ncdirect_check_pixel_support
// fm ncdirect_clear
// fm ncdirect_cursor_disable
// fm ncdirect_cursor_down
@ -67,11 +68,10 @@
//X ncdirect_styles_on // deprecated
//X ncdirect_styles_set // deprecated
// fm ncdirect_vline_interp
//
// rm ncdirect_bg_rgb8
// rm ncdirect_fg_rgb8
// rm ncdirect_getc_nblock
// rm ncdirect_getc_nblocking
// rm ncdirect_bg_rgb8
// rm ncdirect_fg_rgb8
// rm ncdirect_getc_nblock
// rm ncdirect_getc_nblocking
#[cfg(test)]
mod test;

@ -220,6 +220,26 @@ impl Notcurses {
unsafe { crate::notcurses_canutf8(self) }
}
/// Checks for pixel support.
///
/// Returns `false` for no support, or `true` if pixel output is supported.
///
/// This function must successfully return before NCBLIT_PIXEL is available.
///
/// Must not be called concurrently with either input or rasterization.
///
/// *C style function: [notcurses_check_pixel_support()][crate::notcurses_check-pixel_support].*
pub fn check_pixel_support(&mut self) -> NcResult<bool> {
let res = unsafe { crate::notcurses_check_pixel_support(self) };
match res {
0 => return Ok(false),
1 => return Ok(true),
NCRESULT_ERR | _ => {
return Err(NcError::with_msg(res, "Notcuses.check_pixel_support()"));
}
}
}
/// Disables the terminal's cursor, if supported.
///
/// Immediate effect (no need for a call to notcurses_render()).

@ -33,6 +33,7 @@
// fmt notcurses_cansextant
// fmt notcurses_cantruecolor
// fmt notcurses_canutf8
// fm notcurses_check_pixel_support
// fm notcurses_cursor_disable
// fm notcurses_cursor_enable
// fmt notcurses_debug

Loading…
Cancel
Save