Giter Site home page Giter Site logo

rustbox's Introduction

Rustbox

Rustbox is a Rust implementation of termbox.

Currently, this is just a wrapper of the C library by nsf, though my plan is to convert it to be a pure Rust implementation and remove the requirement on the C library.

The original implementation of this was inspired by Aaron Pribadi, so big props to him for the original work.

NOTE This is under development, and the APIs may change as I figure out more how Rust works and as the language itself changes

Documentation

Usage

In your Cargo.toml add the following:

[dependencies]
rustbox = "*"

You can also use the current git version by instead adding:

[dependencies.rustbox]
git = "https://github.com/gchp/rustbox.git"

Then, in your src/example.rs:

extern crate rustbox;

use std::error::Error;
use std::default::Default;

use rustbox::{Color, RustBox};
use rustbox::Key;

fn main() {
    let rustbox = match RustBox::init(Default::default()) {
        Result::Ok(v) => v,
        Result::Err(e) => panic!("{}", e),
    };

    rustbox.print(1, 1, rustbox::RB_BOLD, Color::White, Color::Black, "Hello, world!");
    rustbox.print(1, 3, rustbox::RB_BOLD, Color::White, Color::Black,
                  "Press 'q' to quit.");
    rustbox.present();
    loop {
        match rustbox.poll_event(false) {
            Ok(rustbox::Event::KeyEvent(key)) => {
                match key {
                    Key::Char('q') => { break; }
                    _ => { }
                }
            },
            Err(e) => panic!("{}", e.description()),
            _ => { }
        }
    }
}

NOTE: this example can also be run with cargo run --example hello-world.

Projects that use this crate:

rustbox's People

Contributors

benaryorg avatar bharadwaj6 avatar cpjreynolds avatar craigbarnes avatar crespyl avatar dsprenkels avatar dubhead avatar equal-l2 avatar florianjacob avatar gchp avatar hivectl avatar jackc avatar jmacdonald avatar jstasiak avatar kerinin avatar kindlychung avatar neuschaefer avatar panicbit avatar pythonesque avatar ryanwilliams avatar sogomn avatar sru avatar stebalien avatar tomjakubowski avatar utkarshkukreti avatar wisagan avatar yamakaky 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  avatar  avatar  avatar  avatar  avatar  avatar

rustbox's Issues

SeqCst unresolved name

Debug log is as follows:

src/rustbox.rs:150:30: 150:44 error: unresolved name `atomic::SeqCst`
src/rustbox.rs:150         RUSTBOX_RUNNING.load(atomic::SeqCst)
                                                ^~~~~~~~~~~~~~
src/rustbox.rs:160:39: 160:53 error: unresolved name `atomic::SeqCst`
src/rustbox.rs:160         if RUSTBOX_RUNNING.swap(true, atomic::SeqCst) {
                                                         ^~~~~~~~~~~~~~
src/rustbox.rs:173:42: 173:56 error: unresolved name `atomic::SeqCst`
src/rustbox.rs:173             RUSTBOX_RUNNING.store(false, atomic::SeqCst);
                                                            ^~~~~~~~~~~~~~
error: aborting due to 3 previous errors
Could not compile `rustbox`.

Backspace does not work

I tried to react to a Key::Backspace in my program but I did not receive it, so I displayed the event that occurred and it was read as a KeyEvent(Ctrl('h')).

I don't know if rustbox or the underlying libraries are the problem but I will investigate further.

Any limitations?

If I wanted to use rustbox as base for a TUI text editor, should I be aware of any limitations? Specifically, when using certain library it's sometimes impossible to parse certain key combinations etc. Example from kakoune: mawww/kakoune#1270 , where <c-h> can't be used because ncurses does not handle it.

Using InputMode::Mouse triggers termbox assertion

Using termbox.set_input_mode(InputMode::Mouse) and poll_event(โ€ฆ) triggers an assertion in termbox. It doesn't seem to trigger imediately after a poll but when deinitializing rust-/termbox.

Here's a minimal example:

extern crate rustbox;

fn main() {
    let rustbox = rustbox::RustBox::init(Default::default()).unwrap();
    rustbox.set_input_mode(rustbox::InputMode::Mouse);
    rustbox.poll_event(true);
}

What's weird, though, is that the equivalent C program does not trigger the assertion:

#include "termbox.h"

int main(int argc, char **argv) {
    tb_init();
    tb_select_input_mode(TB_INPUT_MOUSE);

    struct tb_event ev;
    tb_poll_event(&ev);

    tb_shutdown();
    return 0;
}

testing should include stable branch

I suggest to add the testing target stable to .travis.yml.

But as this is an administrative decision, I am not going to send a pull-request.

Further targets include:

  • beta
  • 1.2.0
  • 1.3.0
  • 1.4.0
  • 1.5.0

The version targets as a sort of promise-statement.
As if you said

The library runs on all of these platforms.

And only the incompatible, old platforms are then removed (and new old ones (current stable) added).

This is just a suggestion though.

Can't compile with rustc beta 1.1

Exact version: rustc 1.1.0-beta (cd7d89af9 2015-05-16) (built 2015-05-16)

   Compiling rustbox v0.6.1
/Users/benekastah/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbox-0.6.1/src/rustbox.rs:1:1: 1:18 error: unstable feature
/Users/benekastah/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbox-0.6.1/src/rustbox.rs:1 #![feature(libc)]
                                                                                                 ^~~~~~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
/Users/benekastah/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbox-0.6.1/src/rustbox.rs:2:1: 2:34 error: unstable feature
/Users/benekastah/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbox-0.6.1/src/rustbox.rs:2 #![feature(optin_builtin_traits)]
                                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
error: aborting due to 2 previous errors
Could not compile `rustbox`.

I also can't compile with the rustc 1.0 since tempfile (a dependency of a dependency I guess) won't compile on that version.

Can't control cursor

This is a bit of an odd issue. I cannot control the appearance of the cursor on only one my computers, running OSX Mavericks. On the other one, with Yosemite, I can use rustbox.set_cursor() to control its position, but it has no effect on this one.

I'll attach a picture of what it looks like and what it should look like. Here the cursor is following the input for some reason.

screen shot 2015-02-01 at 7 48 55 pm

Here it seems to work as expected. There is no difference in code on the two boxes.
screen shot 2015-02-01 at 7 51 00 pm

std::char::from_digit not working with print_char()

extern crate rustbox;

use rustbox::{Color, RustBox};
use std::char::from_digit;
use rustbox::Key;

fn main() {

    let rustbox = RustBox::init(Default::default()).ok().unwrap();
    for x in 0..rustbox.width() - 1 {
           rustbox.print_char(x, 0, rustbox::RB_NORMAL, Color::Black, Color::Cyan, '-');
    }

    for y in 0..rustbox.height() - 1 {
           rustbox.print_char(0, y + 1, rustbox::RB_NORMAL, Color::Black, Color::Blue, from_digit(y as u32, 10).unwrap());
    }

    loop {
        rustbox.present();
        match rustbox.poll_event(false) {
            Ok(rustbox::Event::KeyEvent(key)) => {
                match key {
                    Key::Char('q') => { break; }
                    _ => { }
                }
            },
            Err(e) => panic!("{}", e),
            _ => { }
        }
    }

}

The following program does not print anything to the screen whereas changing the from_digit() call to a hardcoded char value makes it run fine.

remove Option from KeyEvent

I just wrote a small event-loop and noticed the Some I needed to place everywhere.

After a while it gets a little annoying.
So I'm suggesting the following change:

  • KeyEvent will be KeyEvent(Key)
  • Key enum will contain something like an Unhandled or Other element wrapping an u16
  • Key::from_code(u16) will not return an Option but a Key and in the _ branch returns Key::Unhandled(code)
    • Sorry I did not understand what the function is for

The functionality stays the same but solved more "rust-like" as we can use more beautiful match-branches.

Edit: If you are okay with the proposed changes I would like to send this as a PR to make your life a bit easier.

256 color support

It is currently available in termbox master, and hasn't made it into a release yet. It would be nice to add it to rustbox once termbox 1.1.0 lands.

Key::Ctrl('[') does not work

I replaced the quit key from Key::Char('q') to Key::Ctrl('[') in example.rs but it takes no effect when attempting to quit.

I haven't been able to reproduce this problem with any other combination so far.

EDIT: I took a look at the source and it seems like the currently working keys are

rustbox/src/keyboard.rs

Lines 27 to 83 in 1d42771

match code {
1 => Some(Key::Ctrl('a')),
2 => Some(Key::Ctrl('b')),
3 => Some(Key::Ctrl('c')),
4 => Some(Key::Ctrl('d')),
5 => Some(Key::Ctrl('e')),
6 => Some(Key::Ctrl('f')),
7 => Some(Key::Ctrl('g')),
8 => Some(Key::Ctrl('h')),
9 => Some(Key::Tab),
10 => Some(Key::Ctrl('j')),
11 => Some(Key::Ctrl('k')),
12 => Some(Key::Ctrl('l')),
13 => Some(Key::Enter),
14 => Some(Key::Ctrl('n')),
15 => Some(Key::Ctrl('o')),
16 => Some(Key::Ctrl('p')),
17 => Some(Key::Ctrl('q')),
18 => Some(Key::Ctrl('r')),
19 => Some(Key::Ctrl('s')),
20 => Some(Key::Ctrl('t')),
21 => Some(Key::Ctrl('u')),
22 => Some(Key::Ctrl('v')),
23 => Some(Key::Ctrl('w')),
24 => Some(Key::Ctrl('x')),
25 => Some(Key::Ctrl('y')),
26 => Some(Key::Ctrl('z')),
27 => Some(Key::Esc),
28 => Some(Key::Ctrl('\\')),
29 => Some(Key::Ctrl(']')),
30 => Some(Key::Ctrl('6')),
31 => Some(Key::Ctrl('/')),
32 => Some(Key::Char(' ')),
127 => Some(Key::Backspace),
65514 => Some(Key::Right),
65515 => Some(Key::Left),
65516 => Some(Key::Down),
65517 => Some(Key::Up),
65535 => Some(Key::F(1)),
65534 => Some(Key::F(2)),
65533 => Some(Key::F(3)),
65532 => Some(Key::F(4)),
65531 => Some(Key::F(5)),
65530 => Some(Key::F(6)),
65529 => Some(Key::F(7)),
65528 => Some(Key::F(8)),
65527 => Some(Key::F(9)),
65526 => Some(Key::F(10)),
65525 => Some(Key::F(11)),
65524 => Some(Key::F(12)),
65523 => Some(Key::Insert),
65522 => Some(Key::Delete),
65521 => Some(Key::Home),
65520 => Some(Key::End),
65519 => Some(Key::PageUp),
65518 => Some(Key::PageDown),
_ => None,

Any reason other combinations aren't a part yet?

Integer type mismatch

The .width() and .height() methods on RustBox return usize, but the ResizeEvent variant of Event provides a pair of i32 integers. The types between the methods and the variant probably should match.

Windows support

So far I've only tested this on Linux and Mac. Need to make sure it works correctly on Windows also. Right now I believe this doesn't even build on Windows. See gchp/iota#25 for a starting place.

Signals are not handler properly

My term is completely broken after finishing application with SIGINT/SIGTERM (cursor and input characters are invisible, x axis positioning is broken too), I guess these signals should be handled to terminate resources properly.
I'm using Arch Linux and termite terminal emulator.

Thread safety

Hi,

I've been experimenting with rustbox and wanted to use it to across threads.

According to this commit it looks like I can: #8

But then I get this error when I try to use it in a thread:

the trait `core::marker::Send` is not implemented for the type `*mut ()`

Which I think is coming from here:

_phantom: PhantomData<*mut ()>,

Which indicated that termbox isn't thread safe.

Can rustbox be used in threads?

If so, any tips on how? I've tried wrapping it in Arc::new(Mutex::new(Rustbox::init()) but without luck.

Cheers

Means of waking up the event loop

Right now, rustbox blocks in poll_event and there is no way of waking it up. An external event in another thread does not seem to have any means of triggering a redraw without using peek_event in a busy loop.

I think a cleaner design would be to replace poll_event through a mpsc::channel. The consumer could then select over multiple channels to act on multiple inputs and peek_event could just be idiomatically replaced through https://doc.rust-lang.org/nightly/std/iter/struct.Peekable.html. This would also allow for the very intuitive for loop syntax:

// rustbox.events is a mpsc::Receiver<rustbox::Event>;
while let (event) = rustbox.events {
match event {
....
}
}

Unable to compile example on Mac OSX

/Users/gabriel/.cargo/registry/src/github.com-1ecc6299db9ec823/tempfile-0.4.0/src/imp/unix.rs:45:17:     45:21 error: unresolved name `path`. Did you mean `dir`?
/Users/gabriel/.cargo/registry/src/github.com-1ecc6299db9ec823/tempfile-0.4.0/src/imp/unix.rs:45          create_unix(path)
                                                                                                             ^~~~
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `tempfile`.

I'm not actually aware if this is supposed to work right now or not. This error was generated with:

cargo run --example hello-world

How to pass RustBox within threads?

I'd like to pass Rustbox within threads. I tried using the inbuilt std::thread as well as the crossbeam library but I seem to be running across the following error

the trait bound *mut (): std::marker::Sync is not satisfied in &rustbox::RustBox

I came across #65 which says

For sending the RustBox type between threads, you can now wrap it inside a std::sync::Mutex (which will implement Sync).

I've never worked with threads in Rust before so I am not sure how to initialize RustBox around a Mutex wrap and pass it between threads.

Can someone help me out with a minimal example?

x, y parameters are unsigned; C API has defined behavior for values under 0.

Since the C API has well defined behavior for values under 0 for the x,y coordinates, I feel like it's incorrect to place such a restriction on the Rust API via usize. Here's the relevant termbox code: https://github.com/nsf/termbox/blob/master/src/termbox.c#L226

void tb_put_cell(int x, int y, const struct tb_cell *cell)
{
    if ((unsigned)x >= (unsigned)back_buffer.width)
        return;
    if ((unsigned)y >= (unsigned)back_buffer.height)
        return;
    CELL(&back_buffer, x, y) = *cell;
}

This also would allow for print to be used offscreen and correctly clip the few first characters off screen without any funky splice logic.

Linking error when cross compiling

I want to compile my project using Rustbox for the Raspberry Pi (arm).

export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=../../tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
cargo build --target=armv7-unknown-linux-gnueabihf --verbose

When I do this, I get the following error:

error: linking with `${crossgcc}/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc` failed: exit code: 1
  |
  = note: "${crossgcc}/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-L" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1008l0s9nl4wm7th.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.12k7pgxoiobo1iii.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.19cqvc3dzrmeckjk.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1dvzg9oh1jegxabd.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1edz53dex3gqajxq.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1g2gfhp3sc5kx4s9.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1jymavqstc8ihg0r.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1kqd8dllyvsjajo9.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1ly4emdjih3g0vy6.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1ounnrf447udb9t1.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1rs7hfaj69qi537r.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1rxdrl96skzy32ec.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1svomfg85dl7lb45.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1xeve1e3ohjytfia.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.1yb8gfnya8mf08bc.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.215bizr89anbmt56.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.257zdolv8vxwuops.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2847d2cvyhjpm0ys.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2ba94v7nc96unz5v.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2izhkh3ouaj1c6gb.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2lpc7b4gprr5wsz8.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2mbpcea8v4ff0pmr.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2omhgqc9ig09t6zw.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2p3ixo1str5754ti.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2p7dkr4hm0qbrue9.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2rsg1snl3how4y34.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2t6q7k3mhmxfllso.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2ta8er23rs3dk4mq.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2txz1tmhx061upc8.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2u0p2e5a7vap77d0.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2vf7v8d5y0enpi4n.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2vwbsa7se25khwuc.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.2w1bdfkth1a1g5x0.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.32jcekf5j4rzdnf2.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.35ci1gqv93xhms71.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.39z6eogf3avg7tyh.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3aqlvpepwgxwohh5.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3dmdcpwnx9bb4ej0.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3i3rczevmdtsrojh.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3lg46efxlfmva0mp.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3o9xq77onssjtr0l.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3q8msmkkn3jnw688.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3r1kz7ohfkigdn08.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3sztj1nz2hw55aif.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3tau4qsfulrvzljs.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.3uosxaykpp5evipj.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.42agq16cf213sc0l.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.46kkuayemzs9rgmi.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.48gren5nft6hyn54.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4aqpjp2qd7a9ugeg.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4ct2q2t1qi4k50lr.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4d704zhphd8igsyk.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4gk14y7qn2pxlc61.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4h5vy7785hzz3xtf.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4i5r35mfbeu2ial9.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4mynvmntc9bgng23.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4qjhjiskf5m2pvry.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4rganp8vd3xlo27z.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4v3oltt9l1xfnj3o.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4wjwckitc9fijiqw.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4wv9rdl1zurxq14b.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4xly2jo9c8q5akmw.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4yaj4y9m26iqub5d.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.4z5gdwgyzyzsy1i9.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.536z3tn6hgtlyzxq.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.574b6yhsdljwfu3x.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.57zhllmpipv0nlqk.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.5a4dj8cgzx4wzxt9.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.5acclkpx9ttwgh21.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.5d3vl9z2yw5lxrlz.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.8ypo8iixyaykk49.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.9vaw0qfox3jry5m.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.emv05lcv863t0ae.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.jshjhe5d4jheoy4.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.ntcy8lpo8qxcr9j.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.q4brfjcbpwo8iv1.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.rofvvnesfz6hg21.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.t0bwea30jgemcjf.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.t2g1ujgh90zkmpc.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.up7amjnd935kwn5.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.uyj9d66axig7jyv.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.vkzygjqio102jzl.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.xie7dzd42e97sxt.rcgu.o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.zh5wbsm4cnebfed.rcgu.o" "-o" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/raspi_midi-bc8787688de306da.13s8rhl7je04dhdf.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps" "-L" "${projectdir}/target/debug/deps" "-L" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/build/termbox-sys-ae593235b9c54fee/out/lib" "-L" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib" "-Wl,-Bstatic" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtui-d1094482cf843bee.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libitertools-10b7cf24f1b4adea.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libeither-cdbe8cbd6ccc2258.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libbitflags-2c7b3e3d10e1e0dd.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libcassowary-12f30d1587272133.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libunicode_width-768fcc6a10e1b4fd.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libunicode_segmentation-0a12d9b320ac8e9a.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/liblog-5d8fea13e8566107.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtake_mut-e724a03909f2ee46.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtelnet-20e464814e44ab85.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/librustbox-9ede41e94e7b8119.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libbitflags-6e94fb97404a885e.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtermbox_sys-e359ea16b6845dd7.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libnum_traits-007e9378c9adbeb7.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libnum_traits-bebf719718549e64.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libgag-b9aa7658784435fe.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtempfile-ffb6a8fc89d37bc1.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/librand-be4d8af7e5be7a08.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/librand_chacha-5ee44d5402b96f96.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libc2_chacha-6c9603266c1ccdca.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libppv_lite86-f1ba3aff7c7b0810.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/liblazy_static-a80335916d5ac241.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/librand_core-cc812de9cd5d62d7.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libgetrandom-c2261ebb9275cc88.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libremove_dir_all-35bde33bb517195f.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libcfg_if-3aec7a461cb89471.rlib" "${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/liblibc-91546af03d20f85e.rlib" "-Wl,--start-group" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libstd-b806fbdf01014e64.rlib" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libpanic_unwind-765c392663bd34b7.rlib" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libbacktrace_sys-1059e0ba7f05fd67.rlib" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/librustc_demangle-85b43da92537c77f.rlib" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libunwind-f8a77019eff82b98.rlib" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/liblibc-1d32a47a0bdcb0a2.rlib" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/liballoc-c47e11e0b4c869e2.rlib" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/librustc_std_workspace_core-5a60e280b382f06e.rlib" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libcore-8010f7064010be9c.rlib" "-Wl,--end-group" "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libcompiler_builtins-566972fa63f867ee.rlib" "-Wl,-Bdynamic" "-lutil" "-lutil" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
  = note: ${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtermbox_sys-e359ea16b6845dd7.rlib: error adding symbols: File format not recognized
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: Could not compile `raspi-midi`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name raspi_midi src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=bc8787688de306da -C extra-filename=-bc8787688de306da --out-dir ${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps --target armv7-unknown-linux-gnueabihf -C linker=${crossgcc}/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -C incremental=${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/incremental -L dependency=${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps -L dependency=${projectdir}/target/debug/deps --extern jack=${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libjack-fe740c1a502d2c76.rlib --extern rustbox=${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/librustbox-9ede41e94e7b8119.rlib --extern take_mut=${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtake_mut-e724a03909f2ee46.rlib --extern telnet=${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtelnet-20e464814e44ab85.rlib --extern tui=${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/deps/libtui-d1094482cf843bee.rlib -L ${projectdir}/target/armv7-unknown-linux-gnueabihf/debug/build/termbox-sys-ae593235b9c54fee/out/lib` (exit code: 1)
  • Compiling locally works fine, both on the Pi and my PC
  • Cross-compiling works fine too as long as I don't use Rustbox

init dies without returning Err?

I am seeing rustbox::init die without returning Err. I'm not sure how this happens or why, but it happens when I run in a terminal over ssh. The difference may, however, be in the different computers rather than the ssh connection, since I can't test in person on the computer that has the trouble, since it's on the wrong side of the country.

You can (maybe) reproduce this problem by running:

git clone git://github.com/droundy/pmail
cd pmail
cargo build
target/debug/textmode-pmail

If it works properly ctrl-q enables you to exit. When it fails, it exits without blanking the screen, and leaves something like the following:

examining secret myself
Pmail starting! PublicKey([153, 3, 192, 37, 53, 25, 134, 237, 70, 201, 10, 3, 53, 138, 150, 133, 16, 141, 76, 3, 252, 140, 7, 171, 181, 238, 236, 64, 156, 188, 145, 58])
Initializing rustbox.
Wrote addressbook successfully!

The last line indicates that a local variable has been dropped, meaning that there seems to have been a relatively clean exit. But a println! inserted in the error path failed to be shown.

RAII guard should be unreverted for memory safety.

23b75fb says it removes the RAII guard because it believes it is no longer needed. This is incorrect; the RAII guard is required for memory safety, because otherwise there is nothing preventing two instances of rustbox from existing at the same time (and the comments in the file explain why this is the case). The current implementation is not memory safe, so the guard should be added back.

Accessing Cells

does rust-box have some sort of cell struct? If so how can I access it? Say if i'd like to get the cell at location (x,y), how would I go about doing that?

The example fails to compile.

The whole error is:

examples/hello-world.rs:29:38: 29:51 error: type `core::option::Option<rustbox::EventErrorKind::Error>` does not implement any method in scope named `description`
examples/hello-world.rs:29             Err(e) => panic!("{}", e.description()),
                                                                ^~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:9:1: 9:40 note: expansion site
<std macros>:1:1: 11:23 note: in expansion of panic!
examples/hello-world.rs:29:23: 29:52 note: expansion site
error: aborting due to previous error
Could not compile `rustbox`.

which can be temporarily fixed by:

diff --git a/examples/hello-world.rs b/examples/hello-world.rs
index d4b65e6..52a52ce 100644
--- a/examples/hello-world.rs
+++ b/examples/hello-world.rs
@@ -1,8 +1,5 @@
-#![feature(core)]
-
 extern crate rustbox;

-use std::error::Error;
 use std::default::Default;

 use rustbox::{Color, RustBox};
@@ -26,7 +23,7 @@ fn main() {
                     _ => { }
                 }
             },
-            Err(e) => panic!("{}", e.description()),
+            Err(e) => panic!("{:?}", e),
             _ => { }
         }
     }

using the Debug trait for Option<T>.

The rustc version is: rustc 1.1.0-nightly (c4b23aec4 2015-04-29) (built 2015-04-28)

I have looked into the source, and I have a (or two) question about InitError and InitErrorKind.
Is there rationale behind splitting those two? What is the purpose of #[repr(C, isize)]?

I am fairly new to Rust, but AFAIK #[repr(C)] is only needed if you need interoperability (which is not necessary in this case because Rustbox is currently a wrapper for Termbox).

Can't you just do like this:

#[derive(Debug)]
pub enum InitError {
    BufferStderrFailed(io::Error),
    AlreadyOpen,
    UnsupportedTerminal,
    FailedToOpenTTy,
    PipeTrapError,
    Other(isize),
}

impl fmt::Display for InitError { ... }

impl Error for InitError { ... }

impl FromPrimitive for InitError {
    // you can use `unwrap()` directly because it only returns Some(..)
    fn from_i64(n: i64) -> Option<InitError> {
        match n {
            -1 => Some(InitError::UnsupportedTerminal),
            -2 => Some(InitError::FailedToOpenTTy),
            -3 => Some(InitError::PipeTrapError),
            n => Some(Other(n as isize)),
        }
    }

    // can't convert from unsigned
    fn from_u64(n: u64) -> Option<InitError> {
        None
    }
}

You'd lose the benefit from using the enum_primitive macro, but you can tell the user what unknown error code the termbox gave.

Also, same applies to the EventError and EventErrorKind, which is quite conspicuous with "FIXME" label.

No FromPrimitive in std::num - does not compile on latest nightly

thiotimoline@scrith:~/github/rustbox$ cargo run --example hello-world
   Compiling rustbox v0.5.0 (file:///home/thiotimoline/github/rustbox)
src/rustbox.rs:18:5: 18:28 error: unresolved import `std::num::FromPrimitive`. There is no `FromPrimitive` in `std::num`
src/rustbox.rs:18 use std::num::FromPrimitive;
                      ^~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `rustbox`.

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

Build errors on latest rust nightly

   Compiling rustbox v0.2.9
/Users/sameerdhar/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbox-0.2.9/src/rustbox.rs:122:32: 122:37 error: explicit lifetime bound required
/Users/sameerdhar/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbox-0.2.9/src/rustbox.rs:122     Opt(InitOption, Option<Box<Error>>),
                                                                                                                                  ^~~~~
error: aborting due to previous error
Could not compile `rustbox`.
$[~] rustc --version                            
rustc 1.0.0-nightly (29bd9a06e 2015-01-20 23:03:09 +0000)

Shift+Tab capability

Hello. I am working on a project where the tab button navigates from control to control (defined as text boxes, and list selects). I'd like to implement shift+tab to do the opposite, like it works in browsers and most other graphical applications. However, the last time I attempted capturing shift+tab, it made it seem like 3 buttons were being pressed in sequence. None of them being shift or tab. Is this possible, or not really?

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.