summary refs log tree commit diff stats
path: root/doc/pydoc/ranger.container.environment.html
blob: 6ee8a0dfb7697281b443d442d2e2b2fc0e3714b0 (plain) (blame)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.container.environment</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.container.html"><font color="#ffffff">container</font></a>.environment</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/work/ranger/ranger/container/environment.py">/home/hut/work/ranger/ranger/container/environment.py</a></font></td></tr></table>
    <p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="curses.html">curses</a><br>
</td><td width="25%" valign=top><a href="os.html">os</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.container.environment.html#Environment">Environment</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Environment">class <strong>Environment</strong></a>(<a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>A&nbsp;collection&nbsp;of&nbsp;data&nbsp;which&nbsp;is&nbsp;relevant&nbsp;for&nbsp;more&nbsp;than<br>
one&nbsp;class.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="ranger.container.environment.html#Environment">Environment</a></dd>
<dd><a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="Environment-__init__"><strong>__init__</strong></a>(self, path)</dt></dl>

<dl><dt><a name="Environment-assign_correct_cursor_positions"><strong>assign_correct_cursor_positions</strong></a>(self)</dt><dd><tt>Assign&nbsp;correct&nbsp;cursor&nbsp;positions&nbsp;for&nbsp;subdirectories</tt></dd></dl>

<dl><dt><a name="Environment-at_level"><strong>at_level</strong></a>(self, level)</dt><dd><tt>Returns&nbsp;the&nbsp;FileSystemObject&nbsp;at&nbsp;the&nbsp;given&nbsp;level.<br>
level&nbsp;1&nbsp;=&gt;&nbsp;preview<br>
level&nbsp;0&nbsp;=&gt;&nbsp;current&nbsp;file/directory<br>
level&nbsp;&lt;0&nbsp;=&gt;&nbsp;parent&nbsp;directories</tt></dd></dl>

<dl><dt><a name="Environment-enter_dir"><strong>enter_dir</strong></a>(self, path, history<font color="#909090">=True</font>)</dt><dd><tt>Enter&nbsp;given&nbsp;path</tt></dd></dl>

<dl><dt><a name="Environment-garbage_collect"><strong>garbage_collect</strong></a>(self)</dt><dd><tt>Delete&nbsp;unused&nbsp;directory&nbsp;objects</tt></dd></dl>

<dl><dt><a name="Environment-get_directory"><strong>get_directory</strong></a>(self, path)</dt><dd><tt>Get&nbsp;the&nbsp;directory&nbsp;object&nbsp;at&nbsp;the&nbsp;given&nbsp;path</tt></dd></dl>

<dl><dt><a name="Environment-get_selection"><strong>get_selection</strong></a>(self)</dt></dl>

<dl><dt><a name="Environment-history_go"><strong>history_go</strong></a>(self, relative)</dt><dd><tt>Move&nbsp;relative&nbsp;in&nbsp;history</tt></dd></dl>

<dl><dt><a name="Environment-key_append"><strong>key_append</strong></a>(self, key)</dt><dd><tt>Append&nbsp;a&nbsp;key&nbsp;to&nbsp;the&nbsp;keybuffer</tt></dd></dl>

<dl><dt><a name="Environment-key_clear"><strong>key_clear</strong></a>(self)</dt><dd><tt>Clear&nbsp;the&nbsp;keybuffer</tt></dd></dl>

<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>cf</strong> = None</dl>

<dl><dt><strong>copy</strong> = None</dl>

<dl><dt><strong>cut</strong> = None</dl>

<dl><dt><strong>directories</strong> = None</dl>

<dl><dt><strong>history</strong> = None</dl>

<dl><dt><strong>keybuffer</strong> = None</dl>

<dl><dt><strong>last_search</strong> = None</dl>

<dl><dt><strong>path</strong> = None</dl>

<dl><dt><strong>pathway</strong> = None</dl>

<dl><dt><strong>pwd</strong> = None</dl>

<dl><dt><strong>termsize</strong> = None</dl>

<hr>
Data descriptors inherited from <a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Data and other attributes inherited from <a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a>:<br>
<dl><dt><strong>settings</strong> = &lt;ranger.ext.openstruct.OpenStruct object at 0x7f20a718ad90&gt;</dl>

</td></tr></table></td></tr></table>
</body></html>
(get(Recipe, r).name) << "'screen-should-contain' requires exactly one ingredient, but got '" << to_original_string(inst) << "'\n" << end(); break; } if (!is_literal_text(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of 'screen-should-contain' should be a literal string, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); break; } break; } :(before "End Primitive Recipe Implementations") case SCREEN_SHOULD_CONTAIN: { if (!Passed) break; assert(scalar(ingredients.at(0))); check_screen(current_instruction().ingredients.at(0).name, -1); break; } :(before "End Primitive Recipe Declarations") SCREEN_SHOULD_CONTAIN_IN_COLOR, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "screen-should-contain-in-color", SCREEN_SHOULD_CONTAIN_IN_COLOR); :(before "End Primitive Recipe Checks") case SCREEN_SHOULD_CONTAIN_IN_COLOR: { if (SIZE(inst.ingredients) != 2) { raise << maybe(get(Recipe, r).name) << "'screen-should-contain-in-color' requires exactly two ingredients, but got '" << to_original_string(inst) << "'\n" << end(); break; } if (!is_mu_number(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of 'screen-should-contain-in-color' should be a number (color code), but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); break; } if (!is_literal_text(inst.ingredients.at(1))) { raise << maybe(get(Recipe, r).name) << "second ingredient of 'screen-should-contain-in-color' should be a literal string, but got '" << inst.ingredients.at(1).original_string << "'\n" << end(); break; } break; } :(before "End Primitive Recipe Implementations") case SCREEN_SHOULD_CONTAIN_IN_COLOR: { if (!Passed) break; assert(scalar(ingredients.at(0))); assert(scalar(ingredients.at(1))); check_screen(current_instruction().ingredients.at(1).name, ingredients.at(0).at(0)); break; } :(before "End Types") // scan an array of characters in a unicode-aware, bounds-checked manner struct raw_string_stream { int index; const 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, const int color) { int screen_location = get_or_insert(Memory, SCREEN+/*skip address alloc id*/1) + /*skip payload alloc id*/1; reagent screen("x:screen"); // just to ensure screen.type is reclaimed int screen_data_location = find_element_location(screen_location, "data", screen.type, "check_screen"); // type: address:array:character assert(screen_data_location >= 0); //? cerr << "screen data is at location " << screen_data_location << '\n'; int screen_data_start = get_or_insert(Memory, screen_data_location+/*skip address alloc id*/1) + /*skip payload alloc id*/1; // type: array:character //? cerr << "screen data start is at " << screen_data_start << '\n'; int screen_width_location = find_element_location(screen_location, "num-columns", screen.type, "check_screen"); //? cerr << "screen width is at location " << screen_width_location << '\n'; int screen_width = get_or_insert(Memory, screen_width_location); //? cerr << "screen width: " << screen_width << '\n'; int screen_height_location = find_element_location(screen_location, "num-rows", screen.type, "check_screen"); //? cerr << "screen height is at location " << screen_height_location << '\n'; int screen_height = get_or_insert(Memory, screen_height_location); //? cerr << "screen height: " << screen_height << '\n'; int top_index_location= find_element_location(screen_location, "top-idx", screen.type, "check_screen"); //? cerr << "top of screen is at location " << top_index_location << '\n'; int top_index = get_or_insert(Memory, top_index_location); //? cerr << "top of screen is index " << top_index << '\n'; raw_string_stream cursor(expected_contents); // todo: too-long expected_contents should fail for (int i=0, row=top_index/screen_width; i < screen_height; ++i, row=(row+1)%screen_height) { cursor.skip_whitespace_and_comments(); if (cursor.at_end()) break; if (cursor.get() != '.') { raise << maybe(current_recipe_name()) << "each row of the expected screen should start with a '.'\n" << end(); if (!Scenario_testing_scenario) Passed = false; return; } int addr = screen_data_start+/*length*/1+row*screen_width* /*size of screen-cell*/2; for (int column = 0; column < screen_width; ++column, addr+= /*size of screen-cell*/2) { const int cell_color_offset = 1; uint32_t curr = cursor.get(); if (get_or_insert(Memory, addr) == 0 && isspace(curr)) continue; if (curr == ' ' && color != -1 && color != get_or_insert(Memory, addr+cell_color_offset)) { // filter out other colors continue; } if (get_or_insert(Memory, addr) != 0 && get_or_insert(Memory, addr) == curr) { if (color == -1 || color == get_or_insert(Memory, addr+cell_color_offset)) continue; // contents match but color is off if (!Hide_errors) cerr << '\n'; raise << "F - " << maybe(current_recipe_name()) << "expected screen location (" << row << ", " << column << ") to contain '" << unicode_character_at(addr) << "' in color " << color << " instead of " << no_scientific(get_or_insert(Memory, addr+cell_color_offset)) << "\n" << end(); if (!Hide_errors) dump_screen(); if (!Scenario_testing_scenario) Passed = false; return; } // really a mismatch // can't print multi-byte unicode characters in errors just yet. not very useful for debugging anyway. char expected_pretty[10] = {0}; if (curr < 256 && !iscntrl(curr)) { // " ('<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 (get_or_insert(Memory, addr) < 256 && !iscntrl(get_or_insert(Memory, addr))) { // " ('<curr>')" actual_pretty[0] = ' ', actual_pretty[1] = '(', actual_pretty[2] = '\'', actual_pretty[3] = static_cast<unsigned char>(get_or_insert(Memory, addr)), actual_pretty[4] = '\'', actual_pretty[5] = ')', actual_pretty[6] = '\0'; } ostringstream color_phrase; if (color != -1) color_phrase << " in color " << color; if (!Hide_errors) cerr << '\n'; raise << "F - " << maybe(current_recipe_name()) << "expected screen location (" << row << ", " << column << ") to contain " << curr << expected_pretty << color_phrase.str() << " instead of " << no_scientific(get_or_insert(Memory, addr)) << actual_pretty << '\n' << end(); if (!Hide_errors) dump_screen(); if (!Scenario_testing_scenario) Passed = false; return; } if (cursor.get() != '.') { raise << maybe(current_recipe_name()) << "row " << row << " of the expected screen is too long\n" << end(); if (!Scenario_testing_scenario) Passed = false; return; } } cursor.skip_whitespace_and_comments(); if (!cursor.at_end()) { raise << maybe(current_recipe_name()) << "expected screen has too many rows\n" << end(); Passed = false; } } const char* unicode_character_at(int addr) { int unicode_code_point = static_cast<int>(get_or_insert(Memory, addr)); return to_unicode(unicode_code_point); } raw_string_stream::raw_string_stream(const string& backing) :index(0), max(SIZE(backing)), 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' << end(); 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") put(Recipe_ordinal, "$dump-screen", _DUMP_SCREEN); :(before "End Primitive Recipe Checks") case _DUMP_SCREEN: { break; } :(before "End Primitive Recipe Implementations") case _DUMP_SCREEN: { dump_screen(); break; } :(code) void dump_screen() { int screen_location = get_or_insert(Memory, SCREEN+/*skip address alloc id*/1) + /*skip payload alloc id*/1; reagent screen("x:screen"); // just to ensure screen.type is reclaimed int screen_data_location = find_element_location(screen_location, "data", screen.type, "check_screen"); // type: address:array:character assert(screen_data_location >= 0); //? cerr << "screen data is at location " << screen_data_location << '\n'; int screen_data_start = get_or_insert(Memory, screen_data_location+/*skip address alloc id*/1) + /*skip payload alloc id*/1; // type: array:character //? cerr << "screen data start is at " << screen_data_start << '\n'; int screen_width_location = find_element_location(screen_location, "num-columns", screen.type, "check_screen"); //? cerr << "screen width is at location " << screen_width_location << '\n'; int screen_width = get_or_insert(Memory, screen_width_location); //? cerr << "screen width: " << screen_width << '\n'; int screen_height_location = find_element_location(screen_location, "num-rows", screen.type, "check_screen"); //? cerr << "screen height is at location " << screen_height_location << '\n'; int screen_height = get_or_insert(Memory, screen_height_location); //? cerr << "screen height: " << screen_height << '\n'; int top_index_location= find_element_location(screen_location, "top-idx", screen.type, "check_screen"); //? cerr << "top of screen is at location " << top_index_location << '\n'; int top_index = get_or_insert(Memory, top_index_location); //? cerr << "top of screen is index " << top_index << '\n'; for (int i=0, row=top_index/screen_width; i < screen_height; ++i, row=(row+1)%screen_height) { cerr << '.'; int curr = screen_data_start+/*length*/1+row*screen_width* /*size of screen-cell*/2; for (int col = 0; col < screen_width; ++col) { if (get_or_insert(Memory, curr)) cerr << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr))); else cerr << ' '; curr += /*size of screen-cell*/2; } cerr << ".\n"; } }