Skip to content

Commit d4c0545

Browse files
Update to bitflags 1.
This is a breaking change and makes this crate now require Rust 1.20 or later.
1 parent 7d82dac commit d4c0545

File tree

5 files changed

+30
-34
lines changed

5 files changed

+30
-34
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ exclude = [
2020
name = "rustbox"
2121

2222
[dependencies]
23-
bitflags = "0.2.1"
23+
bitflags = "1"
2424
termbox-sys = "0.2.9"
2525
gag = "0.1.6"
2626
num-traits = "0.1.13"

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern crate rustbox;
3535
use std::error::Error;
3636
use std::default::Default;
3737

38-
use rustbox::{Color, RustBox};
38+
use rustbox::{Color, RustBox, Style};
3939
use rustbox::Key;
4040

4141
fn main() {
@@ -44,8 +44,8 @@ fn main() {
4444
Result::Err(e) => panic!("{}", e),
4545
};
4646

47-
rustbox.print(1, 1, rustbox::RB_BOLD, Color::White, Color::Black, "Hello, world!");
48-
rustbox.print(1, 3, rustbox::RB_BOLD, Color::White, Color::Black,
47+
rustbox.print(1, 1, Style::RB_BOLD, Color::White, Color::Black, "Hello, world!");
48+
rustbox.print(1, 3, Style::RB_BOLD, Color::White, Color::Black,
4949
"Press 'q' to quit.");
5050
rustbox.present();
5151
loop {

examples/hello-256-world.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate rustbox;
22

33
use std::default::Default;
44

5-
use rustbox::{Color, RustBox, OutputMode};
5+
use rustbox::{Color, RustBox, OutputMode, Style};
66
use rustbox::Key;
77

88
fn main() {
@@ -12,8 +12,8 @@ fn main() {
1212
};
1313
rustbox.set_output_mode(OutputMode::EightBit);
1414

15-
rustbox.print(1, 1, rustbox::RB_BOLD, Color::Byte(0xa2), Color::Black, "Hello, world!");
16-
rustbox.print(1, 3, rustbox::RB_NORMAL, Color::Black, Color::Byte(0x9a), "Press 'q' to quit.");
15+
rustbox.print(1, 1, Style::RB_BOLD, Color::Byte(0xa2), Color::Black, "Hello, world!");
16+
rustbox.print(1, 3, Style::RB_NORMAL, Color::Black, Color::Byte(0x9a), "Press 'q' to quit.");
1717
loop {
1818
rustbox.present();
1919
match rustbox.poll_event(false) {

examples/hello-world.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate rustbox;
22

33
use std::default::Default;
44

5-
use rustbox::{Color, RustBox};
5+
use rustbox::{Color, RustBox, Style};
66
use rustbox::Key;
77

88
fn main() {
@@ -11,8 +11,8 @@ fn main() {
1111
Result::Err(e) => panic!("{}", e),
1212
};
1313

14-
rustbox.print(1, 1, rustbox::RB_BOLD, Color::White, Color::Black, "Hello, world!");
15-
rustbox.print(1, 3, rustbox::RB_BOLD, Color::White, Color::Black,
14+
rustbox.print(1, 1, Style::RB_BOLD, Color::White, Color::Black, "Hello, world!");
15+
rustbox.print(1, 3, Style::RB_BOLD, Color::White, Color::Black,
1616
"Press 'q' to quit.");
1717
loop {
1818
rustbox.present();

src/rustbox.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ extern crate num_traits;
33
extern crate termbox_sys as termbox;
44
#[macro_use] extern crate bitflags;
55

6-
pub use self::style::{Style, RB_BOLD, RB_UNDERLINE, RB_REVERSE, RB_NORMAL};
7-
86
use std::error::Error;
97
use std::fmt;
108
use std::io;
@@ -112,27 +110,25 @@ impl Default for Color {
112110
}
113111
}
114112

115-
mod style {
116-
bitflags! {
117-
#[repr(C)]
118-
flags Style: u16 {
119-
const TB_NORMAL_COLOR = 0x000F,
120-
const RB_BOLD = 0x0100,
121-
const RB_UNDERLINE = 0x0200,
122-
const RB_REVERSE = 0x0400,
123-
const RB_NORMAL = 0x0000,
124-
const TB_ATTRIB = RB_BOLD.bits | RB_UNDERLINE.bits | RB_REVERSE.bits,
125-
}
113+
bitflags! {
114+
#[repr(C)]
115+
pub struct Style: u16 {
116+
const TB_NORMAL_COLOR = 0x000F;
117+
const RB_BOLD = 0x0100;
118+
const RB_UNDERLINE = 0x0200;
119+
const RB_REVERSE = 0x0400;
120+
const RB_NORMAL = 0x0000;
121+
const TB_ATTRIB = Style::RB_BOLD.bits | Style::RB_UNDERLINE.bits | Style::RB_REVERSE.bits;
126122
}
123+
}
127124

128-
impl Style {
129-
pub fn from_color(color: super::Color) -> Style {
130-
Style { bits: color.as_16color() & TB_NORMAL_COLOR.bits }
131-
}
125+
impl Style {
126+
pub fn from_color(color: Color) -> Style {
127+
Style { bits: color.as_16color() & Style::TB_NORMAL_COLOR.bits }
128+
}
132129

133-
pub fn from_256color(color: super::Color) -> Style {
134-
Style { bits: color.as_256color() }
135-
}
130+
pub fn from_256color(color: Color) -> Style {
131+
Style { bits: color.as_256color() }
136132
}
137133
}
138134

@@ -460,13 +456,13 @@ impl RustBox {
460456
match self.output_mode {
461457
// 256 color mode
462458
OutputMode::EightBit => {
463-
fg_int = Style::from_256color(fg) | (sty & style::TB_ATTRIB);
459+
fg_int = Style::from_256color(fg) | (sty & Style::TB_ATTRIB);
464460
bg_int = Style::from_256color(bg);
465461
},
466462

467463
// 16 color mode
468464
_ => {
469-
fg_int = Style::from_color(fg) | (sty & style::TB_ATTRIB);
465+
fg_int = Style::from_color(fg) | (sty & Style::TB_ATTRIB);
470466
bg_int = Style::from_color(bg);
471467
}
472468
}
@@ -487,13 +483,13 @@ impl RustBox {
487483
match self.output_mode {
488484
// 256 color mode
489485
OutputMode::EightBit => {
490-
fg_int = Style::from_256color(fg) | (sty & style::TB_ATTRIB);
486+
fg_int = Style::from_256color(fg) | (sty & Style::TB_ATTRIB);
491487
bg_int = Style::from_256color(bg);
492488
},
493489

494490
// 16 color mode
495491
_ => {
496-
fg_int = Style::from_color(fg) | (sty & style::TB_ATTRIB);
492+
fg_int = Style::from_color(fg) | (sty & Style::TB_ATTRIB);
497493
bg_int = Style::from_color(bg);
498494
}
499495
}

0 commit comments

Comments
 (0)