summary refs log tree commit diff stats
path: root/ranger
Commit message (Expand)AuthorAgeFilesLines
* defaults.commands: Removed "quick" method from :cdhut2010-09-111-12/+0
* Sort settings in ranger/shared/settings.pyhut2010-08-301-20/+20
* defaults.keys: key pL to create relative symlinkshut2010-08-294-5/+50
* Tuned versioning scheme to be more intuitive, back to 1.1.2hut2010-08-282-2/+2
* Changed version number to 1.2 (testing) to adhere with versioning schemehut2010-08-282-2/+9
* Fixed new history implementationhut2010-08-284-9/+22
* Changed default config dir to $XDG_CONFIG_HOME/rangerhut2010-08-288-11/+14
* cleaned up and fine tuned :find commandhut2010-08-281-11/+7
* Integrated new container.history implementationhut2010-08-282-6/+9
* Changed implementation of container.historyhut2010-08-281-59/+72
* Fixed historyhut2010-08-266-27/+37
* widgets.console: removed duplicate importhut2010-08-261-1/+0
* widgets.console: removed unused Console.init() methodhut2010-08-261-4/+0
* more documentation updateshut2010-08-261-14/+21
* core.actions: 12? now opens help chapter 1 subchapter 2hut2010-08-261-2/+16
* Updated documentation for the consolehut2010-08-262-138/+61
* widgets/console: Simplified consolehut2010-08-268-494/+295
* widgets.console: improved delete_word()hut2010-08-251-8/+9
* defaults.keys: added keys gl and gL to resolve linkshut2010-08-252-1/+6
* Fixed exception when using %f macros in special caseshut2010-08-161-2/+4
* defaults.keys: map <backspace> to ^H (since ^H is bugged sometimes)hut2010-08-131-1/+1
* shared.mimetype: look for mimetypes in ~/.mime.typeshut2010-08-121-0/+3
* defaults.keys: added keys da, dr, ya, yr + documentationhut2010-07-233-5/+21
* gui.widgets.console: added %<LETTER> and %<N><letter> macroshut2010-07-172-1/+41
* help.console: typohut2010-07-171-1/+1
* defaults.apps: make pager accept ansi color codeshut2010-07-171-1/+1
* Why did the astrophysicist order three hamburgers? v1.1.2hut2010-07-121-1/+1
* defaults.keys: improved "du" keybindinghut2010-07-051-1/+2
* core.actions: added "execute_console"hut2010-07-031-0/+6
* Fixed default keyword argument value "mode" for fm.open_consolehut2010-07-031-1/+1
* ext.human_readable: fixedhut2010-06-251-5/+5
* ext.human_readable: more efficient implementationhut2010-06-241-19/+34
* ranger.main: ranger dir1 dir2 [...] opens multiple tabshut2010-06-241-7/+6
* core.actions: Fixed indexerror in move_parent()hut2010-06-201-1/+4
* version = version + 1 v1.1.1hut2010-06-181-1/+1
* Don't write bytecode with --clean switchhut2010-06-181-11/+15
* main: catch SystemExit and return the exit valuehut2010-06-181-0/+4
* core.runner: added "w" flag (wait for enter after process is done)hut2010-06-182-1/+19
* core.actions: fixed move_parent()hut2010-06-181-3/+2
* new stable version v1.1.0hut2010-06-091-1/+1
* fsobject.file: blacklist /proc/kcore for previewinghut2010-06-091-0/+2
* renamed "--fail-if-run" to the more accurate "--fail-unless-cd"hut2010-06-092-7/+13
* widgets.console: fixed history in clean modehut2010-06-091-1/+5
* minor changeshut2010-06-092-2/+3
* Fixed some docstringshut2010-06-092-3/+3
* Changed hashbang line to "#!/usr/bin/env python"hut2010-06-091-1/+1
* simpler helphut2010-06-071-2/+2
* main: minor edithut2010-06-051-1/+1
* main: fixed error handling in python2.6 and improved ithut2010-06-051-14/+8
* fsobject: ignore ".part" extensions when determining mimetypehut2010-06-041-1/+4
52 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-05-04 10:31:52 -0700 1248 - syntax for using screens in scenarios' href='/akkartik/mu/commit/cpp/072scenario_screen.cc?h=hlt&id=de49fb426aa44984d308f5856ec836360ba0bdce'>de49fb42 ^
ac0e9db5 ^
f46db248 ^


ac0e9db5 ^
f46db248 ^



















8e41a2b8 ^

f46db248 ^
8e41a2b8 ^



f46db248 ^
8e41a2b8 ^
3b168e00 ^



de49fb42 ^

f46db248 ^










































de49fb42 ^

8e41a2b8 ^













ac0e9db5 ^
8e41a2b8 ^
ac0e9db5 ^
8e41a2b8 ^
ac0e9db5 ^
8e41a2b8 ^

ac0e9db5 ^

8e41a2b8 ^

ac0e9db5 ^

8e41a2b8 ^
ac0e9db5 ^
8e41a2b8 ^





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
241
242
243
244
245
246
247
248
249
250
251



                                                                              



                              
                   












                                                                       















                                                                         














                                                                       
                                                                              
 



                                     



                                                                        

                                                                                

                                                                  



                                                                          
                                                                


                       
                                                                    

                                                 
                                          
 







                                                         
                                        











                                                                      
                                                             


        













                                                                        
       
                                                    
                                        
                                                                          
                                                 

                                                                     

                                                                                                     
                                                                             
                                                                    
                                                                           
                                                                      


                                                           
                                                           



















                                                                                                                                                                                                                             

                                               
                                                                                                                                                                                                                         



                                    
                                                                                                                                                                                
       



                           

             










































                                                                                                                         

   













                                                                          
                                                 
                                                                             
                                                                    
                                                                           
                                                                      

                                                                     

                                                                                                     

                                                                  

                                                           
                                    
                                                            





                                              
//: Clean syntax to manipulate and check the screen in scenarios.
//: Instructions 'assume-screen' and 'screen-should-contain' implicitly create
//: a variable called 'screen' that is accessible inside other 'run'
//: instructions in the scenario.

:(scenarios run_mu_scenario)
:(scenario screen_in_scenario)
scenario screen-in-scenario [
#?   $start-tracing
  assume-screen 5:literal/width, 3:literal/height
  run [
    screen:address <- print-character screen:address, 97:literal  # 'a'
  ]
  screen-should-contain [
  #  01234
    .a    .
    .     .
    .     .
  ]
#?   $exit
]

:(scenario screen_in_scenario_unicode)
# screen-should-contain can check unicode characters in the fake screen
scenario screen-in-scenario [
  assume-screen 5:literal/width, 3:literal/height
  run [
    screen:address <- print-character screen:address, 955:literal  # 'λ'
  ]
  screen-should-contain [
  #  01234
    .λ    .
    .     .
    .     .
  ]
#?   $exit
]

:(scenario screen_in_scenario_error)
#? % cerr << "AAA\n";
% Hide_warnings = true;
scenario screen-in-scenario-error [
  assume-screen 5:literal/width, 3:literal/height
  run [
    screen:address <- print-character screen:address, 97:literal  # 'a'
  ]
  screen-should-contain [
  #  01234
    .b    .
    .     .
    .     .
  ]
]
+warn: expected screen location (0, 0) to contain 98 ('b') instead of 97 ('a')

//: allow naming just for 'screen'
:(before "End is_special_name Cases")
if (s == "screen") return true;

:(before "End Globals")
// Scenarios may not define default-space, so they should fit within the
// initial area of memory reserved for tests. We'll put the predefined
// variables available to them at the end of that region.
const long long int Max_variables_in_scenarios = Reserved_for_tests-100;
long long int Next_predefined_global_for_scenarios = Max_variables_in_scenarios;
:(before "End Setup")
assert(Next_predefined_global_for_scenarios < Reserved_for_tests);
:(after "transform_all()" following "case RUN:")
// There's a restriction on the number of variables 'run' can use, so that
// it can avoid colliding with the dynamic allocator in case it doesn't
// initialize a default-space.
assert(Name[tmp_recipe.at(0)][""] < Max_variables_in_scenarios);

:(before "End Globals")
// Scenario Globals.
const long long int SCREEN = Next_predefined_global_for_scenarios++;
// End Scenario Globals.
:(before "End Predefined Scenario Locals In Run")
Name[tmp_recipe.at(0)]["screen"] = SCREEN;

:(before "End Rewrite Instruction(curr)")
// rewrite `assume-screen width, height` to
// `screen:address <- init-fake-screen width, height`
//? cout << "before: " << curr.to_string() << '\n'; //? 1
if (curr.name == "assume-screen") {
  curr.operation = Recipe_number["init-fake-screen"];
  assert(curr.products.empty());
  curr.products.push_back(reagent("screen:address"));
  curr.products.at(0).set_value(SCREEN);
//? cout << "after: " << curr.to_string() << '\n'; //? 1
//? cout << "AAA " << Recipe_number["init-fake-screen"] << '\n'; //? 1
}

//: screen-should-contain is a regular instruction
:(before "End Primitive Recipe Declarations")
SCREEN_SHOULD_CONTAIN,
:(before "End Primitive Recipe Numbers")
Recipe_number["screen-should-contain"] = SCREEN_SHOULD_CONTAIN;
:(before "End Primitive Recipe Implementations")
case SCREEN_SHOULD_CONTAIN: {
//?   cout << "AAA\n"; //? 1
  check_screen(current_instruction().ingredients.at(0).name);
  break;
}

:(before "End Types")
// scan an array of characters in a unicode-aware, bounds-checked manner
struct raw_string_stream {
  long long int index;
  const long long int max;
  const char* buf;

  raw_string_stream(const string&);
  uint32_t get();  // unicode codepoint
  uint32_t peek();  // unicode codepoint
  bool at_end() const;
  void skip_whitespace_and_comments();
};

:(code)
void check_screen(const string& expected_contents) {
//?   cerr << "Checking screen\n"; //? 1
  assert(!Current_routine->calls.front().default_space);  // not supported
  long long int screen_location = Memory[SCREEN];
  int data_offset = find_element_name(Type_number["screen"], "data");
  assert(data_offset >= 0);
  long long int screen_data_location = screen_location+data_offset;  // type: address:array:character
  long long int screen_data_start = Memory[screen_data_location];  // type: array:character
  int width_offset = find_element_name(Type_number["screen"], "num-columns");
  long long int screen_width = Memory[screen_location+width_offset];
  int height_offset = find_element_name(Type_number["screen"], "num-rows");
  long long int screen_height = Memory[screen_location+height_offset];
  raw_string_stream cursor(expected_contents);
  // todo: too-long expected_contents should fail
  long long int addr = screen_data_start+1;  // skip length
  for (long long int row = 0; row < screen_height; ++row) {
    cursor.skip_whitespace_and_comments();
    if (cursor.at_end()) break;
    assert(cursor.get() == '.');
    for (long long int column = 0;  column < screen_width;  ++column, ++addr) {
      uint32_t curr = cursor.get();
      if (Memory[addr] == 0 && isspace(curr)) continue;
      if (Memory[addr] != 0 && Memory[addr] == curr) continue;
      // mismatch
      // can't print multi-byte unicode characters in warnings just yet. not very useful for debugging anyway.
      char expected_pretty[10] = {0};
      if (curr < 256) {
        // " ('<curr>')"
        expected_pretty[0] = ' ', expected_pretty[1] = '(', expected_pretty[2] = '\'', expected_pretty[3] = static_cast<unsigned char>(curr), expected_pretty[4] = '\'', expected_pretty[5] = ')', expected_pretty[6] = '\0';
      }
      char actual_pretty[10] = {0};
      if (Memory[addr] < 256) {
        // " ('<curr>')"
        actual_pretty[0] = ' ', actual_pretty[1] = '(', actual_pretty[2] = '\'', actual_pretty[3] = static_cast<unsigned char>(Memory[addr]), actual_pretty[4] = '\'', actual_pretty[5] = ')', actual_pretty[6] = '\0';
      }

      if (Current_scenario && !Hide_warnings) {
        // genuine test in a mu file
        raise << "\nF - " << Current_scenario->name << ": expected screen location (" << row << ", " << column << ") to contain " << curr << expected_pretty << " instead of " << Memory[addr] << actual_pretty << "'\n";
        dump_screen();
      }
      else {
        // just testing check_screen
        raise << "expected screen location (" << row << ", " << column << ") to contain " << curr << expected_pretty << " instead of " << Memory[addr] << actual_pretty << '\n';
      }
      if (!Hide_warnings) {
        Passed = false;
        ++Num_failures;
      }
      return;
    }
    assert(cursor.get() == '.');
  }
  cursor.skip_whitespace_and_comments();
  assert(cursor.at_end());
}

raw_string_stream::raw_string_stream(const string& backing) :index(0), max(backing.size()), buf(backing.c_str()) {}

bool raw_string_stream::at_end() const {
  if (index >= max) return true;
  if (tb_utf8_char_length(buf[index]) > max-index) {
    raise << "unicode string seems corrupted at index "<< index << " character " << static_cast<int>(buf[index]) << '\n';
    return true;
  }
  return false;
}

uint32_t raw_string_stream::get() {
  assert(index < max);  // caller must check bounds before calling 'get'
  uint32_t result = 0;
  int length = tb_utf8_char_to_unicode(&result, &buf[index]);
  assert(length != TB_EOF);
  index += length;
  return result;
}

uint32_t raw_string_stream::peek() {
  assert(index < max);  // caller must check bounds before calling 'get'
  uint32_t result = 0;
  int length = tb_utf8_char_to_unicode(&result, &buf[index]);
  assert(length != TB_EOF);
  return result;
}

void raw_string_stream::skip_whitespace_and_comments() {
  while (!at_end()) {
    if (isspace(peek())) get();
    else if (peek() == '#') {
      // skip comment
      get();
      while (peek() != '\n') get();  // implicitly also handles CRLF
    }
    else break;
  }
}

:(before "End Primitive Recipe Declarations")
_DUMP_SCREEN,
:(before "End Primitive Recipe Numbers")
Recipe_number["$dump-screen"] = _DUMP_SCREEN;
:(before "End Primitive Recipe Implementations")
case _DUMP_SCREEN: {
  dump_screen();
  break;
}

:(code)
void dump_screen() {
  assert(!Current_routine->calls.front().default_space);  // not supported
  long long int screen_location = Memory[SCREEN];
  int width_offset = find_element_name(Type_number["screen"], "num-columns");
  long long int screen_width = Memory[screen_location+width_offset];
  int height_offset = find_element_name(Type_number["screen"], "num-rows");
  long long int screen_height = Memory[screen_location+height_offset];
  int data_offset = find_element_name(Type_number["screen"], "data");
  assert(data_offset >= 0);
  long long int screen_data_location = screen_location+data_offset;  // type: address:array:character
  long long int screen_data_start = Memory[screen_data_location];  // type: array:character
//?   cerr << "data start: " << screen_data_start << '\n'; //? 1
  assert(Memory[screen_data_start] == screen_width*screen_height);
  long long int curr = screen_data_start+1;  // skip length
  for (long long int row = 0; row < screen_height; ++row) {
//?     cerr << curr << ":\n"; //? 1
    for (long long int col = 0; col < screen_width; ++col) {
      cerr << static_cast<char>(Memory[curr]);
      ++curr;
    }
    cerr << '\n';
  }
}