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