Git Product home page Git Product logo

ncurses-rs's Introduction

Hi folks

I primarily work on jank, a Clojure dialect on LLVM with a native runtime and C++ interop.

Most of my projects are related to Clojure, C++, or Rust, and I'm trying to find the sweet spot between the three of them. That's where jank comes in.

I also run the Compiler Spotlight newsletter, which showcases programming languages and compilers.

❤️ Sponsor my work here: https://github.com/sponsors/jeaye ❤️

ncurses-rs's People

Contributors

alexchandel avatar brandonson avatar chris-morgan avatar correabuscar avatar dominikwerder avatar dpc avatar ebfe avatar ella-0 avatar euclio avatar golddranks avatar gyscos avatar hectorgrey avatar jeaye avatar kamiyaa avatar kornelski avatar lidavidm avatar magmast avatar mahkoh avatar marchelzo avatar marckvdv avatar phillipwalters avatar pmsanford avatar reisen avatar sodaplayer avatar thomashabets avatar tsurai avatar uasi avatar untitaker avatar utkarshkukreti avatar yeahnoob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ncurses-rs's Issues

Example code crashes on OpenBSD

Hi,

The "move a window" example (https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_4.rs) crashes on OpenBSD on rust rust-1.13.0.

The line which causes the crash is:

printw("Use the arrow keys to move");

Using gdb, it seems that something is smashing the stack:

Program received signal SIGABRT, Aborted.
0x0000113593013b9a in thrkill () at <stdin>:2
2       <stdin>: No such file or directory.
        in <stdin>
Current language:  auto; currently asm
(gdb) bt
#0  0x0000113593013b9a in thrkill () at <stdin>:2
#1  0x000011359305906f in *_libc___stack_smash_handler (func=0x1134a8d41d1a "wprintw", damaged=Variable "damaged" is not available.
)
    at /usr/src/lib/libc/sys/stack_protector.c:79
#2  0x00001134a8c1dc68 in wprintw (win=Variable "win" is not available.
) at /usr/src/lib/libcurses/base/lib_printw.c:84
#3  0x000011329b201fd6 in ?? () from /home/edd/source/fj/target/debug/fj
#4  0x0000000000000000 in ?? ()

(Note, I'm very new to rust and don't really know what I'm doing ;) )

tigetstr wrapper is unsafe & provides no way to check for failures

A simple attempt to use it segfaults:

fn main() {
    let capability = tigetstr("idontexist");
    if capability.is_empty() {
        println!("empty");
    } else {
        println!("nonempty");
    }
}

tigetstr returns (char *)-1 if the capability doesn't exist, and a null pointer if the capability isn't supported. Neither one seems to be supported by the ncurses-rs wrapper.

test fail to build on fedora 25: undefined reference to 'wget_wch'

ncurses 6.0

cargo test  --verbose

warning: path `/tmp/ncurses-rs/src/ncurses.rs` was erroneously implicitly accepted for library `ncurses`,
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml
       Fresh libc v0.2.32
       Fresh gcc v0.3.54
       Fresh pkg-config v0.3.9
   Compiling ncurses v5.86.0 (file:///tmp/ncurses-rs)
     Running `rustc --crate-name ex_7 examples/ex_7.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' -C metadata=32c66cdfcc872a56 -C extra-filename=-32c66cdfcc872a56 --out-dir /tmp/ncurses-rs/target/debug/examples -L dependency=/tmp/ncurses-rs/target/debug/deps --extern libc=/tmp/ncurses-rs/target/debug/deps/liblibc-126a44a53dfd6129.rlib --extern ncurses=/tmp/ncurses-rs/target/debug/deps/libncurses-9c81af12678bde21.rlib -C target-cpu=native -L native=/usr/lib64`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_70.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_71.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_710.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_711.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_712.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_713.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_714.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_715.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_72.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_73.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_74.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_75.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_76.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_77.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_78.rust-cgu.o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.ex_79.rust-cgu.o" "-o" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56" "/tmp/ncurses-rs/target/debug/examples/ex_7-32c66cdfcc872a56.crate.allocator.rust-cgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "-L" "/tmp/ncurses-rs/target/debug/deps" "-L" "/usr/lib64" "-L" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/tmp/ncurses-rs/target/debug/deps/libncurses-9c81af12678bde21.rlib" "/tmp/ncurses-rs/target/debug/deps/liblibc-126a44a53dfd6129.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-ef68455a36f432e0.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-f6e1402098866357.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_system-4217dfafb936c36b.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-97fa3d5ef4bd4fdd.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-cf9300d96e8efc7d.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-e6f731c8a56b92a5.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-58100a6f9c048547.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-f59d3752d69fd895.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-fe3fcd278911a505.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-fcc46f3067b1a58b.rlib" "/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-295aef536590064a.rlib" "-Wl,-Bdynamic" "-l" "ncurses" "-l" "tinfo" "-l" "util" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util"
  = note: src/ncurses.rs:349: error: undefined reference to 'wget_wch'
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: Could not compile `ncurses`.

Caused by:
  process didn't exit successfully: `rustc --crate-name ex_7 examples/ex_7.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg feature="default" -C metadata=32c66cdfcc872a56 -C extra-filename=-32c66cdfcc872a56 --out-dir /tmp/ncurses-rs/target/debug/examples -L dependency=/tmp/ncurses-rs/target/debug/deps --extern libc=/tmp/ncurses-rs/target/debug/deps/liblibc-126a44a53dfd6129.rlib --extern ncurses=/tmp/ncurses-rs/target/debug/deps/libncurses-9c81af12678bde21.rlib -C target-cpu=native -L native=/usr/lib64` (exit code: 101)

keyname can return null

According to the docs, keyname can return null, but this library currently expects this is not the case and return a String unconditionally. As a result, it segfaults if null is returned.

Could keyname check for null, and maybe return an Option<String> being None when null is returned? Thanks!

Does not build with latest nightly build (2015-01-12)

± % rustc --version
rustc 1.0.0-nightly (3d0d9bb6f 2015-01-12 22:56:20 +0000)

± % cargo build
Compiling ncurses v5.71.1 (https://github.com/jeaye/ncurses-rs.git#4dc62c21)
src/ncurses.rs:13:12: 13:17 warning: feature has been added to Rust, directive not necessary
src/ncurses.rs:13 #![feature(globs)]
                         ^~~~~
src/ncurses.rs:14:12: 14:23 warning: feature has been added to Rust, directive not necessary
src/ncurses.rs:14 #![feature(macro_rules)]
                         ^~~~~~~~~~~
src/constants.rs:186:35: 186:43 error: `$b:expr` is followed by `$m:expr`, which is not allowed for `expr` fragments
src/constants.rs:186 macro_rules! ncurses_mouse_mask( ($b: expr $m: expr) => ($m << (($b - 1) * 5)); );
                                                   ^~~~~~~~
src/constants.rs:233:31: 233:39 error: `$e:expr` is followed by `$x:expr`, which is not allowed for `expr` fragments
src/constants.rs:233 macro_rules! button_release( ($e: expr $x: expr) => (e & ncurses_mouse_mask!(x 0x001)); );
                                               ^~~~~~~~
src/constants.rs:234:29: 234:37 error: `$e:expr` is followed by `$x:expr`, which is not allowed for `expr` fragments
src/constants.rs:234 macro_rules! button_press( ($e: expr $x: expr) => (e & ncurses_mouse_mask!(x 0x002)); );
                                             ^~~~~~~~
src/constants.rs:235:29: 235:37 error: `$e:expr` is followed by `$x:expr`, which is not allowed for `expr` fragments
src/constants.rs:235 macro_rules! button_click( ($e: expr $x: expr) => (e & ncurses_mouse_mask!(x 0x004)); );
                                             ^~~~~~~~
src/constants.rs:236:36: 236:44 error: `$e:expr` is followed by `$x:expr`, which is not allowed for `expr` fragments
src/constants.rs:236 macro_rules! button_double_click( ($e: expr $x: expr) => (e & ncurses_mouse_mask!(x 0x008)); );
                                                    ^~~~~~~~
src/constants.rs:237:36: 237:44 error: `$e:expr` is followed by `$x:expr`, which is not allowed for `expr` fragments
src/constants.rs:237 macro_rules! button_triple_click( ($e: expr $x: expr) => (e & ncurses_mouse_mask!(x 0x010)); );
                                                    ^~~~~~~~
src/constants.rs:238:38: 238:46 error: `$e:expr` is followed by `$x:expr`, which is not allowed for `expr` fragments
src/constants.rs:238 macro_rules! button_reserved_event( ($e: expr $x: expr) => (e & ncurses_mouse_mask!(x 0x020)); );

Example 7 fails to build

I get some unresolved errors when trying to build example 7. The other examples build fine. (Arch linux 64)

src/main.rs:38:12: 38:20 error: unresolved name `wget_wch` [E0425]
src/main.rs:38   let ch = wget_wch(stdscr);
                          ^~~~~~~~
src/main.rs:38:12: 38:20 help: run `rustc --explain E0425` to see a detailed explanation
src/main.rs:40:10: 40:28 error: failed to resolve. Use of undeclared type or module `WchResult` [E0433]
src/main.rs:40     Some(WchResult::KeyCode(KEY_MOUSE)) => {
                        ^~~~~~~~~~~~~~~~~~
src/main.rs:40:10: 40:28 help: run `rustc --explain E0433` to see a detailed explanation
src/main.rs:48:10: 48:28 error: failed to resolve. Use of undeclared type or module `WchResult` [E0433]
src/main.rs:48     Some(WchResult::KeyCode(_)) => {
                        ^~~~~~~~~~~~~~~~~~
src/main.rs:48:10: 48:28 help: run `rustc --explain E0433` to see a detailed explanation
src/main.rs:56:10: 56:25 error: failed to resolve. Use of undeclared type or module `WchResult` [E0433]
src/main.rs:56     Some(WchResult::Char(c)) => {
                        ^~~~~~~~~~~~~~~
src/main.rs:56:10: 56:25 help: run `rustc --explain E0433` to see a detailed explanation
error: aborting due to 4 previous errors

`chtype` (and so `attr_t`) is 64bits on Ubuntu 16.10

  • On my machine (archlinux with ncurses 6.0 installed), /usr/include/ncurses.h contains:
#if 1 && defined(_LP64)
typedef unsigned chtype;
typedef unsigned mmask_t;
# else
typedef uint32_t chtype;
typedef uint32_t mmask_t;
#endif

This results in a 32bits chtype.

  • On a Ubuntu 16.10 docker image (with libncursesw5-dev installed), /usr/include/ncursesw/ncurses.h contains:
#if 0 && defined(_LP64)
typedef unsigned chtype;
typedef unsigned mmask_t;
#else
typedef unsigned long chtype;
typedef unsigned long mmask_t;
#endif

This results in a 64bits chtype.

ncurses-rs assumes it is 32 bits, so this type mismatch can cause big troubles in functions like attr_get where ncurses overwrites some extra bytes.

Build error with menu feature on master

# Cargo.toml
# ...
[dependencies.ncurses]
git = "https://github.com/jeaye/ncurses-rs"
rev = "master"
default-features = false  # Disable "wide" to build on OS X
features = ["menu"]
// src/main.rs
extern crate ncurses;
fn main() { }

% cargo build
    Updating git repository `https://github.com/jeaye/ncurses-rs`
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling libc v0.1.8
   Compiling ncurses v5.73.0 (https://github.com/jeaye/ncurses-rs?rev=master#1c09de2c)
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:34:53: 34:63 error: no method named `into_ptr` found for type `std::ffi::c_str::CString` in the current scope
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:34     super::ll::new_item(CString::new(name).unwrap().into_ptr(), CString::new(description).unwrap().into_ptr())
                                                                                                                                                                           ^~~~~~~~~~
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:34:100: 34:110 error: no method named `into_ptr` found for type `std::ffi::c_str::CString` in the current scope
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:34     super::ll::new_item(CString::new(name).unwrap().into_ptr(), CString::new(description).unwrap().into_ptr())
                                                                                                                                                                                                                          ^~~~~~~~~~
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:164:5: 164:22 error: no associated item named `from_ptr` found for type `std::ffi::c_str::CString` in the current scope
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:164     CString::from_ptr(item as *const i8);
                                                                                                                            ^~~~~~~~~~~~~~~~~
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:337:64: 337:74 error: no method named `into_ptr` found for type `std::ffi::c_str::CString` in the current scope
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:337     super::ll::set_menu_mark(menu, CString::new(mark).unwrap().into_ptr())
                                                                                                                                                                                       ^~~~~~~~~~
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:358:70: 358:80 error: no method named `into_ptr` found for type `std::ffi::c_str::CString` in the current scope
/Users/uasi/.multirust/toolchains/stable/cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/menu/wrapper.rs:358     super::ll::set_menu_pattern(menu, CString::new(pattern).unwrap().into_ptr())
                                                                                                                                                                                             ^~~~~~~~~~
error: aborting due to 5 previous errors
Could not compile `ncurses`.

To learn more, run the command again with --verbose.

% rustc --version --verbose
rustc 1.1.0 (35ceea399 2015-06-19)
binary: rustc
commit-hash: 35ceea3997c79a3b7562e89b462ab76af5b86b22
commit-date: 2015-06-19
host: x86_64-apple-darwin
release: 1.1.0

KEY_DC and KEY_IC use wrong code

On my machine, KEY_DC is defined in ncurses.h as 0512, that is 330 or 0x14A.
However it is defined as 0x150 in constants.rs. I suspect a typo?

Similarly, KEY_IC sould be defined as 0513 = 0x14B, but is 0x151 in constans.rs.

ABI Problems on 64-bit Debian

The ABI for chtype isn't quite correct in src/ll.rs on Debian. For some reason Debian on amd64 compiles ncurses with the --disable-lp64 option (probably to be ABI backwards compatible), causing chtype to be an unsigned long instead of an unsigned int. This leads to some strange things happening when using eg. box_(0,0).

I don't know enough Rust yet to know what a good fix for this is (I don't know if there's a good way to pull a typedef out of a C header file), but at least if somebody else hits it they might see this. My fix is just to switch distros 😄.

Make API more natural for Rust

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.

Derive `Default` for MEVENT

To retrieve a mouse event, we need to use ncurses::getmouse with a *mut EVENT. This means we need to create an "empty" MEVENT to give to this function.
It would be nice to be able to create this object using MEVENT::default(), rather than initializing the fields manually. (The result would be similar to C, where we just declare MEVENT event;)

Build issue; permission denied to open file

Trying out the simple hello world example.

I added ncurses to my dependencies and just ran it. This is the result:

cargo build
   Compiling ncurses v5.85.0
error: failed to run custom build command for `ncurses v5.85.0`
process didn't exit successfully: `C:\~~~\rust\example\target\debug\build\ncurses-35f9ffa7ff1eeb80\build-script-build` (exit code: 101)
--- stdout
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-pc-windows-msvc")
HOST = Some("x86_64-pc-windows-msvc")
TARGET = Some("x86_64-pc-windows-msvc")
TARGET = Some("x86_64-pc-windows-msvc")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
TARGET = Some("x86_64-pc-windows-msvc")
HOST = Some("x86_64-pc-windows-msvc")
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
PROFILE = Some("debug")
chtype_size.c
c1: fatal error C1083: Cannot open source file: 'C:\~~~\rust\example\target\debug\build\ncurses-b821ee5513798319\out\chtype_size.c': Permission denied

--- stderr
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
thread 'main' panicked at 'C:\~~~\rust\example\target\debug\build\ncurses-b821ee5513798319\out\chtype_size failed: Error { repr: Os { code: 2, message: "The system cannot find the file specified." } }', C:\bot\slave\stable-dist-rustc-win-msvc-64\build\src\libcore\result.rs:868

attron and wattron takes different argument types

attron (and attroff) take attr_t, which is a u64, while wattron (and wattroff) take a i32.
I suspect the first one is the correct one?

EDIT: just found out the original ncurses lib is similarly inconsistent. Since an upstream fix seem unlikely, maybe we could fix it here?... :-S

addchstr null termination

The addchstr family of functions requires that the chstr array is null terminated, but the bindings currently don't ensure null termination. This could lead to reads out of bounds of the input array.

mismatched types error on armv7 linux

Trying to compile ncurses using rustc 1.5.0-dev (e518c057f 2015-10-23) on arm as part of a thyme build fails with:

Compiling ncurses v5.73.0
     Running `rustc /home/odroid/.cargo/registry/src/github.com-121aea75f9ef2ce2/ncurses-5.73.0/src/ncurses.rs --crate-name ncurses --crate-type lib -C opt-level=3 --cfg feature=\"default\" --cfg feature=\"wide\" -C metadata=086a089f5500fcfb -C extra-filename=-086a089f5500fcfb --out-dir /tmp/thyme-master/target/release/deps --emit=dep-info,link -L dependency=/tmp/thyme-master/target/release/deps -L dependency=/tmp/thyme-master/target/release/deps --extern libc=/tmp/thyme-master/target/release/deps/liblibc-ba87e8a144a58f65.rlib --cap-lints allow`
/home/odroid/.cargo/registry/src/github.com-121aea75f9ef2ce2/ncurses-5.73.0/src/ncurses.rs:43:40: 43:41 error: mismatched types:
 expected `*const i8`,
    found `*const u8`
(expected i8,
    found u8) [E0308]
/home/odroid/.cargo/registry/src/github.com-121aea75f9ef2ce2/ncurses-5.73.0/src/ncurses.rs:43             let bytes = CStr::from_ptr(s).to_bytes();

.
.
.
.

/home/odroid/.cargo/registry/src/github.com-121aea75f9ef2ce2/ncurses-5.73.0/src/ncurses.rs:43:40: 43:41 help: run `rustc --explain E0308` to see a detailed explanation
/home/odroid/.cargo/registry/src/github.com-121aea75f9ef2ce2/ncurses-5.73.0/src/ncurses.rs:1546:27: 1546:48 error: mismatched types:
 expected `*const u8`,
    found `*const i8`
(expected u8,
    found i8) [E0308]
/home/odroid/.cargo/registry/src/github.com-121aea75f9ef2ce2/ncurses-5.73.0/src/ncurses.rs:1546 { unsafe { ll::wprintw(w, s.to_c_str().as_ptr()) } }
                                                                                                                          ^~~~~~~~~~~~~~~~~~~~~
/home/odroid/.cargo/registry/src/github.com-121aea75f9ef2ce2/ncurses-5.73.0/src/ncurses.rs:1546:27: 1546:48 help: run `rustc --explain E0308` to see a detailed explanation

error: aborting due to 25 previous errors
Could not compile `ncurses`.

Is this related to the recent libc crate update? (0.2)

Build error on Windows 8.1 x64

I tried to build ncurses-rs from cargo.

Build log: https://gist.github.com/jajakobyly/fa09e29fc46f49cf4474 (quite a long one)
OS: Windows 8.1 x64
rustc version:

rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37e99060162a2674e3ff45409ac73595c0e
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-pc-windows-gnu
release: 1.0.0

It looks like a wrong integer type is used throughout the bindings.

Fails to compile on 2014-06-29 rustc nightly

Could not execute process `rustc src/ncurses.rs --crate-type lib --out-dir /home/henry/rust-gravity-worm/target/deps -L /home/henry/rust-gravity-worm/target/deps -L /home/henry/rust-gravity-worm/target/deps` (status=101)
--- stderr
src/ll.rs:23:21: 23:22 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:23 pub type attr_t_p = *attr_t;
                                 ^
src/ll.rs:24:20: 24:21 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:24 pub type short_p = *c_short;
                                ^
src/ll.rs:25:19: 25:20 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:25 pub type void_p = *c_void;
                               ^
src/ll.rs:26:19: 26:20 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:26 pub type char_p = *c_char;
                               ^
src/ll.rs:27:21: 27:22 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:27 pub type chtype_p = *chtype;
                                 ^
src/ll.rs:28:19: 28:20 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:28 pub type WINDOW = *WINDOW_impl;
                               ^
src/ll.rs:29:19: 29:20 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:29 pub type SCREEN = *SCREEN_impl;
                               ^
src/ll.rs:30:19: 30:20 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:30 pub type FILE_p = *FILE;
                               ^
src/ll.rs:31:20: 31:21 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ll.rs:31 pub type va_list = *u8;
                                ^
src/constants.rs:21:23: 21:24 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/constants.rs:21   pub static ttytype: *c_char;
                                          ^
src/ncurses.rs:83:29: 83:30 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:83     ll::attr_get(&*attrs as *i32,
                                              ^
src/ncurses.rs:84:28: 84:29 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:84                  &*pair as *i16,
                                             ^
src/ncurses.rs:159:30: 159:31 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:159                       &*r as *i16,
                                                ^
src/ncurses.rs:160:30: 160:31 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:160                       &*g as *i16,
                                                ^
src/ncurses.rs:161:30: 161:31 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:161                       &*b as *i16)
                                                ^
src/ncurses.rs:311:23: 311:24 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:311 pub fn getwin(reader: *libc::FILE) -> WINDOW
                                         ^
src/ncurses.rs:1021:42: 1021:43 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1021 { unsafe { ll::pair_content(pair, &*f as *i16, &*b as *i16) } }
                                                             ^
src/ncurses.rs:1021:55: 1021:56 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1021 { unsafe { ll::pair_content(pair, &*f as *i16, &*b as *i16) } }
                                                                          ^
src/ncurses.rs:1379:40: 1379:41 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1379 { unsafe { ll::wattr_get(w, &*attrs as *i32, &*pair as *i16, ptr::null()) } }
                                                           ^
src/ncurses.rs:1379:56: 1379:57 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1379 { unsafe { ll::wattr_get(w, &*attrs as *i32, &*pair as *i16, ptr::null()) } }
                                                                           ^
src/ncurses.rs:1672:39: 1672:40 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1672 { unsafe { ll::wgetscrreg(w, &*top as *i32, &*bot as *i32) } }
                                                          ^
src/ncurses.rs:1672:54: 1672:55 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1672 { unsafe { ll::wgetscrreg(w, &*top as *i32, &*bot as *i32) } }
                                                                         ^
src/ncurses.rs:1800:66: 1800:67 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1800 { unsafe { char::from_u32(*((acs_map as i32 + 4 * (c as i32)) as *u32)).expect("Invalid char") } }
                                                                                     ^
src/ncurses.rs:1957:24: 1957:25 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1957 pub fn getmouse(event: *MEVENT) -> i32
                                           ^
src/ncurses.rs:1960:26: 1960:27 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1960 pub fn ungetmouse(event: *MEVENT) -> i32
                                             ^
src/ncurses.rs:1975:24: 1975:25 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
src/ncurses.rs:1975 pub fn wmouse_trafo(w: *WINDOW, y: &[i32], x: &[i32], to_screen: bool) -> i32
                                           ^
error: aborting due to 26 previous errors

Multiple TRUE imports

    Updating git repository `https://github.com/jeaye/ncurses-rs.git`
   Compiling ncurses v5.80.0 (https://github.com/jeaye/ncurses-rs.git#2b3e818d)
D:\Users\nabijaczleweli\.cargo\git\checkouts\ncurses-rs-a39bc38240b97745\master\src\menu\wrapper.rs:11:5: 11:20 error: a value named `TRUE` has already been imported in this module [E0252]
D:\Users\nabijaczleweli\.cargo\git\checkouts\ncurses-rs-a39bc38240b97745\master\src\menu\wrapper.rs:11 use constants::TRUE;
                                                                                                           ^~~~~~~~~~~~~~~
D:\Users\nabijaczleweli\.cargo\git\checkouts\ncurses-rs-a39bc38240b97745\master\src\menu\wrapper.rs:11:5: 11:20 help: run `rustc --explain E0252` to see a detailed explanation
D:\Users\nabijaczleweli\.cargo\git\checkouts\ncurses-rs-a39bc38240b97745\master\src\menu\wrapper.rs:8:1: 8:13 note: previous import of `TRUE` here
D:\Users\nabijaczleweli\.cargo\git\checkouts\ncurses-rs-a39bc38240b97745\master\src\menu\wrapper.rs:8 use libc::*;
                                                                                                      ^~~~~~~~~~~~
error: aborting due to previous error
Could not compile `ncurses`.

Happens on Rust stable 1.5.0, upstream ncurses-rs.

ALL_MOUSE_EVENTS and mousemask have incompatible types

  • In C, ALL_MOUSE_EVENTS is defined in ncurses.h as a macro, so doesn't really have a type.
    mousemask takes a mmask_t, which is defined the same as chtype (unsigned 32 bits).

  • In rust, ALL_MOUSE_EVENTS is defined as a i32.
    mousemask takes a mmask_t, which is defined as chtype.

I think ALL_MOUSE_EVENTS should be defined as a mmask_t instead of i32.

Can't print chars like ✔?

Hei!

Nice work. I'm currently trying the library. Now, i'm trying to print characters like emojis (or others things). And mvprintw(LINES() - 2, 1, "✔") gives me weird symbols. Any way to print this correctly?

Have a nice day!

Build fails on Rust Beta

I'm trying to build a project with ncurses and get the following error when running cargo build:

    Compiling ncurses v5.72.0 (https://github.com/jeaye/ncurses-rs#7a019596)
/Users/Paul/.cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/ncurses.rs:15:1: 15:18 error: unstable feature
/Users/Paul/.cargo/git/checkouts/ncurses-rs-19e4d6676c1c76f9/master/src/ncurses.rs:15 #![feature(core)]
                                                                                      ^~~~~~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
error: aborting due to previous error
Could not compile `ncurses`.

Generates "warning: redundant linker flag specified for library `ncurses`"

If I create a new binary project, add 'ncurses = "*"', and build it, it generates the following warning:

warning: redundant linker flag specified for library `ncurses`

This occurs on an unstable x86_64 Debian system with libncurses5-dev 6.0+20171125-1 installed.

Should this warning be addressed somehow?

`ncurses::stdscr` will require unsafe block

Using latest Rust nightly, accessing static extern require unsafe (see rust-lang/rust#35112):

The examples now produce this error:

% rustc --version
rustc 1.13.0-nightly (55bf6a4f8 2016-09-18)
% cargo build --example ex_2
   Compiling ncurses v5.82.0 (file:///home/gyscos/fetched/ncurses-rs)
warning: use of extern static requires unsafe function or block (error E0133), #[warn(safe_extern_statics)] on by default
  --> examples/ex_2.rs:23:10
   |
23 |   keypad(stdscr, true);
   |          ^^^^^^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue 36247 <https://github.com/rust-lang/rust/issues/35112>

    Finished debug [unoptimized + debuginfo] target(s) in 0.21 secs

Performance problem when creating a new window

I use ncurses programs like cmus and wifi-menu and I never run into performance issues. However, ncurses-rs seems to flicker when calling doupdate() (or refresh()) after a call to newwin(). I've created an example program which demonstrates the flicker.

I'm wondering if it's an isssue with the program, an issue with ncurses, or an issue with my code:

extern crate ncurses;

use std::{thread, time};
use ncurses::*;

fn main () {
    initscr();
    refresh();

    // sleep for 3
    thread::sleep(time::Duration::new(3, 0));

    let win = newwin(0,0,0,0);
    wnoutrefresh(win);
    doupdate();

    // sleep for 3
    thread::sleep(time::Duration::new(3, 0));
    endwin();
}

Thanks.

Submit to crates.io

There currently isn't a wrapper for ncurses on crates.io. This repo would be a good start!

Printw segfault

printw segfaults if you try to print a string with %s in it. Not sure if this is expected or not:

printw("%s")

addstr does not.

Push new version to crates.io?

Could we have the latest version of this repository uploaded to crates.io? I'm trying to publish a crate that depends on this one, and I need features from the latest version of this repository on GitHub - the crates.io version is too old. I can't seem to reference GitHub dependencies in published crates, so would you be able to publish a new version on crates.io?

Compilation on linux fails with "error: mismatched types: expected `uint` but found `u32`"

Here's the build error:

$ make
rustc -O --out-dir target src/ncurses.rs
src/ncurses.rs:1676:14: 1676:44 error: mismatched types: expected `uint` but found `u32` (expected uint but found u32)
src/ncurses.rs:1676 { ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) }
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/ncurses.rs:1688:27: 1688:31 error: mismatched types: expected `uint` but found `u32` (expected uint but found u32)
src/ncurses.rs:1688 { NCURSES_BITS(((1u32) << 8u32) - 1u32, 0u32) as i32 }
                                              ^~~~
error: aborting due to 2 previous errors
make: *** [target/libncurses-37fa153e-5.71.rlib] Error 101

I'm building using a freshly updated rust nightly build from https://launchpad.net/~hansjorg/+archive/rust.

Build error on OSX 10.9.1

ProductName: Mac OS X
ProductVersion: 10.9.1
BuildVersion: 13B3116

silver@calypso:~/Projects/Rust/ncurses-rs-master% sudo make -B   
»»» Building ncurses-rs 
error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'lib/libncurses-f5aa8b14-5.71.dylib' 'lib/ncurses.o' 'lib/ncurses.metadata.o' '-L/Users/silver/Projects/Rust/ncurses-rs-master/.rust' '-L/Users/silver/Projects/Rust/ncurses-rs-master' '-L/Users/silver/Projects/Rust/.rust' '-lncurses' '-L/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lstd-3e5aeb83-0.9' '-lpthread' '-dynamiclib' '-Wl,-dylib' '-Wl,-install_name,@rpath/libncurses-f5aa8b14-5.71.dylib' '-lmorestack' '-Wl,-rpath,@loader_path/../../../../../../usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-Wl,-rpath,/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-Wl,-rpath,/usr/local/Cellar/rust/0.9/lib/rustlib/x86_64-apple-darwin/lib'
note: ld: warning: directory not found for option '-L/Users/silver/Projects/Rust/ncurses-rs-master/.rust'
Undefined symbols for architecture x86_64:
  "_has_mouse", referenced from:
      has_mouse::h1ead82b7e4510befaN::v5.71 in ncurses.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /private/tmp/rust-R5p2/rust-0.9/src/libsyntax/diagnostic.rs:75
task '<main>' failed at 'explicit failure', /private/tmp/rust-R5p2/rust-0.9/src/librustc/lib.rs:453
make: *** [.build_lib] Error 101

`COLOR_PAIR` takes i16 instead of i32

ll::COLOR_PAIR takes c_int, which resolves to i32. But ncurses::COLOR_PAIR somehow takes a i16 (and converts it internally to a i32).
It seems having ncurses::COLOR_PAIR take a i32 would be much simpler.

EDIT: Aaaaaaah damn ncurses and its incoherent type usage! I don't know what should be done anymore :(

Online documentation needed

Maybe because I'm a Rust noob, but I can't find documentation anywhere. "Documentation" link in Crates.io page redirects to this Github page, but there's no online documentation as far as I can see.

Special ACS characters don't work

I'm not sure what's happening, considering the ACS methods are so thin, but the bug is present: using, for instance, addch(ACS_TTEE()); prints ^@ instead.
I tried with ACS_ULCORNER, or basically any other ACS_ method, and it always prints ^@ instead.

Note: using the box_ method (using the default characters) does produce the correct result. It's just impossible to do it manually.

EDIT: it seems addch may be the culprit. printw("┘"); works fine, but addch('┘'); does not.

(I did some tests with the C ncurses library, and while addch('┘'); does not work because does not fit in a byte, addch(ACS_TTEE); does work... :-S )

Can't access private MEVENT struct members

I'm not sure how I'm supposed to get at any of an MEVENT struct's members - when I try to do something like println!("{}", (*ev).x) I get a compile error: field 'x' of struct 'ncurses::ll::MEVENT' is private.

Relicense under dual MIT/Apache-2.0

This issue was automatically generated. Feel free to close without ceremony if
you do not agree with re-licensing or if it is not possible for other reasons.
Respond to @cmr with any questions or concerns, or pop over to
#rust-offtopic on IRC to discuss.

You're receiving this because someone (perhaps the project maintainer)
published a crates.io package with the license as "MIT" xor "Apache-2.0" and
the repository field pointing here.

TL;DR the Rust ecosystem is largely Apache-2.0. Being available under that
license is good for interoperation. The MIT license as an add-on can be nice
for GPLv2 projects to use your code.

Why?

The MIT license requires reproducing countless copies of the same copyright
header with different names in the copyright field, for every MIT library in
use. The Apache license does not have this drawback. However, this is not the
primary motivation for me creating these issues. The Apache license also has
protections from patent trolls and an explicit contribution licensing clause.
However, the Apache license is incompatible with GPLv2. This is why Rust is
dual-licensed as MIT/Apache (the "primary" license being Apache, MIT only for
GPLv2 compat), and doing so would be wise for this project. This also makes
this crate suitable for inclusion and unrestricted sharing in the Rust
standard distribution and other projects using dual MIT/Apache, such as my
personal ulterior motive, the Robigalia project.

Some ask, "Does this really apply to binary redistributions? Does MIT really
require reproducing the whole thing?" I'm not a lawyer, and I can't give legal
advice, but some Google Android apps include open source attributions using
this interpretation. Others also agree with
it
.
But, again, the copyright notice redistribution is not the primary motivation
for the dual-licensing. It's stronger protections to licensees and better
interoperation with the wider Rust ecosystem.

How?

To do this, get explicit approval from each contributor of copyrightable work
(as not all contributions qualify for copyright, due to not being a "creative
work", e.g. a typo fix) and then add the following to your README:

## License

Licensed under either of

 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.

and in your license headers, if you have them, use the following boilerplate
(based on that used in Rust):

// Copyright 2016 ncurses-rs Developers
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

It's commonly asked whether license headers are required. I'm not comfortable
making an official recommendation either way, but the Apache license
recommends it in their appendix on how to use the license.

Be sure to add the relevant LICENSE-{MIT,APACHE} files. You can copy these
from the Rust repo for a plain-text
version.

And don't forget to update the license metadata in your Cargo.toml to:

license = "MIT OR Apache-2.0"

I'll be going through projects which agree to be relicensed and have approval
by the necessary contributors and doing this changes, so feel free to leave
the heavy lifting to me!

Contributor checkoff

To agree to relicensing, comment with :

I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.

Or, if you're a contributor, you can check the box in this repo next to your
name. My scripts will pick this exact phrase up and check your checkbox, but
I'll come through and manually review this issue later as well.

something is wrong with colors (example 5 is not working as expected)

I think there's something wrong with color-related part of the API. For example, example 5 doesn't show anything on my terminal.

When I select the text shown in example, I can copy the shown text(e.g. code from a Rust file) but the text is just not visible. (probably related with colors)

Only thing that's visible in example 5 is the "press space" text in the bottom. I don't know why, maybe because there is something wrong with attribute generation. As far as I can see "press space" text is printed using a built-in attribute. (instead of attributes created using ncurses-rs API)

Another thing to note is that I changed my terminal colors from dark to light etc. but nothing changed. (the app is painting the background anyway)

Name resolution error on master

# Cargo.toml
# ...
[dependencies.ncurses]
git = "https://github.com/jeaye/ncurses-rs"
rev = "master"  # == 1c09de2ceac3bf98981e0093938eba34dacf4f2f
default-features = false  # Disable "wide" to build on OS X
// src/main.rs
extern crate ncurses;
fn main() {
    ncurses::initscr();
    ncurses::endwin();
}

% cargo build
   Compiling ncurses-test v0.1.0 (file:///Users/uasi/ncurses-test)
src/main.rs:3:5: 3:21 error: unresolved name `ncurses::initscr`
src/main.rs:3     ncurses::initscr();
                  ^~~~~~~~~~~~~~~~
src/main.rs:4:5: 4:20 error: unresolved name `ncurses::endwin`
src/main.rs:4     ncurses::endwin();
                  ^~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
Could not compile `rust-ncurses-color`.

To learn more, run the command again with --verbose.
% rustc --version --verbose
rustc 1.1.0 (35ceea399 2015-06-19)
binary: rustc
commit-hash: 35ceea3997c79a3b7562e89b462ab76af5b86b22
commit-date: 2015-06-19
host: x86_64-apple-darwin
release: 1.1.0

setlocale does not handle null_ptr

Also, I think the returned String must be cloned.

I wonder if that's a exploitable security issue. Probably is, but considering the scope it doesn't matter, I guess.

Testing fix, will submit PR shortly.

has_colors() always returns false because ll::has_colors() returns non-bool

// src/main.rs
extern crate ncurses;
use ncurses::*;

fn main() {
    initscr();
    let has_colors = has_colors();
    let ll_has_colors = unsafe { ll::has_colors() };
    endwin();
    println!("has_colors={}, ll_has_colors={}", has_colors, ll_has_colors);
}

% cargo run
     Running `target/debug/rust-ncurses-color`
has_colors=false, ll_has_colors=-624931583

(-624931583 == 0b11011010110000000100110100000001; it seems the higher bits are uninitialized)

% rustc --version --verbose
rustc 1.1.0 (35ceea399 2015-06-19)
binary: rustc
commit-hash: 35ceea3997c79a3b7562e89b462ab76af5b86b22
commit-date: 2015-06-19
host: x86_64-apple-darwin
release: 1.1.0

Mouse events are broken

Retrieving mouse events through ncurses-rs does not work. getmouse(event) always returns an error. has_mouse() also always indicates that the mouse is not supported.

Here is a simple C program demonstrating mouse functionality:

#include <ncurses.h>
#include <assert.h>

int main() {
    int ch, count=0;
    MEVENT event;

    initscr();
    raw();
    keypad(stdscr, TRUE);
    noecho();

    clear();
    cbreak();

    mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);

    while ((ch = getch()) != 'q') {
        count++;
        mvprintw(1, 1, "Has mouse: %d", has_mouse());
        mvprintw(2, 1, "Key code: %x; mouse code:%x", ch, KEY_MOUSE);
        if (ch == KEY_MOUSE) {
            assert(getmouse(&event) == OK);
            mvprintw(3, 3, "Mouse Event: x=%d, y=%d z=%d",
                    event.x, event.y, event.z);
            mvprintw(4, 3, "Mouse device id: %x", event.id);
            mvprintw(5, 3, "Mouse button mask: %x", event.bstate);
        }
        mvprintw(6, 1, "Event number: %4d",count);
        refresh();
    }
    endwin();
}

After compiling and linking with ncurses, the program prints all mouse events received to the screen.

Here is a Rust translation of the same program:

extern crate ncurses;

use std::ptr;

use ncurses::*;

fn main() {
    initscr();
    raw();
    keypad(stdscr, true);
    noecho();

    clear();
    cbreak();

    mousemask((ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION) as u64, None);

    let mut ch = getch();
    let mut count = 0;
    let mut even: MEVENT = unsafe { mem::uninitialized() };
    while ch != 'q' as i32 {
        ch = getch();
        count += 1;
        mvprintw(1, 1, &format!("Has mouse: {}", has_mouse()));
        mvprintw(2, 1, &format!("Key code: {:x}; mouse code: {:x}", ch, KEY_MOUSE));
        if ch == KEY_MOUSE {
            assert!(getmouse(event_ptr) == OK);
            let event = unsafe { *event_ptr };
            mvprintw(3, 3, &format!("Mouse Event: x={}, y={}, z={}", event.x, event.y, event.z));
            mvprintw(4, 3, &format!("Mouse device id: {:x}", event.id));
            mvprintw(5, 3, &format!("Mouse button mask: {:x}", event.bstate));
        }
        mvprintw(6, 1, &format!("Event number: {:04}", count));
        refresh();
    }
    endwin();
}

The program panics with a failed assertion. Upon removing the assertion, the program crashes immediately, probably due to a null pointer dereference.

EDIT: Fixed failed assertion thanks to @lifthrasiir

Collaborators wanted

I spend less and less time with Rust these days, so it's been up to the community to keep ncurses-rs going. Fortunately, you guys are awesome. I'd like to bring on one or two collaborators, who have committed to ncurses-rs already, or who're prominent enough in the Rust scene, to help make sure ncurses-rs is going where it should.

If you'd like to volunteer, comment here or shoot me an email if you'd prefer to keep it private.

Incorrect values for e.g. KEY_DC

I somehow screwed up the translation of the ncurses header file, and so there are incorrect entries for at least some of the cases.

I only discovered this while making enums for a "Rust-ified" wrapper module, and rustc complained about duplicate entries.

Here are the particular examples I have found at the outset:

pub static KEY_DC: i32=                0x150;                /* delete-character key */
pub static KEY_IC: i32=                0x151;                /* insert-character key */
pub static KEY_EIC: i32=                0x152;                /* sent by rmir or smir in insert mode */
...
pub static KEY_SF: i32=                0x150;                /* scroll-forward key */
pub static KEY_SR: i32=                0x151;                /* scroll-backward key */
pub static KEY_NPAGE: i32=        0x152;                /* next-page key */

We now have octal literals, I'm going to change my code to just use them; that should be easier to match up against the ncurses header file.

Build error when running make

Using rust nightly fron 2015-05-04.

Running make gives the following output:
http://pastebin.com/jKBvZBiF

TLDR:
error: use of unstable library feature 'libc'
help: add #![feature(libc)] to the crate attributes to enable

EDIT: I guess the makefile is deprecated and Cargo is the way to go now?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.