Skip to content

Commit

Permalink
Update to bitflags 1.
Browse files Browse the repository at this point in the history
This is a breaking change and makes this crate now require Rust 1.20
or later.
  • Loading branch information
waywardmonkeys committed Mar 22, 2018
1 parent cf1d081 commit b18992b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions examples/hello-256-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions examples/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
Expand Down
44 changes: 20 additions & 24 deletions src/rustbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::cell::UnsafeCell;
use std::error::Error;
use std::fmt;
Expand Down Expand Up @@ -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() }
}
}

Expand Down Expand Up @@ -435,13 +431,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);
}
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit b18992b

Please sign in to comment.