about summary refs log tree commit diff stats
path: root/main.lua
Commit message (Collapse)AuthorAgeFilesLines
...
* always have a filenameKartik K. Agaram2022-05-161-4/+2
| | | | | When a filename is provided, we write to it. When it isn't we always open the same file, and it persists between loads.
* gracefully handle a non-existent filename at the commandlineKartik K. Agaram2022-05-161-2/+5
|
* couple of bugfixes to file-handlingKartik K. Agaram2022-05-161-1/+2
|
* delete experimental REPLKartik K. Agaram2022-05-161-13/+0
| | | | We're going to focus on a simple text editor for now.
* silly reason my screenshots had an ugly black line down the leftKartik K. Agaram2022-05-161-1/+1
|
* to open a file without a terminal, drag it on!Kartik K. Agaram2022-05-161-5/+18
|
* 2 regressions:Kartik K. Agaram2022-05-161-6/+7
| | | | | - loading a file from the command line - don't insert empty lines when loading a file from the command line
* bugfixKartik K. Agaram2022-05-161-1/+2
|
* slightly better default sizing of drawingsKartik K. Agaram2022-05-161-1/+2
|
* adjust window sizeKartik K. Agaram2022-05-161-0/+6
|
* some missing transitionsKartik K. Agaram2022-05-151-4/+14
|
* esc to cancel a shape mid-clickKartik K. Agaram2022-05-151-0/+5
|
* fix a commentKartik K. Agaram2022-05-151-3/+2
|
* autosave on keystrokesKartik K. Agaram2022-05-151-1/+6
|
* bugfix: move modeKartik K. Agaram2022-05-151-1/+5
|
* online contextual helpKartik K. Agaram2022-05-151-0/+130
|
* icons for current_modeKartik K. Agaram2022-05-151-0/+39
|
* delete drawing using backspaceKartik K. Agaram2022-05-151-0/+2
| | | | I solemnly swear that I am aware of the risk of data loss..
* experiment: only show drawing borders when they can be editedKartik K. Agaram2022-05-151-2/+6
|
* bugfix: text sometimes getting colored like drawing bordersKartik K. Agaram2022-05-151-0/+2
|
* load/save remaining shapesKartik K. Agaram2022-05-151-14/+18
|
* load/save freehand strokesKartik K. Agaram2022-05-151-2/+18
| | | | Also found a couple of bugs in the process.
* starting to load/saveKartik K. Agaram2022-05-151-4/+65
|
* more intuitive point delete from polygonsKartik K. Agaram2022-05-151-2/+18
|
* delete points or shapesKartik K. Agaram2022-05-141-12/+50
| | | | Deleting a point deletes all shapes that use it (but not other points in those shapes).
* slightly less strange now that we have the same two ways to move points as ↵Kartik K. Agaram2022-05-141-6/+18
| | | | | | | any other operation 1. hover over point, hit C-v 2. press mouse on point, hit v
* slightly strange way to move pointsKartik K. Agaram2022-05-141-5/+44
| | | | | | | | | | | | Hover mouse on a point, hit a hotkey (C-v), then move mouse without clicking, and click to finalize. The hotkey is like a pointer tool, except you have to already be at the thing you want to erase. And it's slightly inconvenient to move multiple points one by one. In the process I also fixed a bug: keychord clauses should always specify the mouse button state.
* changing your mind mid-shapeKartik K. Agaram2022-05-141-2/+30
| | | | | | | | | line->circle circle->line line->polygon polygon->line circle->polygon polygon->circle
* new mode: circle arcKartik K. Agaram2022-05-141-0/+81
| | | | | We start out drawing a circle, but instead of releasing the mouse we hit 'a'.
* new mode: circleKartik K. Agaram2022-05-141-0/+28
|
* new mode: polygonKartik K. Agaram2022-05-141-0/+55
| | | | | Polygons are closed. Add vertices to them by pressing 'p' while holding down the mouse.
* .Kartik K. Agaram2022-05-141-1/+1
|
* bugfix: clipping in line and manhattan modeKartik K. Agaram2022-05-141-13/+29
| | | | Thanks Kiran and Ravi.
* new mode: manhattanKartik K. Agaram2022-05-141-2/+41
|
* .Kartik K. Agaram2022-05-141-2/+2
|
* make points easier to acquireKartik K. Agaram2022-05-141-4/+8
|
* make point near focus 'pop'Kartik K. Agaram2022-05-141-1/+3
|
* snap lines to nearby pointsKartik K. Agaram2022-05-141-1/+3
|
* add a level of indirection to vertices of shapesKartik K. Agaram2022-05-141-37/+68
| | | | This is like Sketchpad.
* .Kartik K. Agaram2022-05-141-1/+1
|
* draw lines by defaultKartik K. Agaram2022-05-141-1/+1
| | | | Freehand strokes are a special case. Let's ignore them for a bit.
* bugfix: keep the click to create a new drawing from creating a new shape in ↵Kartik K. Agaram2022-05-141-14/+14
| | | | | | the drawing Easiest way to do this is to keep the screen areas for button and drawing disjoint.
* experimental approach to combining keyboard and mouse while drawingKartik K. Agaram2022-05-141-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Desired properties: - fluently draw lots of precise drawings - requires expressing lots of different kinds of constraints - always know what pressing a key is going to do - when typing, don't care where the mouse pointer is Less important: - discoverability, learnability. Provide a hotkey for help. Current plan: - chorded keys to modify drawings while mouse button is not pressed - unchorded keys to modify drawings only while mouse button is pressed - make changes while drawing a shape by pressing a key while mouse button is pressed - make changes to a drawing by hovering mouse pointer at a shape and pressing a key (unary operators) - add constraints after drawing by hovering mouse pointer at a shape, pressing a key and moving mouse pointer to a second shape (binary operators) - almost any change can be made to a shape after it's drawn (inspired by Sketchpad) - keys pressed while drawing a shape act as abbreviations to performing the action after drawing First example in this PR: - you press mouse button, start drawing freehand - you realize you want a simple line, not a freehand stroke - without releasing the mouse button, you press 'l' - now you're drawing a straight line You could also release the mouse button and finish the stroke, then press 'ctrl-l' while hovering the mouse pointer on the stroke to turn it into a line. There's an asymmetry here. Strokes require a lot more information, so while you can turn a stroke into a line, you can't turn a line into a stroke. Strokes are an exception where you can't switch to freehand mode after you start drawing. You have to press C-f before drawing.
* bugfixKartik K. Agaram2022-05-141-1/+1
|
* beginnings of support for multiple shapesKartik K. Agaram2022-05-141-43/+114
|
* color close to drawingKartik K. Agaram2022-05-141-1/+1
|
* Devine's suggestion to try to live with just freehandKartik K. Agaram2022-05-141-0/+17
| | | | | | | | | | | | https://merveilles.town/@neauoire/108301005736317873 Drawbacks: Smoothing eliminates high-frequency noise but not low-frequency bumps. Making a drawing end at the start point is very challenging. Still perhaps a useful addition to the toolbox for now. I'm going to need a cambrian explosion of tools in the toolbox for a while before I prune.
* revert: back to freehandKartik K. Agaram2022-05-141-21/+44
|
* switch from freehand to just straight linesKartik K. Agaram2022-05-131-44/+21
|
* store device-independent coordinates inside drawingsKartik K. Agaram2022-05-121-11/+25
|
/akkartik/mu/blame/089scenario_filesystem.cc?h=hlt&id=10f415a60a130ceefc4ce0f32155507763e6cee6'>^
c594062c ^
66abe7c1 ^




bc98ddb2 ^
0893d65e ^
bc98ddb2 ^


0893d65e ^
bc98ddb2 ^




0893d65e ^
bc98ddb2 ^

c594062c ^
66abe7c1 ^




bc98ddb2 ^
0893d65e ^
bc98ddb2 ^


0893d65e ^
bc98ddb2 ^

c594062c ^
66abe7c1 ^




bc98ddb2 ^
0893d65e ^
bc98ddb2 ^


0893d65e ^
bc98ddb2 ^



0893d65e ^
bc98ddb2 ^


0893d65e ^
bc98ddb2 ^









0893d65e ^
bc98ddb2 ^




6c96a437 ^
bc98ddb2 ^
18261f19 ^


0893d65e ^
18261f19 ^


bc98ddb2 ^







0893d65e ^
23d3a022 ^

6c96a437 ^
23d3a022 ^
78c50205 ^
a89c1bed ^
7fd01071 ^
23d3a022 ^
78c50205 ^
a89c1bed ^
7fd01071 ^
bc98ddb2 ^
23d3a022 ^

a89c1bed ^
0893d65e ^

23d3a022 ^
0893d65e ^
a89c1bed ^
bc98ddb2 ^
23d3a022 ^
a89c1bed ^
bc98ddb2 ^

0893d65e ^
bc98ddb2 ^


0893d65e ^

acce384b ^
bc98ddb2 ^


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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
                                                                      

                                                                         


                             
                            
             
                    










                                                     

                                                  
                                           
                                   
                                                   
                                        
                                  
                                           
                                   
                                                   
                                       
                                  
                                           
                                   
                                                   
                                       












                                
                                  
                                 
             
                    
                               
                                            
            
                

     

                                                  
                                           
                                   
                                                   
                                       






                               
                       
                                                                                                   
                                                  
                                                  

                                                       
                                             
                                  
                                                              
                                                                       

                                                                     
                                                          


                                                  
                 
                                        
                                                          
                                       
                        


                                                
                        
                                    
                                                                                        



        
                                                                 
                               

                                          

 
                                                                                          





                                     
                                    




                                                                            
                                   
                                                                                                              


                                    
                                                                                                            




                                     
                                                                                                    

            
                                 




                                                                            
                        
                                                                                                                                      


                        
                                                                                                               

            
                                    




                                                                            
                                   
                                                                                                                                                     


                                    
                                                                                                                                                   



                                     
                                                                             


   
                                                                                                   









                                   
                                                                                                                                    




                                  
                                            
                                   


                               
                                                                                                       


                







                                                                 
                                                                      

                                                                                                    
                                                                                              
                                              
                                             
                                                                                                  
           
                                                  
                                              
                                                                                                      
           
   

                                                                       
                                                                                                     

                                                        
                                                                                                            
                                            
                                                                                                                  
                    
                                                               
                                                                                                             

 
                         


                                       

                                               
                         


                
//: Clean syntax to manipulate and check the file system in scenarios.
//: Instruction 'assume-resources' implicitly creates a variable called
//: 'resources' that is accessible to later instructions in the scenario.

:(scenarios run_mu_scenario)
:(scenario simple_filesystem)
scenario simple-filesystem [
  local-scope
  assume-resources [
    # file 'a' containing two lines of data
    [a] <- [
      |a bc|
      |de f|
    ]
    # directory 'b' containing two files, 'c' and 'd'
    [b/c] <- []
    [b/d] <- [
      |xyz|
    ]
  ]
  data:&:@:resource <- get *resources, data:offset
  file1:resource <- index *data, 0
  file1-name:text <- get file1, name:offset
  10:@:char/raw <- copy *file1-name
  file1-contents:text <- get file1, contents:offset
  100:@:char/raw <- copy *file1-contents
  file2:resource <- index *data, 1
  file2-name:text <- get file2, name:offset
  30:@:char/raw <- copy *file2-name
  file2-contents:text <- get file2, contents:offset
  40:@:char/raw <- copy *file2-contents
  file3:resource <- index *data, 2
  file3-name:text <- get file3, name:offset
  50:@:char/raw <- copy *file3-name
  file3-contents:text <- get file3, contents:offset
  60:@:char/raw <- copy *file3-contents
  memory-should-contain [
    10:array:character <- [a]
    100:array:character <- [a bc
de f
]
    30:array:character <- [b/c]
    40:array:character <- []
    50:array:character <- [b/d]
    60:array:character <- [xyz
]
  ]
]

:(scenario escaping_file_contents)
scenario escaping-file-contents [
  local-scope
  assume-resources [
    # file 'a' containing a '|'
    # need to escape '\' once for each block
    [a] <- [
      |x\\\\|yz|
    ]
  ]
  data:&:@:resource <- get *resources, data:offset
  file1:resource <- index *data, 0
  file1-name:text <- get file1, name:offset
  10:@:char/raw <- copy *file1-name
  file1-contents:text <- get file1, contents:offset
  20:@:char/raw <- copy *file1-contents
  memory-should-contain [
    10:array:character <- [a]
    20:array:character <- [x|yz
]
  ]
]

:(before "End Globals")
extern const int RESOURCES = next_predefined_global_for_scenarios(/*size_of(address:resources)*/2);
//: give 'resources' a fixed location in scenarios
:(before "End Special Scenario Variable Names(r)")
Name[r]["resources"] = RESOURCES;
//: make 'resources' always a raw location in scenarios
:(before "End is_special_name Special-cases")
if (s == "resources") return true;
:(before "End Initialize Type Of Special Name In Scenario(r)")
if (r.name == "resources") r.type = new_type_tree("address:resources");

:(before "End initialize_transform_rewrite_literal_string_to_text()")
recipes_taking_literal_strings.insert("assume-resources");

//: screen-should-contain is a regular instruction
:(before "End Primitive Recipe Declarations")
ASSUME_RESOURCES,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "assume-resources", ASSUME_RESOURCES);
:(before "End Primitive Recipe Checks")
case ASSUME_RESOURCES: {
  break;
}
:(before "End Primitive Recipe Implementations")
case ASSUME_RESOURCES: {
  assert(scalar(ingredients.at(0)));
  assume_resources(current_instruction().ingredients.at(0).name, current_recipe_name());
  break;
}

:(code)
void assume_resources(const string& data, const string& caller) {
  map<string, string> contents;
  parse_resources(data, contents, caller);
  construct_resources_object(contents);
}

void parse_resources(const string& data, map<string, string>& out, const string& caller) {
  istringstream in(data);
  in >> std::noskipws;
  while (true) {
    if (!has_data(in)) break;
    skip_whitespace_and_comments(in);
    if (!has_data(in)) break;
    string filename = next_word(in);
    if (filename.empty()) {
      assert(!has_data(in));
      raise << "incomplete 'resources' block at end of file (0)\n" << end();
      return;
    }
    if (*filename.begin() != '[') {
      raise << caller << ": assume-resources: filename '" << filename << "' must begin with a '['\n" << end();
      break;
    }
    if (*filename.rbegin() != ']') {
      raise << caller << ": assume-resources: filename '" << filename << "' must end with a ']'\n" << end();
      break;
    }
    filename.erase(0, 1);
    filename.erase(SIZE(filename)-1);
    if (!has_data(in)) {
      raise << caller << ": assume-resources: no data for filename '" << filename << "'\n" << end();
      break;
    }
    string arrow = next_word(in);
    if (arrow.empty()) {
      assert(!has_data(in));
      raise << "incomplete 'resources' block at end of file (1)\n" << end();
      return;
    }
    if (arrow != "<-") {
      raise << caller << ": assume-resources: expected '<-' after filename '" << filename << "' but got '" << arrow << "'\n" << end();
      break;
    }
    if (!has_data(in)) {
      raise << caller << ": assume-resources: no data for filename '" << filename << "' after '<-'\n" << end();
      break;
    }
    string contents = next_word(in);
    if (contents.empty()) {
      assert(!has_data(in));
      raise << "incomplete 'resources' block at end of file (2)\n" << end();
      return;
    }
    if (*contents.begin() != '[') {
      raise << caller << ": assume-resources: file contents '" << contents << "' for filename '" << filename << "' must begin with a '['\n" << end();
      break;
    }
    if (*contents.rbegin() != ']') {
      raise << caller << ": assume-resources: file contents '" << contents << "' for filename '" << filename << "' must end with a ']'\n" << end();
      break;
    }
    contents.erase(0, 1);
    contents.erase(SIZE(contents)-1);
    put(out, filename, munge_resources_contents(contents, filename, caller));
  }
}

string munge_resources_contents(const string& data, const string& filename, const string& caller) {
  if (data.empty()) return "";
  istringstream in(data);
  in >> std::noskipws;
  skip_whitespace_and_comments(in);
  ostringstream out;
  while (true) {
    if (!has_data(in)) break;
    skip_whitespace(in);
    if (!has_data(in)) break;
    if (in.peek() != '|') {
      raise << caller << ": assume-resources: file contents for filename '" << filename << "' must be delimited in '|'s\n" << end();
      break;
    }
    in.get();  // skip leading '|'
    string line;
    getline(in, line);
    for (int i = 0;  i < SIZE(line);  ++i) {
      if (line.at(i) == '|') break;
      if (line.at(i) == '\\') {
        ++i;  // skip
        if (i == SIZE(line)) {
          raise << caller << ": assume-resources: file contents can't end a line with '\\'\n" << end();
          break;
        }
      }
      out << line.at(i);
    }
    // todo: some way to represent a file without a final newline
    out << '\n';
  }
  return out.str();
}

void construct_resources_object(const map<string, string>& contents) {
  int resources_data_address = allocate(SIZE(contents) * /*size of resource*/4 + /*array length*/1);
  int curr = resources_data_address + /*skip alloc id*/1 + /*skip array length*/1;
  for (map<string, string>::const_iterator p = contents.begin();  p != contents.end();  ++p) {
    ++curr;  // skip alloc id of resource.name
    put(Memory, curr, new_mu_text(p->first));
    trace("mem") << "storing file name " << get(Memory, curr) << " in location " << curr << end();
    ++curr;
    ++curr;  // skip alloc id of resource.contents
    put(Memory, curr, new_mu_text(p->second));
    trace("mem") << "storing file contents " << get(Memory, curr) << " in location " << curr << end();
    ++curr;
  }
  curr = resources_data_address + /*skip alloc id of resources.data*/1;
  put(Memory, curr, SIZE(contents));  // array length
  trace("mem") << "storing resources size " << get(Memory, curr) << " in location " << curr << end();
  // wrap the resources data in a 'resources' object
  int resources_address = allocate(size_of_resources());
  curr = resources_address+/*alloc id*/1+/*offset of 'data' element*/1+/*skip alloc id of 'data' element*/1;
  put(Memory, curr, resources_data_address);
  trace("mem") << "storing resources data address " << resources_data_address << " in location " << curr << end();
  // save in product
  put(Memory, RESOURCES+/*skip alloc id*/1, resources_address);
  trace("mem") << "storing resources address " << resources_address << " in location " << RESOURCES << end();
}

int size_of_resources() {
  // memoize result if already computed
  static int result = 0;
  if (result) return result;
  assert(get(Type_ordinal, "resources"));
  type_tree* type = new type_tree("resources");
  result = size_of(type);
  delete type;
  return result;
}