1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::io::{self};
use super::character::Character;
#[derive(Debug, Clone)]
pub struct Cursor<T> {
pos: usize,
inner: T,
}
impl <T> Cursor <T> {
pub fn new(inner: T) -> Cursor<T> {
Cursor {
pos: 0,
inner: inner,
}
}
pub fn into_inner(self) -> T {
self.inner
}
pub fn get_ref(&self) -> &T {
&self.inner
}
pub fn get_mut(&mut self) -> &mut T {
&mut self.inner
}
pub fn position(&self) -> usize {
self.pos
}
pub fn set_position(&mut self, pos: usize) {
self.pos = pos;
}
}
impl Cursor<Vec<Character>> {
pub fn write_with_color(
&mut self,
glyph: char,
mut ope: Character,
) -> io::Result<usize> {
unsafe {
ope.set_glyph(glyph);
*self.inner.get_unchecked_mut(self.pos) = ope;
self.pos += 1;
Ok(1)
}
}
}