From d4c0545f78562b19e8faea7c5f4002f8ecc87f4e Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Thu, 22 Mar 2018 21:44:51 +0700 Subject: [PATCH 1/2] Update to bitflags 1. This is a breaking change and makes this crate now require Rust 1.20 or later. --- Cargo.toml | 2 +- README.md | 6 ++--- examples/hello-256-world.rs | 6 ++--- examples/hello-world.rs | 6 ++--- src/rustbox.rs | 44 +++++++++++++++++-------------------- 5 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a308bc6..ed699f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ exclude = [ name = "rustbox" [dependencies] -bitflags = "0.2.1" +bitflags = "1" termbox-sys = "0.2.9" gag = "0.1.6" num-traits = "0.1.13" diff --git a/README.md b/README.md index 22b0fff..0d9fef8 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ extern crate rustbox; use std::error::Error; use std::default::Default; -use rustbox::{Color, RustBox}; +use rustbox::{Color, RustBox, Style}; use rustbox::Key; fn main() { @@ -44,8 +44,8 @@ fn main() { 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, + rustbox.print(1, 1, Style::RB_BOLD, Color::White, Color::Black, "Hello, world!"); + rustbox.print(1, 3, Style::RB_BOLD, Color::White, Color::Black, "Press 'q' to quit."); rustbox.present(); loop { diff --git a/examples/hello-256-world.rs b/examples/hello-256-world.rs index 3888f95..0c5fae1 100644 --- a/examples/hello-256-world.rs +++ b/examples/hello-256-world.rs @@ -2,7 +2,7 @@ extern crate rustbox; use std::default::Default; -use rustbox::{Color, RustBox, OutputMode}; +use rustbox::{Color, RustBox, OutputMode, Style}; use rustbox::Key; fn main() { @@ -12,8 +12,8 @@ fn main() { }; rustbox.set_output_mode(OutputMode::EightBit); - rustbox.print(1, 1, rustbox::RB_BOLD, Color::Byte(0xa2), Color::Black, "Hello, world!"); - rustbox.print(1, 3, rustbox::RB_NORMAL, Color::Black, Color::Byte(0x9a), "Press 'q' to quit."); + rustbox.print(1, 1, Style::RB_BOLD, Color::Byte(0xa2), Color::Black, "Hello, world!"); + rustbox.print(1, 3, Style::RB_NORMAL, Color::Black, Color::Byte(0x9a), "Press 'q' to quit."); loop { rustbox.present(); match rustbox.poll_event(false) { diff --git a/examples/hello-world.rs b/examples/hello-world.rs index 06885cc..5ba33b5 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -2,7 +2,7 @@ extern crate rustbox; use std::default::Default; -use rustbox::{Color, RustBox}; +use rustbox::{Color, RustBox, Style}; use rustbox::Key; fn main() { @@ -11,8 +11,8 @@ fn main() { 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, + rustbox.print(1, 1, Style::RB_BOLD, Color::White, Color::Black, "Hello, world!"); + rustbox.print(1, 3, Style::RB_BOLD, Color::White, Color::Black, "Press 'q' to quit."); loop { rustbox.present(); diff --git a/src/rustbox.rs b/src/rustbox.rs index 23f1fac..388366f 100644 --- a/src/rustbox.rs +++ b/src/rustbox.rs @@ -3,8 +3,6 @@ extern crate num_traits; extern crate termbox_sys as termbox; #[macro_use] extern crate bitflags; -pub use self::style::{Style, RB_BOLD, RB_UNDERLINE, RB_REVERSE, RB_NORMAL}; - use std::error::Error; use std::fmt; use std::io; @@ -112,27 +110,25 @@ impl Default for Color { } } -mod style { - bitflags! { - #[repr(C)] - flags Style: u16 { - const TB_NORMAL_COLOR = 0x000F, - const RB_BOLD = 0x0100, - const RB_UNDERLINE = 0x0200, - const RB_REVERSE = 0x0400, - const RB_NORMAL = 0x0000, - const TB_ATTRIB = RB_BOLD.bits | RB_UNDERLINE.bits | RB_REVERSE.bits, - } +bitflags! { + #[repr(C)] + pub struct Style: u16 { + const TB_NORMAL_COLOR = 0x000F; + const RB_BOLD = 0x0100; + const RB_UNDERLINE = 0x0200; + const RB_REVERSE = 0x0400; + const RB_NORMAL = 0x0000; + const TB_ATTRIB = Style::RB_BOLD.bits | Style::RB_UNDERLINE.bits | Style::RB_REVERSE.bits; } +} - impl Style { - pub fn from_color(color: super::Color) -> Style { - Style { bits: color.as_16color() & TB_NORMAL_COLOR.bits } - } +impl Style { + pub fn from_color(color: Color) -> Style { + Style { bits: color.as_16color() & Style::TB_NORMAL_COLOR.bits } + } - pub fn from_256color(color: super::Color) -> Style { - Style { bits: color.as_256color() } - } + pub fn from_256color(color: Color) -> Style { + Style { bits: color.as_256color() } } } @@ -460,13 +456,13 @@ impl RustBox { match self.output_mode { // 256 color mode OutputMode::EightBit => { - fg_int = Style::from_256color(fg) | (sty & style::TB_ATTRIB); + fg_int = Style::from_256color(fg) | (sty & Style::TB_ATTRIB); bg_int = Style::from_256color(bg); }, // 16 color mode _ => { - fg_int = Style::from_color(fg) | (sty & style::TB_ATTRIB); + fg_int = Style::from_color(fg) | (sty & Style::TB_ATTRIB); bg_int = Style::from_color(bg); } } @@ -487,13 +483,13 @@ impl RustBox { match self.output_mode { // 256 color mode OutputMode::EightBit => { - fg_int = Style::from_256color(fg) | (sty & style::TB_ATTRIB); + fg_int = Style::from_256color(fg) | (sty & Style::TB_ATTRIB); bg_int = Style::from_256color(bg); }, // 16 color mode _ => { - fg_int = Style::from_color(fg) | (sty & style::TB_ATTRIB); + fg_int = Style::from_color(fg) | (sty & Style::TB_ATTRIB); bg_int = Style::from_color(bg); } } From ecd78a260531ad7801c866f49d07156b5fceeb61 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Thu, 22 Mar 2018 21:47:17 +0700 Subject: [PATCH 2/2] Update to num-traits 0.2. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ed699f3..bcdf523 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,4 @@ name = "rustbox" bitflags = "1" termbox-sys = "0.2.9" gag = "0.1.6" -num-traits = "0.1.13" +num-traits = "0.2"