diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/db/cards.rs | 1 | ||||
-rw-r--r-- | src/gui/message.rs | 2 | ||||
-rw-r--r-- | src/gui/question.rs | 7 | ||||
-rw-r--r-- | src/model/mod.rs | 1 | ||||
-rw-r--r-- | src/parser.rs | 20 | ||||
-rw-r--r-- | src/space_repetition.rs | 8 |
6 files changed, 14 insertions, 25 deletions
diff --git a/src/db/cards.rs b/src/db/cards.rs index 6d3e28d..709e4eb 100644 --- a/src/db/cards.rs +++ b/src/db/cards.rs @@ -109,7 +109,6 @@ pub fn pick_random_ready(conn: &Connection) -> Option<Card> { question: row.get(0).ok()?, responses: serialization::line_to_words(&responses_str), state: serde_json::from_str(&state_str).ok()?, - ready: row.get(3).ok()?, }) } diff --git a/src/gui/message.rs b/src/gui/message.rs index 61f57ba..3273b31 100644 --- a/src/gui/message.rs +++ b/src/gui/message.rs @@ -20,7 +20,7 @@ pub fn show<B: Backend>( .direction(Direction::Vertical) .margin(2) .constraints([Constraint::Length(1), Constraint::Percentage(50)].as_ref()) - .split(f.size()); + .split(f.area()); let d1 = util::title(title); f.render_widget(d1, chunks[0]); diff --git a/src/gui/question.rs b/src/gui/question.rs index 512ca49..2a42e57 100644 --- a/src/gui/question.rs +++ b/src/gui/question.rs @@ -50,7 +50,7 @@ pub fn ask<B: Backend>(terminal: &mut Terminal<B>, title: &str, card: &Card) -> ] .as_ref(), ) - .split(f.size()); + .split(f.area()); let d1 = util::title(title); f.render_widget(d1, chunks[0]); @@ -232,10 +232,7 @@ fn remove_whitespaces(input: &str) -> String { } fn remove_indications_and_phonetics(response: &str) -> &str { - response - .split(|c| c == '(' || c == '[') - .collect::<Vec<&str>>()[0] - .trim() + response.split(['(', '[']).collect::<Vec<&str>>()[0].trim() } fn extract_phonetics(response: &str) -> Option<String> { diff --git a/src/model/mod.rs b/src/model/mod.rs index 4df4c49..6451e76 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -19,7 +19,6 @@ pub struct Card { pub question: String, pub responses: Vec<String>, pub state: space_repetition::State, - pub ready: u64, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/src/parser.rs b/src/parser.rs index 09b3121..62c4d99 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -6,7 +6,7 @@ use nom::{ error::{Error, ErrorKind}, multi::separated_list1, sequence::delimited, - IResult, + IResult, Parser, }; // Temporary API @@ -14,7 +14,7 @@ use nom::{ pub fn parse_line(s: &str) -> IResult<&str, Option<Line>> { let (s, _) = space0(s)?; - let (s, line) = opt(parse_parts)(s)?; + let (s, line) = opt(parse_parts).parse(s)?; let (s, _) = parse_end_of_line(s)?; Ok((s, line)) } @@ -29,14 +29,14 @@ fn parse_parts(s: &str) -> IResult<&str, Line> { // Rest fn parse_options(s: &str) -> IResult<&str, Vec<String>> { - separated_list1(sep('|'), parse_term)(s) + separated_list1(sep('|'), parse_term).parse(s) } pub fn parse_term(s: &str) -> IResult<&str, String> { let mut term = String::from(""); let mut s = s; - while let Ok((_, c)) = peek(take::<usize, &str, ()>(1_usize))(s) { + while let Ok((_, c)) = peek(take::<usize, &str, ()>(1_usize)).parse(s) { if c == "[" { let (s1, cs) = take_until("]")(s)?; s = s1; @@ -66,7 +66,7 @@ pub fn parse_term(s: &str) -> IResult<&str, String> { fn parse_end_of_line(s: &str) -> IResult<&str, ()> { let (s, _) = space0(s)?; - let (s, _) = opt(parse_comment)(s)?; + let (s, _) = opt(parse_comment).parse(s)?; Ok((s, ())) } @@ -80,7 +80,7 @@ fn parse_comment(s: &str) -> IResult<&str, ()> { pub fn sep(c: char) -> impl FnMut(&str) -> IResult<&str, ()> { move |s: &str| { - let (s, _) = delimited(space0, char(c), space0)(s)?; + let (s, _) = delimited(space0, char(c), space0).parse(s)?; Ok((s, ())) } } @@ -94,19 +94,19 @@ mod tests { use nom::{character::complete::newline, multi::many0}; fn parse(s: &str) -> IResult<&str, Vec<Line>> { - let (s, lines) = many0(parse_next)(s)?; - let (s, _) = many0(parse_empty_line)(s)?; + let (s, lines) = many0(parse_next).parse(s)?; + let (s, _) = many0(parse_empty_line).parse(s)?; Ok((s, lines)) } fn parse_next(s: &str) -> IResult<&str, Line> { - let (s, _) = many0(parse_empty_line)(s)?; + let (s, _) = many0(parse_empty_line).parse(s)?; let (s, _) = space0(s)?; let (s, part_1) = parse_options(s)?; let (s, _) = sep(':')(s)?; let (s, part_2) = parse_options(s)?; let (s, _) = parse_end_of_line(s)?; - let (s, _) = opt(newline)(s)?; + let (s, _) = opt(newline).parse(s)?; Ok((s, Line { part_1, part_2 })) } diff --git a/src/space_repetition.rs b/src/space_repetition.rs index e2ab382..c9b315c 100644 --- a/src/space_repetition.rs +++ b/src/space_repetition.rs @@ -148,13 +148,7 @@ fn clamp_ease(f: f32) -> f32 { } fn clamp_interval(i: f32) -> f32 { - if i < INTERVAL_MIN { - INTERVAL_MIN - } else if i > INTERVAL_MAX { - INTERVAL_MAX - } else { - i - } + i.clamp(INTERVAL_MIN, INTERVAL_MAX) } #[cfg(test)] |