Skip to content

Commit

Permalink
Add the command tnew toggling whether only new cards should be shown.
Browse files Browse the repository at this point in the history
  • Loading branch information
ticki committed Apr 8, 2020
1 parent 9318f2d commit 79d055a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ You can then run `mkmu`, which crawls directories (and subdirectories) and
compiles the TeX files using the `latexmk` build tool. The resulting files are
placed in the `deck` directory.

You can then `cd` into `deck` and run `mu`, which starts `mu`, entering into a
shell-like problem that looks like this (run `help` to see list of commands):
You can then run `mu` in the directory containing the `deck/` directory, which starts `mu`, entering
into a shell-like problem that looks like this (run `help` to see list of commands):

——— card 'grassmanian' ———
file: grassmanian.pdf
Expand Down
10 changes: 8 additions & 2 deletions backend/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ pub struct Scheduler {
/// This is supposed to reflect the number of cards in `self.queue` whose scheduled time is
/// prior to the current point in time.
due: usize,
/// Should we prefer new cards?
///
/// When this is set to `true`, the scheduler will yield cards from the new queue whenever
/// possible.
pub prefer_new: bool,
}

impl Scheduler {
Expand Down Expand Up @@ -244,6 +249,7 @@ impl Scheduler {
current_card: !0,
queue,
due: 0,
prefer_new: false,
};

// Populate the new cards queue with the new cards from today, that are not studied yet.
Expand Down Expand Up @@ -323,8 +329,8 @@ impl Scheduler {
let new = if self.new_queue.is_empty() {
// There are no new cards to be introduced.
false
} else if self.due == 0 {
// There are no due cards.
} else if self.due == 0 || self.prefer_new {
// There are no due cards, or new cards are preferred.
true
// Randomly choose between the new queue or the due cards. The ratio is chosen such
// that the space between new cards is as wide as possible.
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ hard, h : Review the card as hard
okay, o : Review the card as okay
good, g : Review the card as good
easy, e : Review the card as easy
post, p : Postpone the card to tomorrow"#;
post, p : Postpone the card to tomorrow
tnew, tn : Toggle whether new cards should be preferred"#;

/// Formatter for durations.
struct DurationFormatter(chrono::Duration);
Expand Down Expand Up @@ -123,9 +124,10 @@ impl<W: Write, R: io::BufRead> State<W, R> {

/// Print the shell, that is, the text before the command input.
pub fn print_shell(&mut self) -> Result<(), Error> {
write!(self.stdout, "D:{} N:{} {}>>{} ",
write!(self.stdout, "D:{} N:{}{} {}>>{} ",
self.scheduler.due_cards(),
self.scheduler.new_cards(),
if self.scheduler.prefer_new { "-" } else { "" },
color::Fg(color::Red),
color::Fg(color::Reset),
)?;
Expand Down Expand Up @@ -168,6 +170,8 @@ impl<W: Write, R: io::BufRead> State<W, R> {
"quit" | "q" => return Ok(false),
// Print help screen.
"help" | "he" => self.help()?,
// Toggle preference for new cards.
"tnew" | "tn" => self.scheduler.prefer_new ^= true,
// Skip.
"" => (),
// Unknown command.
Expand Down

0 comments on commit 79d055a

Please sign in to comment.