diff --git a/internal/files.go b/internal/files.go index 97cb1b7..a84353b 100644 --- a/internal/files.go +++ b/internal/files.go @@ -163,7 +163,11 @@ func (s *Session) updateCardInFile(c *Card) { check(err) md := string(data) re := regexp.MustCompile(fmt.Sprintf(``, c.Id)) - md = re.ReplaceAllString(md, fmt.Sprintf("", c.Id, c.Box, c.Due.Format("2006-01-02"))) + markString := "" + if c.Marked { + markString = ";fixme" + } + md = re.ReplaceAllString(md, fmt.Sprintf("", c.Id, c.Box, c.Due.Format("2006-01-02"), markString)) err = os.WriteFile(s.File.Path, []byte(md), 0644) check(err) } @@ -193,7 +197,7 @@ func (s *Session) ChooseCategory() { } fmt.Print("Your choice: ") - choice := ReadNumberInput(1, len(categories)) + choice, _ := ReadNumberInput(1, len(categories)) s.Category = categories[choice-1] } diff --git a/internal/leitner.go b/internal/leitner.go index 521f700..573e1fc 100644 --- a/internal/leitner.go +++ b/internal/leitner.go @@ -22,6 +22,7 @@ type Card struct { Back string Category string Id string + Marked bool // Box number starts at 0 Box uint Due time.Time @@ -69,7 +70,7 @@ func (s *Session) Start() { // Start the study session. for len(s.studyQueue) > 0 { ScrollDownScreen() - card, difficulty := s.flashNextCard() + card, difficulty, marked := s.flashNextCard() // If in test mode, don't update the metadata. if s.TestMode { @@ -84,7 +85,7 @@ func (s *Session) Start() { testModeResults.Easy++ } } else { - s.updateCard(card, difficulty) + s.updateCard(card, difficulty, marked) } } @@ -176,7 +177,7 @@ func (s *Session) assembleStudyQueue() { // flashNextCard Shows a card's front side. The card is picked from the study queue. // Waits for the user to press a key to signal how difficult the card was to remember. -func (s *Session) flashNextCard() (c *Card, difficulty float32) { +func (s *Session) flashNextCard() (c *Card, difficulty float32, marked bool) { ClearConsole() fmt.Printf("--- Cards left for today: %d / %d", len(s.studyQueue), s.NumberCards) @@ -198,9 +199,10 @@ func (s *Session) flashNextCard() (c *Card, difficulty float32) { back := WrapLines(c.Back, s.WrapLines) fmt.Printf("\n%s\n", back) + fmt.Println("--> Enter (m) to mark card with 'fixme' tag.") fmt.Println("--> How difficult was it to remember?") fmt.Printf("--> (1) Not remembered, (2) Hard, (3) Okay, (4) Easy: ") - d := ReadNumberInput(1, 4) + d, marked := ReadNumberInput(1, 4) switch d { case 1: difficulty = NotRemembered @@ -211,12 +213,12 @@ func (s *Session) flashNextCard() (c *Card, difficulty float32) { case 4: difficulty = Easy } - return c, difficulty + return c, difficulty, marked } // updateCard Updates the card's metadata (box and due date) according to the user's input. // It may also add the card back to the study queue if the answer was not remembered. -func (s *Session) updateCard(c *Card, difficulty float32) { +func (s *Session) updateCard(c *Card, difficulty float32, marked bool) { if difficulty == NotRemembered { // Move the card to the first box, reset the due date to today, and add it back to the study queue. c.Box = 0 @@ -236,5 +238,8 @@ func (s *Session) updateCard(c *Card, difficulty float32) { } c.Due = time.Date(y, m, d, 0, 0, 0, 0, time.UTC).AddDate(0, 0, daysInFuture) } + if marked { + c.Marked = true + } s.updateCardInFile(c) } diff --git a/internal/utils.go b/internal/utils.go index 525b85e..4826e86 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -43,21 +43,27 @@ func PrintJSON[T any](v T) { fmt.Println(string(out)) } -// ReadNumberInput reads a number from standard input. The number must be within i and j. If it is not, it will retry. -func ReadNumberInput(i, j int) int { - res := i - 1 +// ReadNumberInput reads a number or "m" symbol from standard input. +// The number must be within i and j. If it is not, it will retry. +func ReadNumberInput(i, j int) (int, bool) { + marked := false scanner := bufio.NewScanner(os.Stdin) - for res < i || res > j { + + for { scanner.Scan() in := scanner.Text() + if in == "m" { + marked = true + fmt.Print("Card marked for edit. Please enter a number: ") + continue + } nr, err := strconv.Atoi(in) if err != nil || nr < i || nr > j { fmt.Print("Please enter a number: ") continue } - res = nr + return nr, marked } - return res } // ReadEnterInput Blocks until the user enters a newline. diff --git a/test.md b/test.md index 6c18f51..48d19ab 100644 --- a/test.md +++ b/test.md @@ -2,12 +2,12 @@ some text that won't be parsed -## Why do broadcast algorithms differentiate between receiving and delivering? Some more text here to test the width setting and line wraps. +## Why do broadcast algorithms differentiate between receiving and delivering? Some more text here to test the width setting and line wraps. Because between the network and the application there lies the broadcast algorithm as a middleware. The algorithm decides, whether a message which the node received is forwarded (i.e. delivered) to the application. The same applies to the send. An application only sees the broadcast call but the middleware then spreads it into multiple point-to-point messages. -## Which types of reliable broadcast are there? +## Which types of reliable broadcast are there? - FIFO broadcast - Causal broadcast @@ -18,7 +18,7 @@ The same applies to the send. An application only sees the broadcast call but th A1 -## Q2 +## Q2 A2 ## Q3 @@ -27,7 +27,7 @@ A3 # T2 some other text -## Q4 +## Q4 A4