Merge branch 'master'

This commit is contained in:
Alexandre Bury 2017-10-13 11:01:33 -07:00
commit 111d593f55
5 changed files with 17 additions and 10 deletions

View File

@ -83,7 +83,7 @@ fn phase_2(s: &mut Cursive) {
.map(|_| rand::thread_rng().gen_range(50, 150)) .map(|_| rand::thread_rng().gen_range(50, 150))
.collect(); .collect();
let n_max = 100000; let n_max = 100_000;
let cb = s.cb_sink().clone(); let cb = s.cb_sink().clone();
// Let's prepare the progress bars... // Let's prepare the progress bars...

View File

@ -31,11 +31,11 @@ fn find_closest(color: &Color) -> i16 {
Color::Light(BaseColor::Cyan) => 14, Color::Light(BaseColor::Cyan) => 14,
Color::Light(BaseColor::White) => 15, Color::Light(BaseColor::White) => 15,
Color::Rgb(r, g, b) => { Color::Rgb(r, g, b) => {
let r = 6 * r as u16 / 256; let r = 6 * u16::from(r) / 256;
let g = 6 * g as u16 / 256; let g = 6 * u16::from(g) / 256;
let b = 6 * b as u16 / 256; let b = 6 * u16::from(b) / 256;
(16 + 36 * r + 6 * g + b) as i16 (16 + 36 * r + 6 * g + b) as i16
} }
Color::RgbLowRes(r, g, b) => (16 + 36 * r + 6 * g + b) as i16, Color::RgbLowRes(r, g, b) => i16::from(16 + 36 * r + 6 * g + b),
} }
} }

View File

@ -24,7 +24,7 @@ impl Concrete {
&self, pairs: &mut HashMap<ColorPair, i16>, pair: ColorPair &self, pairs: &mut HashMap<ColorPair, i16>, pair: ColorPair
) -> i16 { ) -> i16 {
let n = 1 + pairs.len() as i16; let n = 1 + pairs.len() as i16;
let target = if ncurses::COLOR_PAIRS() > n as i32 { let target = if ncurses::COLOR_PAIRS() > i32::from(n) {
// We still have plenty of space for everyone. // We still have plenty of space for everyone.
n n
} else { } else {

View File

@ -26,7 +26,7 @@ where
let mut res = 0u32; let mut res = 0u32;
// First, get the data - only the few last bits // First, get the data - only the few last bits
res |= (first & make_mask(7 - n_bytes)) as u32; res |= u32::from(first & make_mask(7 - n_bytes));
// We already have one byte, now read the others. // We already have one byte, now read the others.
for _ in 1..n_bytes { for _ in 1..n_bytes {
@ -42,7 +42,7 @@ where
// We have 6 fresh new bits to read, make room. // We have 6 fresh new bits to read, make room.
res <<= 6; res <<= 6;
// 0x3F is 00111111, so we keep the last 6 bits // 0x3F is 00111111, so we keep the last 6 bits
res |= (byte & 0x3F) as u32; res |= u32::from(byte & 0x3F);
} }
// from_u32 could return an error if we gave it invalid utf-8. // from_u32 could return an error if we gave it invalid utf-8.

View File

@ -12,6 +12,13 @@ use utils::{simple_prefix, simple_suffix};
use vec::Vec2; use vec::Vec2;
use view::View; use view::View;
/// closure type for callbacks when the content is modified. Arguments are the
/// `Cursive`, current content of the input and cursor position
pub type OnEdit = Fn(&mut Cursive, &str, usize);
/// closure type for callbacks when Enter is pressed. Arguments are the `Cursive`
/// and the content of the input.
pub type OnSubmit = Fn(&mut Cursive, &str);
/// Input box where the user can enter and edit text. /// Input box where the user can enter and edit text.
/// ///
@ -74,10 +81,10 @@ pub struct EditView {
/// Callback when the content is modified. /// Callback when the content is modified.
/// ///
/// Will be called with the current content and the cursor position. /// Will be called with the current content and the cursor position.
on_edit: Option<Rc<Fn(&mut Cursive, &str, usize)>>, on_edit: Option<Rc<OnEdit>>,
/// Callback when <Enter> is pressed. /// Callback when <Enter> is pressed.
on_submit: Option<Rc<Fn(&mut Cursive, &str)>>, on_submit: Option<Rc<OnSubmit>>,
/// When `true`, only print `*` instead of the true content. /// When `true`, only print `*` instead of the true content.
secret: bool, secret: bool,