Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pancurses work with ncurses 6.0.1 #93

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target/
.project
Cargo.lock
.settings/
rustc-ice-*.txt
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions src/unix/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 15 additions & 6 deletions src/window.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -28,8 +30,8 @@ impl Window {
///
/// The functionality is similar to calling window.addch() once for each character in the
/// string.
pub fn addstr<T: AsRef<str>>(&self, string: T) -> i32 {
let s = CString::new(string.as_ref()).unwrap();
pub fn addstr<T: AsRef<str>>(&self, string: T) -> i32 {
let s = CString::new(string.as_ref()).unwrap();
unsafe { curses::waddstr(self._window, s.as_ptr()) }
}

Expand Down Expand Up @@ -370,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)
}

Expand Down Expand Up @@ -445,7 +449,10 @@ impl Window {
/// Add a string to the window at the specified cursor position.
pub fn mvprintw<T: AsRef<str>>(&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).
Expand Down Expand Up @@ -485,7 +492,9 @@ impl Window {
/// Add a string to the window at the current cursor position.
pub fn printw<T: AsRef<str>>(&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
Expand All @@ -497,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 {
Expand Down