cursor/cmn/
info.rs

1// Copyright 2021 Hwakyeom Kim(=just-do-halee)
2
3use super::*;
4
5#[derive(PartialEq, Eq)]
6pub struct CursorInfo<T, E: Extras<T> = NoneExtras<T>> {
7    pub init: bool,
8    pub backwards: bool,
9    pub pos: usize,
10    pub extras: E,
11    pub noeffects: bool,
12    _marker: PhantomData<T>,
13}
14impl<T, E: Extras<T>> Default for CursorInfo<T, E> {
15    #[inline]
16    fn default() -> Self {
17        CursorInfo {
18            init: false,
19            backwards: false,
20            pos: 0,
21            extras: Extras::new(),
22            noeffects: false,
23            _marker: PhantomData,
24        }
25    }
26}
27impl<T, E: Extras<T>> Clone for CursorInfo<T, E> {
28    #[inline]
29    fn clone(&self) -> Self {
30        CursorInfo {
31            init: self.init,
32            backwards: self.backwards,
33            pos: self.pos,
34            extras: self.extras.clone(),
35            noeffects: false,
36            _marker: PhantomData,
37        }
38    }
39}
40
41impl<T, E: Extras<T>> CursorInfo<T, E> {
42    #[inline]
43    pub fn new() -> Self {
44        CursorInfo::default()
45    }
46    #[inline]
47    pub fn reset(&mut self) {
48        self.init = false;
49        self.backwards = false;
50        self.pos = 0;
51        self.extras.reset();
52        self.noeffects = false;
53    }
54}
55
56// ------ extensions ------
57
58#[derive(PartialEq, Eq)]
59pub struct StrCursorInfo<E: Extras<char> = NoneExtras<char>> {
60    pub inner: CursorInfo<u8, NoneExtras<u8>>,
61    pub pos: usize,
62    pub extras: E,
63    pub char_start_pos: usize,
64    pub current: char,
65    pub noeffects: bool,
66}
67impl<E: Extras<char>> Default for StrCursorInfo<E> {
68    #[inline]
69    fn default() -> Self {
70        StrCursorInfo {
71            inner: CursorInfo::default(),
72            pos: 0,
73            extras: Extras::new(),
74            char_start_pos: 0,
75            current: EOF_CHAR,
76            noeffects: false,
77        }
78    }
79}
80impl<E: Extras<char>> Clone for StrCursorInfo<E> {
81    #[inline]
82    fn clone(&self) -> Self {
83        StrCursorInfo {
84            inner: self.inner.clone(),
85            pos: self.pos,
86            extras: self.extras.clone(),
87            char_start_pos: self.char_start_pos,
88            current: self.current,
89            noeffects: self.noeffects,
90        }
91    }
92}
93
94impl<E: Extras<char>> StrCursorInfo<E> {
95    #[inline]
96    pub fn new() -> Self {
97        StrCursorInfo::default()
98    }
99    #[inline]
100    pub fn reset(&mut self) {
101        self.inner.reset();
102        self.pos = 0;
103        self.extras.reset();
104        self.char_start_pos = 0;
105        self.current = EOF_CHAR;
106        self.noeffects = false;
107    }
108}