-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add stdscr() #43
base: main
Are you sure you want to change the base?
Add stdscr() #43
Conversation
The test failure for windows are:
|
I wonder if theres a way to enable the This would be a place where I think it'd be warranted to differ from the regular ncurses API a bit more. How does a program usually do things with |
I either call stdscr, or methods that implicitly use stdscr internally. |
If newterm returning a Window works I'd prefer that over exposing stdscr. |
Sounds good. Newterm is supposed to replace initscr, so returning a window as well makes sense. |
Can we merge/release this one, since it exposes a pretty useful function? |
There is one problem with this pull request. This is Unicode support. This PR supports us to use Unicode support was implemented by this commit: 16139e4. Though that commit did not take into account that another source than stdout could be used. The solution for this is to add like pub fn newterm(t: Option<&str>, output: FILE, input: FILE) -> ScrPtr {
platform_specific::pre_init();
let term_type = t.map(|x| CString::new(x).unwrap());
let type_ptr = match term_type {
Some(ref s) => s.as_ptr(),
_ => std::ptr::null(),
};
unsafe { curses::newterm(type_ptr, output, input) }
} I am using this code, and the Unicode support worked when I added the // By default pancurses use stdout.
// We can change this by calling `new_term` with an FILE pointer to the source.
// Which is /dev/tty in our case.
let file = File::open("/dev/tty").unwrap();
let c_file = unsafe {
libc::fdopen(
file.into_raw_fd(),
CStr::from_bytes_with_nul_unchecked(b"w+\0").as_ptr(),
)
};
// Create screen pointer which we will be using for this backend.
let screen = unsafe { pancurses::newterm(Some(env!("TERM")), c_file, c_file) };
// Get `Window` of the created screen.
let window = pancurses::stdscr();
window.printw("█"); |
Fixes #40