ncurses-rs icon indicating copy to clipboard operation
ncurses-rs copied to clipboard

Make API more natural for Rust

Open netvl opened this issue 9 years ago • 7 comments

For example, there is no reason to use mutable references for functions like getmaxyx(): instead of

let mut max_x = 0;
let mut max_y = 0;
getmaxyx(stdscr, &mut max_y, &mut max_x);

you should be able to write

let (max_y, max_x) = getmaxyx(stdscr);

as this is more idiomatic for Rust.

Maybe there are other parts of API which could be modeled better in Rust too, this is the most glaring one.

netvl avatar Oct 23 '14 19:10 netvl

I understand your concern. ncurses-rs was designed specifically to allow near-one-to-one ports from C code, so it didn't really "rustify" the API at all. Note the first sentence of the README:

This is a very thin wrapper around the ncurses TUI lib.

With that said, providing an orthogonal version with a more rustic API (given the proper refinement and testing, as well as support from the existing ncurses-rs users) might increase the longevity of the project. Alas, I don't have the time for this now; we need a new hero to take the reigns.

jeaye avatar Oct 24 '14 02:10 jeaye

I say leave the library as plain and simple wrapper, and handle high-level stuff in a separate library.

osa1 avatar Nov 02 '14 10:11 osa1

This issue isn't that the library should be more abstract, but that the constructs aren't idiomatic for Rust.

marcusklaas avatar Dec 07 '14 16:12 marcusklaas

@marcusklaas yes good point. This library wouldn't have to be abstract to be rust idiomatic.

alexispurslane avatar Dec 14 '14 14:12 alexispurslane

@jeaye I'd argue that one-to-one ports from C into Rust would barely take advantage of the new language, since a main selling point of Rust is that you don't have to use mutability everywhere to write memory-efficient programs. I propose that ncurses is wrapped the other way around: The C-compatible API should be built on top of the idiomatic one.

untitaker avatar Mar 05 '15 18:03 untitaker

With that said, providing an orthogonal version with a more rustic API (given the proper refinement and testing, as well as support from the existing ncurses-rs users) might increase the longevity of the project. Alas, I don't have the time for this now; we need a new hero to take the reigns.

@untitaker ^

jeaye avatar Mar 06 '15 08:03 jeaye

For a more Rustic API, you can probably use pancurses which aims "to provide a more Rustic interface over the usual curses functions for ease of use while remaining close enough to curses to make porting easy." It's a wrapper for this (on Unix) and pdcurses-sys (on Windows).

gbear605 avatar Dec 13 '17 21:12 gbear605