From 071ddb2ef70d3d5a5291cd52b1faf3d630f1d50e Mon Sep 17 00:00:00 2001 From: correabuscar Date: Thu, 11 Apr 2024 10:23:02 +0200 Subject: [PATCH 1/3] make it work with ncurses v6.0.1 --- Cargo.toml | 2 +- src/unix/constants.rs | 30 +++++++++++++++--------------- src/window.rs | 12 ++++++++++-- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cc34a62d..9b76e01d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ libc = "0.2" pdcurses-sys = "0.7" winreg = "0.5" [target.'cfg(unix)'.dependencies] -ncurses = "5.101.0" +ncurses = "6.0.1" [dev-dependencies] rand = "0.8.4" diff --git a/src/unix/constants.rs b/src/unix/constants.rs index a3a4bddd..c9f20c3b 100644 --- a/src/unix/constants.rs +++ b/src/unix/constants.rs @@ -62,28 +62,28 @@ pub use ncurses::COLOR_RED; pub use ncurses::COLOR_WHITE; pub use ncurses::COLOR_YELLOW; -pub const A_ALTCHARSET: attr_t = ncurses::A_ALTCHARSET(); -pub const A_ATTRIBUTES: attr_t = ncurses::A_ATTRIBUTES(); -pub const A_BLINK: attr_t = ncurses::A_BLINK(); -pub const A_BOLD: attr_t = ncurses::A_BOLD(); -pub const A_CHARTEXT: attr_t = ncurses::A_CHARTEXT(); -pub const A_COLOR: attr_t = ncurses::A_COLOR(); -pub const A_DIM: attr_t = ncurses::A_DIM(); -pub const A_ITALIC: attr_t = ncurses::A_ITALIC(); -pub const A_INVIS: attr_t = ncurses::A_INVIS(); +pub const A_ALTCHARSET: attr_t = ncurses::A_ALTCHARSET; +pub const A_ATTRIBUTES: attr_t = ncurses::A_ATTRIBUTES; +pub const A_BLINK: attr_t = ncurses::A_BLINK; +pub const A_BOLD: attr_t = ncurses::A_BOLD; +pub const A_CHARTEXT: attr_t = ncurses::A_CHARTEXT; +pub const A_COLOR: attr_t = ncurses::A_COLOR; +pub const A_DIM: attr_t = ncurses::A_DIM; +pub const A_ITALIC: attr_t = ncurses::A_ITALIC; +pub const A_INVIS: attr_t = ncurses::A_INVIS; pub const A_LEFTLINE: attr_t = 0; // Not supported on ncurses -pub const A_NORMAL: attr_t = ncurses::A_NORMAL(); +pub const A_NORMAL: attr_t = ncurses::A_NORMAL; pub const A_OVERLINE: attr_t = 0; // Not supported on ncurses -pub const A_REVERSE: attr_t = ncurses::A_REVERSE(); +pub const A_REVERSE: attr_t = ncurses::A_REVERSE; pub const A_RIGHTLINE: attr_t = 0; // Not supported on ncurses -pub const A_STANDOUT: attr_t = ncurses::A_STANDOUT(); +pub const A_STANDOUT: attr_t = ncurses::A_STANDOUT; pub const A_STRIKEOUT: attr_t = 0; // Not supported on ncurses -pub const A_UNDERLINE: attr_t = ncurses::A_UNDERLINE(); +pub const A_UNDERLINE: attr_t = ncurses::A_UNDERLINE; pub const KEY_OFFSET: i32 = 0o0400; pub const KEY_RESIZE: i32 = ncurses::KEY_RESIZE; -pub const KEY_F15: i32 = ncurses::KEY_F15; -pub const KEY_EVENT: i32 = ncurses::KEY_EVENT; +pub const KEY_F15: i32 = ncurses::KEY_F(15); +//pub const KEY_EVENT: i32 = ncurses::KEY_EVENT; // doesn't exist anymore in /usr/include/ncurses.h -> curses.h of ncurses 6.4_p20230401 (gentoo) or in ncurses-rs https://github.com/jeaye/ncurses-rs/pull/201/files#diff-b9f534f90cc01f9fbdcf768139ee60ac1e0c33b114024029c8e2f3f1e32c8a97L215 pub const SPECIAL_KEY_CODES: [Input; 108] = [ Input::KeyCodeYes, diff --git a/src/window.rs b/src/window.rs index a3a3747d..a0e47074 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,3 +1,5 @@ +#![warn(temporary_cstring_as_ptr)] // false positives? https://github.com/rust-lang/rust/issues/78691 + use crate::{chtype, curses, platform_specific, ptr, Input, ToChtype, ERR}; use std::ffi::CString; @@ -442,10 +444,14 @@ impl Window { unsafe { curses::mvwinsch(self._window, y, x, ch.to_chtype()) } } + /// Add a string to the window at the specified cursor position. pub fn mvprintw>(&self, y: i32, x: i32, string: T) -> i32 { let s = CString::new(string.as_ref()).unwrap(); - unsafe { curses::mvwprintw(self._window, y, x, s.as_ptr()) } + //XXX: extracted to variable 'ps' due to false positive warning https://github.com/rust-lang/rust/issues/78691 + let ps = CString::new("%s").unwrap();//FIXME: find a better way + unsafe { curses::mvwprintw(self._window, y, x, ps.as_ptr(), s.as_ptr()) } + //unsafe { curses::mvwprintw(self._window, y, x, CString::new("%s").unwrap().as_ptr(), s.as_ptr()) } } /// Moves the window so that the upper left-hand corner is at position (y,x). @@ -485,7 +491,9 @@ impl Window { /// Add a string to the window at the current cursor position. pub fn printw>(&self, string: T) -> i32 { let s = CString::new(string.as_ref()).unwrap(); - unsafe { curses::wprintw(self._window, s.as_ptr()) } + //XXX: extracted to variable 'ps' due to false positive warning https://github.com/rust-lang/rust/issues/78691 + let ps = CString::new("%s").unwrap();//FIXME: find a better way + unsafe { curses::wprintw(self._window, ps.as_ptr(), s.as_ptr()) } } /// Copies the named window to the physical terminal screen, taking into account what From 6dc0b1f929b3d557d42773c734bb7c10ed87e275 Mon Sep 17 00:00:00 2001 From: correabuscar Date: Thu, 11 Apr 2024 10:31:40 +0200 Subject: [PATCH 2/3] rustfmt src/window.rs --- src/window.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/window.rs b/src/window.rs index a0e47074..b922ee04 100644 --- a/src/window.rs +++ b/src/window.rs @@ -30,8 +30,8 @@ impl Window { /// /// The functionality is similar to calling window.addch() once for each character in the /// string. - pub fn addstr>(&self, string: T) -> i32 { - let s = CString::new(string.as_ref()).unwrap(); + pub fn addstr>(&self, string: T) -> i32 { + let s = CString::new(string.as_ref()).unwrap(); unsafe { curses::waddstr(self._window, s.as_ptr()) } } @@ -372,7 +372,9 @@ impl Window { pub fn mouse_trafo(&self, y: i32, x: i32, to_screen: bool) -> (i32, i32) { let mut mut_y = y; let mut mut_x = x; - unsafe { curses::wmouse_trafo(self._window, &mut mut_y, &mut mut_x, to_screen as u8); } + unsafe { + curses::wmouse_trafo(self._window, &mut mut_y, &mut mut_x, to_screen as u8); + } (mut_y, mut_x) } @@ -444,12 +446,11 @@ impl Window { unsafe { curses::mvwinsch(self._window, y, x, ch.to_chtype()) } } - /// Add a string to the window at the specified cursor position. pub fn mvprintw>(&self, y: i32, x: i32, string: T) -> i32 { let s = CString::new(string.as_ref()).unwrap(); //XXX: extracted to variable 'ps' due to false positive warning https://github.com/rust-lang/rust/issues/78691 - let ps = CString::new("%s").unwrap();//FIXME: find a better way + let ps = CString::new("%s").unwrap(); //FIXME: find a better way unsafe { curses::mvwprintw(self._window, y, x, ps.as_ptr(), s.as_ptr()) } //unsafe { curses::mvwprintw(self._window, y, x, CString::new("%s").unwrap().as_ptr(), s.as_ptr()) } } @@ -492,7 +493,7 @@ impl Window { pub fn printw>(&self, string: T) -> i32 { let s = CString::new(string.as_ref()).unwrap(); //XXX: extracted to variable 'ps' due to false positive warning https://github.com/rust-lang/rust/issues/78691 - let ps = CString::new("%s").unwrap();//FIXME: find a better way + let ps = CString::new("%s").unwrap(); //FIXME: find a better way unsafe { curses::wprintw(self._window, ps.as_ptr(), s.as_ptr()) } } @@ -505,7 +506,7 @@ impl Window { pub fn refresh(&self) -> i32 { unsafe { curses::wrefresh(self._window) } } - + /// Resizes the window to the given dimensions. Doesn't resize subwindows on pdcurses /// so you have to resize them yourself. pub fn resize(&mut self, nlines: i32, ncols: i32) -> i32 { From 91c83d641611bb17d53247022580fe4485722f5f Mon Sep 17 00:00:00 2001 From: correabuscar Date: Thu, 11 Apr 2024 12:44:02 +0200 Subject: [PATCH 3/3] .gitignore rustc ice files ... created due to using -Z treat-err-as-bug=5 and there are more than 5 compile errors, eg. rustc-ice-2024-04-11T10_19_07-85702.txt --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7274c22c..8ebc7eee 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target/ .project Cargo.lock .settings/ +rustc-ice-*.txt