summary refs log blame commit diff stats
path: root/doc/pydoc/ranger.gui.bar.html
blob: 988c736be6fc283ae7c8984382374104b10f6120 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                                              
                                                                   






                                                                                                                                                                                                                                          
                                                                                                                                                                                                   
                                                                                                                              
     



                                                                                                                                           
     






                                                                                                                                                                              







                                                                                                  
                                                                                                                                    




                                                                                   
                                                                                    










                                                                                                           
                                                                                                                                                               








































                                                                                                                                    
                                                                                                                                                                   



                                                                         

                                                           























                                                                                                                    
                                                                          

































                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                 






                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                  


                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                  



                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                    

                                                                                                                                                                                                                                          
                                                                                                                                                                   





                                                                                                                                                                                                  
                                                                                                                                                                                                            

    
                                                                                            

                                             
                                                                                                                                                                                                                                                                                                 




                                                                           
                                                                                                                                                                                   




















                                                                                                 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.bar</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.gui.html"><font color="#ffffff">gui</font></a>.bar</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/code/ranger/ranger/gui/bar.py">/home/hut/code/ranger/ranger/gui/bar.py</a></font></td></tr></table>
    <p><tt>#&nbsp;Copyright&nbsp;(C)&nbsp;2009,&nbsp;2010&nbsp;&nbsp;Roman&nbsp;Zimbelmann&nbsp;&lt;romanz@lavabit.com&gt;<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
#&nbsp;it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
#&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;either&nbsp;version&nbsp;3&nbsp;of&nbsp;the&nbsp;License,&nbsp;or<br>
#&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
#&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
#&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
#&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
#<br>
#&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License<br>
#&nbsp;along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see&nbsp;&lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.</tt></p>
<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="builtins.html#list">builtins.list</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.bar.html#BarSide">BarSide</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.bar.html#Bar">Bar</a>
</font></dt><dt><font face="helvetica, arial"><a href="ranger.gui.bar.html#ColoredString">ColoredString</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="Bar">class <strong>Bar</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Bar-__init__"><strong>__init__</strong></a>(self, base_color_tag)</dt></dl>

<dl><dt><a name="Bar-add"><strong>add</strong></a>(self, *a, **kw)</dt></dl>

<dl><dt><a name="Bar-addright"><strong>addright</strong></a>(self, *a, **kw)</dt></dl>

<dl><dt><a name="Bar-combine"><strong>combine</strong></a>(self)</dt></dl>

<dl><dt><a name="Bar-fill_gap"><strong>fill_gap</strong></a>(self, char, wid, gapwidth<font color="#909090">=False</font>)</dt></dl>

<dl><dt><a name="Bar-fixedsize"><strong>fixedsize</strong></a>(self)</dt></dl>

<dl><dt><a name="Bar-shrink_by_cutting"><strong>shrink_by_cutting</strong></a>(self, wid)</dt></dl>

<dl><dt><a name="Bar-shrink_by_removing"><strong>shrink_by_removing</strong></a>(self, wid)</dt></dl>

<dl><dt><a name="Bar-sumsize"><strong>sumsize</strong></a>(self)</dt></dl>

<hr>
Data descriptors defined here:<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 defined here:<br>
<dl><dt><strong>gap</strong> = None</dl>

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

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

</td></tr></table> <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="BarSide">class <strong>BarSide</strong></a>(<a href="builtins.html#list">builtins.list</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="ranger.gui.bar.html#BarSide">BarSide</a></dd>
<dd><a href="builtins.html#list">builtins.list</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="BarSide-__init__"><strong>__init__</strong></a>(self, base_color_tag)</dt></dl>

<dl><dt><a name="BarSide-add"><strong>add</strong></a>(self, string, *lst, **kw)</dt></dl>

<dl><dt><a name="BarSide-add_space"><strong>add_space</strong></a>(self, n<font color="#909090">=1</font>)</dt></dl>

<dl><dt><a name="BarSide-fixedsize"><strong>fixedsize</strong></a>(self)</dt></dl>

<dl><dt><a name="BarSide-nonfixed_items"><strong>nonfixed_items</strong></a>(self)</dt></dl>

<dl><dt><a name="BarSide-sumsize"><strong>sumsize</strong></a>(self)</dt></dl>

<hr>
Data descriptors defined here:<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>
Methods inherited from <a href="builtins.html#list">builtins.list</a>:<br>
<dl><dt><a name="BarSide-__add__"><strong>__add__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__add__">__add__</a>(y)&nbsp;&lt;==&gt;&nbsp;x+y</tt></dd></dl>

<dl><dt><a name="BarSide-__contains__"><strong>__contains__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__contains__">__contains__</a>(y)&nbsp;&lt;==&gt;&nbsp;y&nbsp;in&nbsp;x</tt></dd></dl>

<dl><dt><a name="BarSide-__delitem__"><strong>__delitem__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__delitem__">__delitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;del&nbsp;x[y]</tt></dd></dl>

<dl><dt><a name="BarSide-__eq__"><strong>__eq__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__eq__">__eq__</a>(y)&nbsp;&lt;==&gt;&nbsp;x==y</tt></dd></dl>

<dl><dt><a name="BarSide-__ge__"><strong>__ge__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__ge__">__ge__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&gt;=y</tt></dd></dl>

<dl><dt><a name="BarSide-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>

<dl><dt><a name="BarSide-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl>

<dl><dt><a name="BarSide-__gt__"><strong>__gt__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__gt__">__gt__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&gt;y</tt></dd></dl>

<dl><dt><a name="BarSide-__iadd__"><strong>__iadd__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__iadd__">__iadd__</a>(y)&nbsp;&lt;==&gt;&nbsp;x+=y</tt></dd></dl>

<dl><dt><a name="BarSide-__imul__"><strong>__imul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__imul__">__imul__</a>(y)&nbsp;&lt;==&gt;&nbsp;x*=y</tt></dd></dl>

<dl><dt><a name="BarSide-__iter__"><strong>__iter__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__iter__">__iter__</a>()&nbsp;&lt;==&gt;&nbsp;iter(x)</tt></dd></dl>

<dl><dt><a name="BarSide-__le__"><strong>__le__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__le__">__le__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&lt;=y</tt></dd></dl>

<dl><dt><a name="BarSide-__len__"><strong>__len__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__len__">__len__</a>()&nbsp;&lt;==&gt;&nbsp;len(x)</tt></dd></dl>

<dl><dt><a name="BarSide-__lt__"><strong>__lt__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__lt__">__lt__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&lt;y</tt></dd></dl>

<dl><dt><a name="BarSide-__mul__"><strong>__mul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__mul__">__mul__</a>(n)&nbsp;&lt;==&gt;&nbsp;x*n</tt></dd></dl>

<dl><dt><a name="BarSide-__ne__"><strong>__ne__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__ne__">__ne__</a>(y)&nbsp;&lt;==&gt;&nbsp;x!=y</tt></dd></dl>

<dl><dt><a name="BarSide-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>

<dl><dt><a name="BarSide-__reversed__"><strong>__reversed__</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-__reversed__">__reversed__</a>()&nbsp;--&nbsp;return&nbsp;a&nbsp;reverse&nbsp;iterator&nbsp;over&nbsp;the&nbsp;<a href="builtins.html#list">list</a></tt></dd></dl>

<dl><dt><a name="BarSide-__rmul__"><strong>__rmul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__rmul__">__rmul__</a>(n)&nbsp;&lt;==&gt;&nbsp;n*x</tt></dd></dl>

<dl><dt><a name="BarSide-__setitem__"><strong>__setitem__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__setitem__">__setitem__</a>(i,&nbsp;y)&nbsp;&lt;==&gt;&nbsp;x[i]=y</tt></dd></dl>

<dl><dt><a name="BarSide-__sizeof__"><strong>__sizeof__</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-__sizeof__">__sizeof__</a>()&nbsp;--&nbsp;size&nbsp;of&nbsp;L&nbsp;in&nbsp;memory,&nbsp;in&nbsp;bytes</tt></dd></dl>

<dl><dt><a name="BarSide-append"><strong>append</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-append">append</a>(<a href="builtins.html#object">object</a>)&nbsp;--&nbsp;append&nbsp;<a href="builtins.html#object">object</a>&nbsp;to&nbsp;end</tt></dd></dl>

<dl><dt><a name="BarSide-count"><strong>count</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-count">count</a>(value)&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;number&nbsp;of&nbsp;occurrences&nbsp;of&nbsp;value</tt></dd></dl>

<dl><dt><a name="BarSide-extend"><strong>extend</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-extend">extend</a>(iterable)&nbsp;--&nbsp;extend&nbsp;<a href="builtins.html#list">list</a>&nbsp;by&nbsp;appending&nbsp;elements&nbsp;from&nbsp;the&nbsp;iterable</tt></dd></dl>

<dl><dt><a name="BarSide-index"><strong>index</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-index">index</a>(value,&nbsp;[start,&nbsp;[stop]])&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;first&nbsp;index&nbsp;of&nbsp;value.<br>
Raises&nbsp;ValueError&nbsp;if&nbsp;the&nbsp;value&nbsp;is&nbsp;not&nbsp;present.</tt></dd></dl>

<dl><dt><a name="BarSide-insert"><strong>insert</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-insert">insert</a>(index,&nbsp;<a href="builtins.html#object">object</a>)&nbsp;--&nbsp;insert&nbsp;<a href="builtins.html#object">object</a>&nbsp;before&nbsp;index</tt></dd></dl>

<dl><dt><a name="BarSide-pop"><strong>pop</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-pop">pop</a>([index])&nbsp;-&gt;&nbsp;item&nbsp;--&nbsp;remove&nbsp;and&nbsp;return&nbsp;item&nbsp;at&nbsp;index&nbsp;(default&nbsp;last).<br>
Raises&nbsp;IndexError&nbsp;if&nbsp;<a href="builtins.html#list">list</a>&nbsp;is&nbsp;empty&nbsp;or&nbsp;index&nbsp;is&nbsp;out&nbsp;of&nbsp;range.</tt></dd></dl>

<dl><dt><a name="BarSide-remove"><strong>remove</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-remove">remove</a>(value)&nbsp;--&nbsp;remove&nbsp;first&nbsp;occurrence&nbsp;of&nbsp;value.<br>
Raises&nbsp;ValueError&nbsp;if&nbsp;the&nbsp;value&nbsp;is&nbsp;not&nbsp;present.</tt></dd></dl>

<dl><dt><a name="BarSide-reverse"><strong>reverse</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-reverse">reverse</a>()&nbsp;--&nbsp;reverse&nbsp;*IN&nbsp;PLACE*</tt></dd></dl>

<dl><dt><a name="BarSide-sort"><strong>sort</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-sort">sort</a>(key=None,&nbsp;reverse=False)&nbsp;--&nbsp;stable&nbsp;sort&nbsp;*IN&nbsp;PLACE*</tt></dd></dl>

<hr>
Data and other attributes inherited from <a href="builtins.html#list">builtins.list</a>:<br>
<dl><dt><strong>__hash__</strong> = None</dl>

<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#BarSide-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="builtins.html#object">object</a>&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>

</td></tr></table> <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="ColoredString">class <strong>ColoredString</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="ColoredString-__init__"><strong>__init__</strong></a>(self, string, *lst)</dt></dl>

<dl><dt><a name="ColoredString-__len__"><strong>__len__</strong></a>(self)</dt></dl>

<dl><dt><a name="ColoredString-__str__"><strong>__str__</strong></a>(self)</dt></dl>

<dl><dt><a name="ColoredString-cut_off"><strong>cut_off</strong></a>(self, n)</dt></dl>

<dl><dt><a name="ColoredString-cut_off_to"><strong>cut_off_to</strong></a>(self, n)</dt></dl>

<hr>
Data descriptors defined here:<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>
</td></tr></table></td></tr></table>
</body></html>
"o">="Special"> &lt;- </span>greater-or-equal cursor-column, screen-width <span class="muControl">break-if</span> at-right? curr:address:duplex-list:character<span class="Special"> &lt;- </span>copy before-cursor move-cursor screen, save-row, save-column curr-column:number<span class="Special"> &lt;- </span>copy save-column <span class="Delimiter">{</span> <span class="Comment"># hit right margin? give up and let caller render</span> go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span> at-right?:boolean<span class="Special"> &lt;- </span>greater-than curr-column, right <span class="muControl">return-if</span> at-right? <span class="muControl">break-unless</span> curr <span class="Comment"># newline? done.</span> currc:character<span class="Special"> &lt;- </span>get *curr, <span class="Constant">value:offset</span> at-newline?:boolean<span class="Special"> &lt;- </span>equal currc, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? print screen, currc curr-column<span class="Special"> &lt;- </span>add curr-column, <span class="Constant">1</span> curr<span class="Special"> &lt;- </span>next curr <span class="muControl">loop</span> <span class="Delimiter">}</span> go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span> <span class="muControl">return</span> ] <span class="Comment"># helper for tests</span> <span class="muRecipe">def</span> editor-render screen:address:screen, editor:address:editor-data<span class="muRecipe"> -&gt; </span>screen:address:screen, editor:address:editor-data [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> left:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">left:offset</span> right:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">right:offset</span> row:number, column:number<span class="Special"> &lt;- </span>render screen, editor clear-line-delimited screen, column, right row<span class="Special"> &lt;- </span>add row, <span class="Constant">1</span> draw-horizontal screen, row, left, right, <span class="Constant">9480/horizontal-dotted</span> row<span class="Special"> &lt;- </span>add row, <span class="Constant">1</span> clear-screen-from screen, row, left, left, right ] <span class="muScenario">scenario</span> editor-handles-empty-event-queue [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data assume-console <span class="Constant">[]</span> run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abc .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">1</span>, <span class="Constant">1</span> <span class="Comment"># on the 'b'</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abc .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor is at row 0..</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># ..and column 1</span> ] check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">1</span>, <span class="Constant">7</span> <span class="Comment"># last line, to the right of text</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span> <span class="Comment"># cursor column</span> ] check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text-2 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span> <span class="Constant">def]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">1</span>, <span class="Constant">7</span> <span class="Comment"># interior line, to the right of text</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span> <span class="Comment"># cursor column</span> ] check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text-3 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span> <span class="Constant">def]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">3</span>, <span class="Constant">7</span> <span class="Comment"># below text</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">2</span> <span class="Comment"># cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span> <span class="Comment"># cursor column</span> ] check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-column [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Comment"># editor occupies only left half of screen</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ <span class="Comment"># click on right half of screen</span> left-click <span class="Constant">3</span>, <span class="Constant">8</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abc .</span> <span class="Constant"> .┈┈┈┈┈ .</span> <span class="Constant"> . .</span> ] memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># no change to cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># ..or column</span> ] check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-in-menu-area [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ <span class="Comment"># click on first, 'menu' row</span> left-click <span class="Constant">0</span>, <span class="Constant">3</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># no change to cursor</span> memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> editor-inserts-characters-into-empty-editor [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ type <span class="Constant">[abc]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abc .</span> <span class="Constant"> .┈┈┈┈┈ .</span> <span class="Constant"> . .</span> ] check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> <span class="Comment"># type two letters at different places</span> assume-console [ type <span class="Constant">[0]</span> left-click <span class="Constant">1</span>, <span class="Constant">2</span> type <span class="Constant">[d]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .0adbc .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] check-trace-count-for-label <span class="Constant">7</span>, <span class="Constant">[print-character]</span> <span class="Comment"># 4 for first letter, 3 for second</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-2 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">1</span>, <span class="Constant">5</span> <span class="Comment"># right of last line</span> type <span class="Constant">[d]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcd .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-5 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">1</span>, <span class="Constant">5</span> <span class="Comment"># right of non-last line</span> type <span class="Constant">[e]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abce .</span> <span class="Constant"> .d .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-3 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">3</span>, <span class="Constant">5</span> <span class="Comment"># below all text</span> type <span class="Constant">[d]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcd .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-4 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">3</span>, <span class="Constant">5</span> <span class="Comment"># below all text</span> type <span class="Constant">[e]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abc .</span> <span class="Constant"> .de .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-6 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Constant"> $clear-trace</span> assume-console [ left-click <span class="Constant">3</span>, <span class="Constant">5</span> <span class="Comment"># below all text</span> type <span class="Constant">[ef]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abc .</span> <span class="Constant"> .def .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-after-inserting-characters [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[ab]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data assume-console [ type <span class="Constant">[01]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .01ab .</span> <span class="Constant"> .┈┈┈┈┈ .</span> <span class="Constant"> . .</span> ] ] <span class="Comment"># if the cursor reaches the right margin, wrap the line</span> <span class="muScenario">scenario</span> editor-wraps-line-on-insert [ assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Comment"># type a letter</span> assume-console [ type <span class="Constant">[e]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># no wrap yet</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .eabc .</span> <span class="Constant"> .┈┈┈┈┈.</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> ] <span class="Comment"># type a second letter</span> assume-console [ type <span class="Constant">[f]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># now wrap</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .efab↩.</span> <span class="Constant"> .c .</span> <span class="Constant"> .┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] ] <span class="muScenario">scenario</span> editor-wraps-line-on-insert-2 [ <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcdefg</span> <span class="Constant">defg]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, <span class="Constant">2</span>:address:editor-data <span class="Comment"># type more text at the start</span> assume-console [ left-click <span class="Constant">3</span>, <span class="Constant">0</span> type <span class="Constant">[abc]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor is not wrapped</span> memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">3</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span> ] <span class="Comment"># but line is wrapped</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcd↩ .</span> <span class="Constant"> .efg .</span> <span class="Constant"> .abcd↩ .</span> <span class="Constant"> .efg .</span> ] ] <span class="muRecipe">after</span> <span class="Constant">&lt;insert-character-special-case&gt;</span> [ <span class="Comment"># if the line wraps at the cursor, move cursor to start of next row</span> <span class="Delimiter">{</span> <span class="Comment"># if we're at the column just before the wrap indicator</span> wrap-column:number<span class="Special"> &lt;- </span>subtract right, <span class="Constant">1</span> at-wrap?:boolean<span class="Special"> &lt;- </span>greater-or-equal cursor-column, wrap-column <span class="muControl">break-unless</span> at-wrap? cursor-column<span class="Special"> &lt;- </span>subtract cursor-column, wrap-column cursor-column<span class="Special"> &lt;- </span>add cursor-column, left *editor<span class="Special"> &lt;- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column cursor-row<span class="Special"> &lt;- </span>add cursor-row, <span class="Constant">1</span> *editor<span class="Special"> &lt;- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row <span class="Comment"># if we're out of the screen, scroll down</span> <span class="Delimiter">{</span> below-screen?:boolean<span class="Special"> &lt;- </span>greater-or-equal cursor-row, screen-height <span class="muControl">break-unless</span> below-screen? <span class="Constant"> &lt;scroll-down&gt;</span> <span class="Delimiter">}</span> go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="muScenario">scenario</span> editor-wraps-cursor-after-inserting-characters [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcde]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ left-click <span class="Constant">1</span>, <span class="Constant">4</span> <span class="Comment"># line is full; no wrap icon yet</span> type <span class="Constant">[f]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcd↩ .</span> <span class="Constant"> .fe .</span> <span class="Constant"> .┈┈┈┈┈ .</span> <span class="Constant"> . .</span> ] memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">2</span> <span class="Comment"># cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> editor-wraps-cursor-after-inserting-characters-2 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcde]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ left-click <span class="Constant">1</span>, <span class="Constant">3</span> <span class="Comment"># right before the wrap icon</span> type <span class="Constant">[f]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcf↩ .</span> <span class="Constant"> .de .</span> <span class="Constant"> .┈┈┈┈┈ .</span> <span class="Constant"> . .</span> ] memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">2</span> <span class="Comment"># cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> editor-wraps-cursor-to-left-margin [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcde]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">2/left</span>, <span class="Constant">7/right</span> assume-console [ left-click <span class="Constant">1</span>, <span class="Constant">5</span> <span class="Comment"># line is full; no wrap icon yet</span> type <span class="Constant">[01]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> . abc0↩ .</span> <span class="Constant"> . 1de .</span> <span class="Constant"> . ┈┈┈┈┈ .</span> <span class="Constant"> . .</span> ] memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">2</span> <span class="Comment"># cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span> <span class="Comment"># cursor column</span> ] ] <span class="Comment"># if newline, move cursor to start of next line, and maybe align indent with previous line</span> <span class="muData">container</span> editor-data [ indent?:boolean ] <span class="muRecipe">after</span> <span class="Constant">&lt;editor-initialization&gt;</span> [ *result<span class="Special"> &lt;- </span>put *result, <span class="Constant">indent?:offset</span>, <span class="Constant">1/true</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-down-after-inserting-newline [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ type <span class="Constant">[0</span> <span class="Constant">1]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .0 .</span> <span class="Constant"> .1abc .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] ] <span class="muRecipe">after</span> <span class="Constant">&lt;handle-special-character&gt;</span> [ <span class="Delimiter">{</span> newline?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> newline? <span class="Constant"> &lt;insert-enter-begin&gt;</span> editor<span class="Special"> &lt;- </span>insert-new-line-and-indent editor, screen <span class="Constant"> &lt;insert-enter-end&gt;</span> go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="muRecipe">def</span> insert-new-line-and-indent editor:address:editor-data, screen:address:screen<span class="muRecipe"> -&gt; </span>editor:address:editor-data, screen:address:screen, go-render?:boolean [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> cursor-row:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">cursor-row:offset</span> cursor-column:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">cursor-column:offset</span> before-cursor:address:duplex-list:character<span class="Special"> &lt;- </span>get *editor, <span class="Constant">before-cursor:offset</span> left:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">left:offset</span> right:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">right:offset</span> screen-height:number<span class="Special"> &lt;- </span>screen-height screen <span class="Comment"># insert newline</span> insert <span class="Constant">10/newline</span>, before-cursor before-cursor<span class="Special"> &lt;- </span>next before-cursor *editor<span class="Special"> &lt;- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor cursor-row<span class="Special"> &lt;- </span>add cursor-row, <span class="Constant">1</span> *editor<span class="Special"> &lt;- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row cursor-column<span class="Special"> &lt;- </span>copy left *editor<span class="Special"> &lt;- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="Comment"># maybe scroll</span> <span class="Delimiter">{</span> below-screen?:boolean<span class="Special"> &lt;- </span>greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal, never greater</span> <span class="muControl">break-unless</span> below-screen? <span class="Constant"> &lt;scroll-down&gt;</span> go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span> cursor-row<span class="Special"> &lt;- </span>subtract cursor-row, <span class="Constant">1</span> <span class="Comment"># bring back into screen range</span> *editor<span class="Special"> &lt;- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row <span class="Delimiter">}</span> <span class="Comment"># indent if necessary</span> indent?:boolean<span class="Special"> &lt;- </span>get *editor, <span class="Constant">indent?:offset</span> <span class="muControl">return-unless</span> indent? d:address:duplex-list:character<span class="Special"> &lt;- </span>get *editor, <span class="Constant">data:offset</span> end-of-previous-line:address:duplex-list:character<span class="Special"> &lt;- </span>prev before-cursor indent:number<span class="Special"> &lt;- </span>line-indent end-of-previous-line, d i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> indent-done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, indent <span class="muControl">break-if</span> indent-done? editor, screen, go-render?:boolean<span class="Special"> &lt;- </span>insert-at-cursor editor, <span class="Constant">32/space</span>, screen i<span class="Special"> &lt;- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="Comment"># takes a pointer 'curr' into the doubly-linked list and its sentinel, counts</span> <span class="Comment"># the number of spaces at the start of the line containing 'curr'.</span> <span class="muRecipe">def</span> line-indent curr:address:duplex-list:character, start:address:duplex-list:character<span class="muRecipe"> -&gt; </span>result:number [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> result:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span> <span class="muControl">return-unless</span> curr at-start?:boolean<span class="Special"> &lt;- </span>equal curr, start <span class="muControl">return-if</span> at-start? <span class="Delimiter">{</span> curr<span class="Special"> &lt;- </span>prev curr <span class="muControl">break-unless</span> curr at-start?:boolean<span class="Special"> &lt;- </span>equal curr, start <span class="muControl">break-if</span> at-start? c:character<span class="Special"> &lt;- </span>get *curr, <span class="Constant">value:offset</span> at-newline?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? <span class="Comment"># if c is a space, increment result</span> is-space?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">32/space</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> is-space? result<span class="Special"> &lt;- </span>add result, <span class="Constant">1</span> <span class="Delimiter">}</span> <span class="Comment"># if c is not a space, reset result</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> is-space? result<span class="Special"> &lt;- </span>copy <span class="Constant">0</span> <span class="Delimiter">}</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-down-after-inserting-newline-2 [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">1/left</span>, <span class="Constant">10/right</span> assume-console [ type <span class="Constant">[0</span> <span class="Constant">1]</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> . 0 .</span> <span class="Constant"> . 1abc .</span> <span class="Constant"> . ┈┈┈┈┈┈┈┈┈.</span> <span class="Constant"> . .</span> ] ] <span class="muScenario">scenario</span> editor-clears-previous-line-completely-after-inserting-newline [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcde]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ press enter ] screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcd↩ .</span> <span class="Constant"> .e .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># line should be fully cleared</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> .abcd↩ .</span> <span class="Constant"> .e .</span> <span class="Constant"> .┈┈┈┈┈ .</span> ] ] <span class="muScenario">scenario</span> editor-inserts-indent-after-newline [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">10/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[ab</span> <span class="Constant"> cd</span> <span class="Constant">ef]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># position cursor after 'cd' and hit 'newline'</span> assume-console [ left-click <span class="Constant">2</span>, <span class="Constant">8</span> type [ ] ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor should be below start of previous line</span> memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">3</span> <span class="Comment"># cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">2</span> <span class="Comment"># cursor column (indented)</span> ] ] <span class="muScenario">scenario</span> editor-skips-indent-around-paste [ assume-screen <span class="Constant">10/width</span>, <span class="Constant">10/height</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[ab</span> <span class="Constant"> cd</span> <span class="Constant">ef]</span> <span class="Constant">2</span>:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># position cursor after 'cd' and hit 'newline' surrounded by paste markers</span> assume-console [ left-click <span class="Constant">2</span>, <span class="Constant">8</span> press <span class="Constant">65507</span> <span class="Comment"># start paste</span> press enter press <span class="Constant">65506</span> <span class="Comment"># end paste</span> ] run [ editor-event-loop screen:address:screen, console:address:console, <span class="Constant">2</span>:address:editor-data <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor should be below start of previous line</span> memory-should-contain [ <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">3</span> <span class="Comment"># cursor row</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># cursor column (not indented)</span> ] ] <span class="muRecipe">after</span> <span class="Constant">&lt;handle-special-key&gt;</span> [ <span class="Delimiter">{</span> paste-start?:boolean<span class="Special"> &lt;- </span>equal k, <span class="Constant">65507/paste-start</span> <span class="muControl">break-unless</span> paste-start? *editor<span class="Special"> &lt;- </span>put *editor, <span class="Constant">indent?:offset</span>, <span class="Constant">0/false</span> go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="muRecipe">after</span> <span class="Constant">&lt;handle-special-key&gt;</span> [ <span class="Delimiter">{</span> paste-end?:boolean<span class="Special"> &lt;- </span>equal k, <span class="Constant">65506/paste-end</span> <span class="muControl">break-unless</span> paste-end? *editor<span class="Special"> &lt;- </span>put *editor, <span class="Constant">indent?:offset</span>, <span class="Constant">1/true</span> go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="SalientComment">## helpers</span> <span class="muRecipe">def</span> draw-horizontal screen:address:screen, row:number, x:number, right:number<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> style:character, style-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> style-found? style<span class="Special"> &lt;- </span>copy <span class="Constant">9472/horizontal</span> <span class="Delimiter">}</span> color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> <span class="muControl">break-if</span> color-found? color<span class="Special"> &lt;- </span>copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> bg-color-found? bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> screen<span class="Special"> &lt;- </span>move-cursor screen, row, x <span class="Delimiter">{</span> continue?:boolean<span class="Special"> &lt;- </span>lesser-or-equal x, right <span class="Comment"># right is inclusive, to match editor-data semantics</span> <span class="muControl">break-unless</span> continue? print screen, style, color, bg-color x<span class="Special"> &lt;- </span>add x, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] </pre> </body> </html> <!-- vim: set foldmethod=manual : -->