1 type Command 2 | Left 3 | Right 4 | Up 5 | Down 6 | Apply 7 | Revert 8 | SaveAll 9 | Rename 10 | Remove 11 | File 12 | Directory 13 | Crate 14 15 type EditorCommand = 16 val build_kedr : bool 17 val emit_cpp : bool 18 val build_cpp : bool 19 val run : bool 20 21 type EditorState = 22 | Idle 23 | BuildKedr 24 | CMake 25 | BuildCpp 26 | Run 27 28 type Registry = 29 let map : Map<String, String> 30 31 def get_subpath (name : String) = 32 map.try_get name |> unwrap_or name 33 34 def load_registry (crates_path : String) = 35 let path = "$crates_path/registry.txt" 36 let lines = fs/read_text path |> lines 37 let map = Map<String, String>.new 38 for line in lines do 39 let (name, value) = line.split_at_first " = " 40 map.add name value 41 42 Registry map 43 44 module editor_object 45 46 type Editor @[mut internal] = 47 val app : App 48 val drawer : Drawer 49 val crate_name : String 50 val crates_path : String 51 val target_path : String 52 val develop_path : String 53 var maybe_process : Option<Process> = None 54 var maybe_command : Option<EditorCommand> = None 55 var state = EditorState/Idle 56 var should_draw = true 57 var was_resized = false 58 local mut should_separate = false 59 val registry = load_registry crates_path 60 val crates = List<FileItem>.new 61 val changed = obs/List<FileItem>.new 62 val content_changed = List<FileItem>.new 63 val tokens = List<Token>.new 64 65 val data = FileItem 66 is_root = true 67 is_directory = true 68 path = crates_path 69 actual_path = crates_path 70 71 val tab_item_text_boxes = Map<TabItem, MultilineTextBox>.new 72 val tab_item_file_items = Map<TabItem, FileItem>.new 73 val file_item_tab_items = Map<FileItem, TabItem>.new 74 75 val listener = TcpListener.bind 8000 76 77 def redraw = 78 should_draw = true 79 80 app.os_window.sizes.subscribe { redraw 81 was_resized = true } |> tokens.add 82 app.mouse.hover@atom.subscribe { redraw } |> tokens.add 83 84 local add_all_to_changed (item : FileItem) : Unit = 85 changed.add item 86 for x in item.items do 87 add_all_to_changed x 88 89 fun destruct = 90 listener.discard 91 for i = tokens.size - 1 downto 0 do 92 tokens[i].discard 93 94 tokens.clear 95 96 def compile (crate_name : String) (emit_c : bool) = 97 let s = if emit_c then "compile" else "build" 98 let text = "$s $crate_name" 99 case TcpStream.connect "127.0.0.1:8001" of 100 Some input_stream -> 101 input_stream.write text 102 discard 103 true 104 105 None -> false 106