diff --git a/rust/examples/direct-capabilities.rs b/rust/examples/direct-capabilities.rs new file mode 100644 index 000000000..0c7ab6d74 --- /dev/null +++ b/rust/examples/direct-capabilities.rs @@ -0,0 +1,22 @@ +use libnotcurses_sys::*; + +fn main() -> NcResult<()> { + let mut dm = DirectMode::new()?; + + let (t_rows, t_cols) = dm.dim_yx(); + println!("Terminal rows={0}, cols={1}", t_rows, t_cols); + + println!( + "Can display UTF-8: {0} +Can open images: {1} +Supports Pixels: {2:?} +Palette size: {3:?} +", + dm.canutf8(), + dm.canopen_images(), + dm.check_pixel_support(), + dm.palette_size(), + ); + + Ok(()) +} diff --git a/rust/examples/direct-text.rs b/rust/examples/direct-text.rs deleted file mode 100644 index 4fd52712b..000000000 --- a/rust/examples/direct-text.rs +++ /dev/null @@ -1,110 +0,0 @@ -#![allow(unused_imports)] - -use libnotcurses_sys::*; - -fn main() -> NcResult<()> { - let mut dm = DirectMode::new()?; - - // INFO - - let t_rows = dm.dim_y(); - let t_cols = dm.dim_x(); - 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::(), - // )?; - // 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(()) -} diff --git a/rust/examples/full-capabilities.rs b/rust/examples/full-capabilities.rs new file mode 100644 index 000000000..52c8a6cc1 --- /dev/null +++ b/rust/examples/full-capabilities.rs @@ -0,0 +1,30 @@ +use libnotcurses_sys::*; + +fn main() -> NcResult<()> { + let mut nc = FullMode::new()?; + + let (t_rows, t_cols) = nc.term_dim_yx(); + println!("Terminal rows={0}, cols={1}", t_rows, t_cols); + + println!( + "Can display UTF-8: {0} +Can display sextant characters: {1} +Can open images: {2} +Can open videos: {3} +Supports Pixels: {4:?} +Supports True Color: {5} +Palette size: {6:?} +", + nc.canutf8(), + nc.cansextant(), + nc.canopen_images(), + nc.canopen_videos(), + nc.check_pixel_support(), + nc.cantruecolor(), + nc.palette_size(), + ); + + println!("Done. Waiting for 10 seconds. . ."); + rsleep![&mut nc, 10]; + Ok(()) +} diff --git a/rust/src/direct/methods.rs b/rust/src/direct/methods.rs index 29def2cdd..a852481f5 100644 --- a/rust/src/direct/methods.rs +++ b/rust/src/direct/methods.rs @@ -159,7 +159,8 @@ impl NcDirect { ] } - /// Returns the number of simultaneous colors claimed to be supported. + /// Returns the number of simultaneous colors claimed to be supported, + /// if there is color support. /// /// Note that several terminal emulators advertise more colors than they /// actually support, downsampling internally. diff --git a/rust/src/notcurses/methods.rs b/rust/src/notcurses/methods.rs index e943a0608..982e8d873 100644 --- a/rust/src/notcurses/methods.rs +++ b/rust/src/notcurses/methods.rs @@ -456,14 +456,21 @@ impl Notcurses { } /// Returns the number of simultaneous colors claimed to be supported, - /// or 1 if there is no color support. + /// if there is color support. /// /// Note that several terminal emulators advertise more colors than they /// actually support, downsampling internally. /// /// *C style function: [notcurses_palette_size()][crate::notcurses_palette_size].* - pub fn palette_size(&mut self) -> u32 { - unsafe { crate::notcurses_palette_size(self) } + pub fn palette_size(&mut self) -> NcResult { + let res = unsafe { crate::notcurses_palette_size(self) }; + if res == 1 { + return Err(NcError::with_msg( + 1, + "No color support ← Notcurses.palette_size()", + )); + } + Ok(res) } /// Refreshes the physical screen to match what was last rendered (i.e.,