From a17d46fe375132ab332842178b82545d6d45671f Mon Sep 17 00:00:00 2001 From: Jay Randez Date: Fri, 26 Jun 2015 02:40:33 -0400 Subject: [PATCH 1/8] [Broken] Moving C binding implementation into separate directory. --- src/{ => rustbox-c}/keyboard.rs | 0 src/{ => rustbox-c}/mouse.rs | 0 src/{ => rustbox-c}/rustbox.rs | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/{ => rustbox-c}/keyboard.rs (100%) rename src/{ => rustbox-c}/mouse.rs (100%) rename src/{ => rustbox-c}/rustbox.rs (100%) diff --git a/src/keyboard.rs b/src/rustbox-c/keyboard.rs similarity index 100% rename from src/keyboard.rs rename to src/rustbox-c/keyboard.rs diff --git a/src/mouse.rs b/src/rustbox-c/mouse.rs similarity index 100% rename from src/mouse.rs rename to src/rustbox-c/mouse.rs diff --git a/src/rustbox.rs b/src/rustbox-c/rustbox.rs similarity index 100% rename from src/rustbox.rs rename to src/rustbox-c/rustbox.rs From e764c7ab98dc589e8e9419c7ced42cdd1d98296b Mon Sep 17 00:00:00 2001 From: Jay Randez Date: Fri, 26 Jun 2015 02:41:15 -0400 Subject: [PATCH 2/8] [Broken] Renaming "rustbox.rs" to "mod.rs" by convention. --- src/rustbox-c/{rustbox.rs => mod.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/rustbox-c/{rustbox.rs => mod.rs} (100%) diff --git a/src/rustbox-c/rustbox.rs b/src/rustbox-c/mod.rs similarity index 100% rename from src/rustbox-c/rustbox.rs rename to src/rustbox-c/mod.rs From 88beb21041ee31690d8e2bcfa8585aaff03a2b71 Mon Sep 17 00:00:00 2001 From: Jay Randez Date: Fri, 26 Jun 2015 02:45:33 -0400 Subject: [PATCH 3/8] [Fixed] C binding implementation works from separate directory. --- src/lib.rs | 20 ++++++++++++++++++++ src/rustbox-c/mod.rs | 45 ++++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 src/lib.rs diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..15b336e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,20 @@ +#![feature(libc)] +#![feature(optin_builtin_traits)] + +extern crate gag; +extern crate libc; +extern crate num; +extern crate time; + +#[macro_use] +extern crate bitflags; + +pub use rustbox::*; + +#[cfg(all(target_os="linux"))] +#[path="rustbox-c/mod.rs"] +pub mod rustbox; + +#[cfg(all(target_os="macos"))] +#[path="rustbox-c/mod.rs"] +pub mod rustbox; diff --git a/src/rustbox-c/mod.rs b/src/rustbox-c/mod.rs index 34b893e..10e2d24 100644 --- a/src/rustbox-c/mod.rs +++ b/src/rustbox-c/mod.rs @@ -1,34 +1,24 @@ -#![feature(libc)] -#![feature(optin_builtin_traits)] - -extern crate gag; -extern crate libc; -extern crate num; -extern crate time; extern crate termbox_sys as termbox; -#[macro_use] extern crate bitflags; +pub mod keyboard; +pub mod mouse; + +pub use self::keyboard::Key; +pub use self::mouse::Mouse; +pub use self::running::running; pub use self::style::{Style, RB_BOLD, RB_UNDERLINE, RB_REVERSE, RB_NORMAL}; -use std::error::Error; -use std::fmt; -use std::io; -use std::char; +use self::termbox::RawEvent; + use std::default::Default; +use std::error::Error; +use std::{fmt, io, char}; use num::FromPrimitive; -use termbox::RawEvent; use libc::c_int; use gag::Hold; use time::Duration; -pub mod keyboard; -pub mod mouse; - -pub use self::running::running; -pub use keyboard::Key; -pub use mouse::Mouse; - #[derive(Clone, Copy)] pub enum Event { KeyEventRaw(u8, u16, u32), @@ -356,16 +346,25 @@ impl RustBox { unsafe { termbox::tb_set_cursor(x as c_int, y as c_int) } } - pub unsafe fn change_cell(&self, x: usize, y: usize, ch: u32, fg: u16, bg: u16) { + unsafe fn change_cell_internal(&self, x: usize, y: usize, ch: u32, fg: u16, bg: u16) { termbox::tb_change_cell(x as c_int, y as c_int, ch, fg, bg) } + pub fn change_cell(&self, x:usize, y:usize, ch:char, fg:Color, bg:Color, sty:Style) + { + let fg = Style::from_color(fg) | (sty & style::TB_ATTRIB); + let bg = Style::from_color(bg); + unsafe { + self.change_cell_internal(x, y, ch as u32, fg.bits(), bg.bits()); + } + } + pub fn print(&self, x: usize, y: usize, sty: Style, fg: Color, bg: Color, s: &str) { let fg = Style::from_color(fg) | (sty & style::TB_ATTRIB); let bg = Style::from_color(bg); for (i, ch) in s.chars().enumerate() { unsafe { - self.change_cell(x+i, y, ch as u32, fg.bits(), bg.bits()); + self.change_cell_internal(x+i, y, ch as u32, fg.bits(), bg.bits()); } } } @@ -374,7 +373,7 @@ impl RustBox { let fg = Style::from_color(fg) | (sty & style::TB_ATTRIB); let bg = Style::from_color(bg); unsafe { - self.change_cell(x, y, ch as u32, fg.bits(), bg.bits()); + self.change_cell_internal(x, y, ch as u32, fg.bits(), bg.bits()); } } From b1735b4150b7942738b9b6d881abe9a347bdc707 Mon Sep 17 00:00:00 2001 From: Jay Randez Date: Fri, 26 Jun 2015 04:31:50 -0400 Subject: [PATCH 4/8] Added windows-breaking "termbox-sys", "gag" to cargo default (optional) dependencies. --- Cargo.toml | 25 ++++++++++++++----------- src/lib.rs | 1 - src/rustbox-c/mod.rs | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c541dc9..1db3a7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,26 +2,29 @@ name = "rustbox" version = "0.6.2" authors = ["Greg Chapple "] -description = "A rust implementation of the termbox library" +description = "A Rust implementation of the Termbox library." repository = "https://github.com/gchp/rustbox" homepage = "https://github.com/gchp/rustbox" readme = "README.md" license = "MIT" -keywords = [ - "termbox", - "terminal", - "gui", -] -exclude = [ - "examples/*" -] +keywords = ["termbox", "terminal", "gui",] +exclude = ["examples/*"] [lib] name = "rustbox" +[features] +default = ["termbox-sys", "gag"] + [dependencies] bitflags = "0.2.1" -termbox-sys = "0.2.7" -gag = "0.1.6" num = "*" time = "*" + +[dependencies.termbox-sys] +version = "0.2.7" +optional = true + +[dependencies.gag] +version = "0.1.6" +optional = true diff --git a/src/lib.rs b/src/lib.rs index 15b336e..bf970a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![feature(libc)] #![feature(optin_builtin_traits)] -extern crate gag; extern crate libc; extern crate num; extern crate time; diff --git a/src/rustbox-c/mod.rs b/src/rustbox-c/mod.rs index 10e2d24..53e72c5 100644 --- a/src/rustbox-c/mod.rs +++ b/src/rustbox-c/mod.rs @@ -1,4 +1,5 @@ extern crate termbox_sys as termbox; +extern crate gag; pub mod keyboard; pub mod mouse; @@ -9,14 +10,13 @@ pub use self::running::running; pub use self::style::{Style, RB_BOLD, RB_UNDERLINE, RB_REVERSE, RB_NORMAL}; use self::termbox::RawEvent; +use self::gag::Hold; use std::default::Default; use std::error::Error; use std::{fmt, io, char}; - use num::FromPrimitive; use libc::c_int; -use gag::Hold; use time::Duration; #[derive(Clone, Copy)] From fb379f29792053baab05a475a883342303b3c79d Mon Sep 17 00:00:00 2001 From: Jay Randez Date: Fri, 26 Jun 2015 05:09:46 -0400 Subject: [PATCH 5/8] Using Cargo target dependencies instead. --- Cargo.toml | 14 +++++--------- src/lib.rs | 4 ++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1db3a7d..68c5bfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,18 +13,14 @@ exclude = ["examples/*"] [lib] name = "rustbox" -[features] -default = ["termbox-sys", "gag"] - [dependencies] bitflags = "0.2.1" num = "*" time = "*" -[dependencies.termbox-sys] -version = "0.2.7" -optional = true +[target.x86_64-unknown-linux-gnu.dependencies] +termbox-sys = "0.2.7" +gag = "0.1.6" -[dependencies.gag] -version = "0.1.6" -optional = true +[target.x86_64-pc-windows-gnu.dependencies] +somethingfake = "0.1.1" diff --git a/src/lib.rs b/src/lib.rs index bf970a8..2bb7db0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,3 +17,7 @@ pub mod rustbox; #[cfg(all(target_os="macos"))] #[path="rustbox-c/mod.rs"] pub mod rustbox; + +#[cfg(all(target_os="windows"))] +#[path="rustbox-pure/mod.rs"] +pub mod rustbox; From d0478246b5b752e72d26b1d62168f13bc11ae135 Mon Sep 17 00:00:00 2001 From: Jay Randez Date: Fri, 26 Jun 2015 05:24:20 -0400 Subject: [PATCH 6/8] Adding dependencies for Windows implementation --- Cargo.toml | 11 ++++++++++- src/rustbox-pure/mod.rs | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/rustbox-pure/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 68c5bfd..a3357b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,18 @@ bitflags = "0.2.1" num = "*" time = "*" +[target.i686-unknown-linux-gnu.dependencies] +termbox-sys = "0.2.7" +gag = "0.1.6" + [target.x86_64-unknown-linux-gnu.dependencies] termbox-sys = "0.2.7" gag = "0.1.6" +[target.i686-pc-windows-gnu.dependencies] +winapi = "*" +kernel32-sys = "*" + [target.x86_64-pc-windows-gnu.dependencies] -somethingfake = "0.1.1" +winapi = "*" +kernel32-sys = "*" diff --git a/src/rustbox-pure/mod.rs b/src/rustbox-pure/mod.rs new file mode 100644 index 0000000..a35b4d7 --- /dev/null +++ b/src/rustbox-pure/mod.rs @@ -0,0 +1,2 @@ +extern crate winapi; +extern crate kernel32; From c3c085cae88475f8d67f4f3a4704b9bb83b0dceb Mon Sep 17 00:00:00 2001 From: Jay Randez Date: Fri, 26 Jun 2015 05:56:44 -0400 Subject: [PATCH 7/8] Target triple for OS-X I think... Can't Test. --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index a3357b4..4144a99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,10 @@ gag = "0.1.6" termbox-sys = "0.2.7" gag = "0.1.6" +[target.x86_64-apple-darwin.dependencies] +termbox-sys = "0.2.7" +gag = "0.1.6" + [target.i686-pc-windows-gnu.dependencies] winapi = "*" kernel32-sys = "*" From 2633fa0696e3cc46a5ff45ac85f3f8940b694320 Mon Sep 17 00:00:00 2001 From: Jay Randez Date: Fri, 26 Jun 2015 06:13:49 -0400 Subject: [PATCH 8/8] Revert modifications to linux API to GCHP's original. --- src/rustbox-c/mod.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/rustbox-c/mod.rs b/src/rustbox-c/mod.rs index 53e72c5..3ffdb21 100644 --- a/src/rustbox-c/mod.rs +++ b/src/rustbox-c/mod.rs @@ -346,25 +346,16 @@ impl RustBox { unsafe { termbox::tb_set_cursor(x as c_int, y as c_int) } } - unsafe fn change_cell_internal(&self, x: usize, y: usize, ch: u32, fg: u16, bg: u16) { + pub unsafe fn change_cell(&self, x: usize, y: usize, ch: u32, fg: u16, bg: u16) { termbox::tb_change_cell(x as c_int, y as c_int, ch, fg, bg) } - pub fn change_cell(&self, x:usize, y:usize, ch:char, fg:Color, bg:Color, sty:Style) - { - let fg = Style::from_color(fg) | (sty & style::TB_ATTRIB); - let bg = Style::from_color(bg); - unsafe { - self.change_cell_internal(x, y, ch as u32, fg.bits(), bg.bits()); - } - } - pub fn print(&self, x: usize, y: usize, sty: Style, fg: Color, bg: Color, s: &str) { let fg = Style::from_color(fg) | (sty & style::TB_ATTRIB); let bg = Style::from_color(bg); for (i, ch) in s.chars().enumerate() { unsafe { - self.change_cell_internal(x+i, y, ch as u32, fg.bits(), bg.bits()); + self.change_cell(x+i, y, ch as u32, fg.bits(), bg.bits()); } } } @@ -373,7 +364,7 @@ impl RustBox { let fg = Style::from_color(fg) | (sty & style::TB_ATTRIB); let bg = Style::from_color(bg); unsafe { - self.change_cell_internal(x, y, ch as u32, fg.bits(), bg.bits()); + self.change_cell(x, y, ch as u32, fg.bits(), bg.bits()); } }