1    type TextChar = struct
2        char : Char
3        color : u8
4    
5    type TextLine @mut =
6        var commented_in : u32 = 0
7        var commented_out : u32 = 0
8        let list = List<TextChar>.new
9        let sb = StringBuilder.new
10   
11       fun get (i : u32) = list[i]
12       fun get_ptr (i : u32) = list.as_ptr + i
13   
14       def length = list.size
15       def as_string = sb.as_string
16       def last = list.last.char
17       def chars = sb.as_string.chars
18   
19       def insert (index : u32) (c : Char) =
20           list.add index (TextChar c 0)
21           sb.insert index c
22   
23       def insert (index : u32) (s : String) =
24           let mut i = 0
25           for c in s.chars do
26               insert (index + i) c
27               i += 1
28   
29       def insert (index : u32) (c : TextChar) =
30           list.add index c
31           sb.insert index c.char
32   
33       def remove (index : u32) =
34           list.remove_at index
35           sb.remove_at index
36   
37       def remove_range (start : u32) (end : u32) =
38           assert end > start
39           for _ = 1 to end - start do
40               list.remove_at start
41               sb.remove_at start
42   
43       def remove_from (index : u32) =
44           for _ = 1 to length - index do
45               list.remove_at index
46               sb.remove_at index
47   
48       def remove_to (index : u32) =
49           for _ = 1 to index do
50               list.remove_at 0
51               sb.remove_at 0
52   
53       def trim_end =
54           let mut index = list.size as i32 - 2
55           while index >= 0 && list[index].char == ' ' do
56               list.remove_at index
57               sb.remove_at index
58               index -= 1
59   
60       def set_color (index : u32) (color : u8) =
61           list[index].color = color
62   
63       def set_color (color : u8) =
64           for i = 0 until list.size do
65               list[i].color = color
66   
67       def is_blank = as_string.chars.all { _.is_whitespace }
68