1use std::fmt::Display;
2
3use crate::prelude::*;
4
5#[derive(Debug)]
7pub struct Cursor(Section, usize, usize);
8
9impl Cursor {
10 fn set_section_internal(&mut self, section: Section) {
11 self.0 = section;
12 self.1 = 0;
13 self.2 = 0;
14 }
15
16 pub fn reset(&mut self) {
17 self.set_section_internal(Section::Initial);
18 }
19
20 pub fn set_section(&mut self, name: String) {
21 self.set_section_internal(Section::Named(name));
22 }
23
24 #[must_use]
25 pub fn section(&self) -> &Section {
26 &self.0
27 }
28
29 pub fn next_line_index(&mut self) {
30 self.1 += 1;
31 self.2 = 0;
32 }
33
34 #[must_use]
35 pub fn line_index(&self) -> usize {
36 self.1
37 }
38
39 pub fn next_phrase_index(&mut self) {
40 self.2 += 1;
41 }
42
43 #[must_use]
44 pub fn phrase_index(&self) -> usize {
45 self.2
46 }
47}
48
49impl Default for Cursor {
50 fn default() -> Self {
51 Self(Section::Initial, 0, 0)
52 }
53}
54
55impl Display for Cursor {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 write!(f, "{}:{}:{}", self.0, self.1, self.2)
58 }
59}