1 # Some useful helpers for dealing with text (arrays of characters)
   2 
   3 def equal a:text, b:text -> result:bool [
   4   local-scope
   5   load-inputs
   6   an:num, bn:num <- deaddress a, b
   7   address-equal?:boolean <- equal an, bn
   8   return-if address-equal?, true
   9   return-unless a, false
  10   return-unless b, false
  11   a-len:num <- length *a
  12   b-len:num <- length *b
  13   # compare lengths
  14   trace 99, [text-equal], [comparing lengths]
  15   length-equal?:bool <- equal a-len, b-len
  16   return-unless length-equal?, false
  17   # compare each corresponding character
  18   trace 99, [text-equal], [comparing characters]
  19   i:num <- copy 0
  20   {
  21     done?:bool <- greater-or-equal i, a-len
  22     break-if done?
  23     a2:char <- index *a, i
  24     b2:char <- index *b, i
  25     chars-match?:bool <- equal a2, b2
  26     return-unless chars-match?, false
  27     i <- add i, 1
  28     loop
  29   }
  30   return true
  31 ]
  32 
  33 scenario text-equal-reflexive [
  34   local-scope
  35   x:text <- new [abc]
  36   run [
  37     10:bool/raw <- equal x, x
  38   ]
  39   memory-should-contain [
  40     10 <- 1  # x == x for all x
  41   ]
  42 ]
  43 
  44 scenario text-equal-identical [
  45   local-scope
  46   x:text <- new [abc]
  47   y:text <- new [abc]
  48   run [
  49     10:bool/raw <- equal x, y
  50   ]
  51   memory-should-contain [
  52     10 <- 1  # abc == abc
  53   ]
  54 ]
  55 
  56 scenario text-equal-distinct-lengths [
  57   local-scope
  58   x:text <- new [abc]
  59   y:text <- new [abcd]
  60   run [
  61     10:bool/raw <- equal x, y
  62   ]
  63   memory-should-contain [
  64     10 <- 0  # abc != abcd
  65   ]
  66   trace-should-contain [
  67     text-equal: comparing lengths
  68   ]
  69   trace-should-not-contain [
  70     text-equal: comparing characters
  71   ]
  72 ]
  73 
  74 scenario text-equal-with-empty [
  75   local-scope
  76   x:text <- new []
  77   y:text <- new [abcd]
  78   run [
  79     10:bool/raw <- equal x, y
  80   ]
  81   memory-should-contain [
  82     10 <- 0  # "" != abcd
  83   ]
  84 ]
  85 
  86 scenario text-equal-with-null [
  87   local-scope
  88   x:text <- new [abcd]
  89   y:text <- copy null
  90   run [
  91     10:bool/raw <- equal x, null
  92     11:bool/raw <- equal null, x
  93     12:bool/raw <- equal x, y
  94     13:bool/raw <- equal y, x
  95     14:bool/raw <- equal y, y
  96   ]
  97   memory-should-contain [
  98     10 <- 0
  99     11 <- 0
 100     12 <- 0
 101     13 <- 0
 102     14 <- 1
 103   ]
 104   check-trace-count-for-label 0, [error]
 105 ]
 106 
 107 scenario text-equal-common-lengths-but-distinct [
 108   local-scope
 109   x:text <- new [abc]
 110   y:text <- new [abd]
 111   run [
 112     10:bool/raw <- equal x, y
 113   ]
 114   memory-should-contain [
 115     10 <- 0  # abc != abd
 116   ]
 117 ]
 118 
 119 # A new type to help incrementally construct texts.
 120 container buffer:_elem [
 121   length:num
 122   data:&:@:_elem
 123 ]
 124 
 125 def new-buffer capacity:num -> result:&:buffer:_elem [
 126   local-scope
 127   load-inputs
 128   result <- new {(buffer _elem): type}
 129   *result <- put *result, length:offset, 0
 130   {
 131     break-if capacity
 132     # capacity not provided
 133     capacity <- copy 10
 134   }
 135   data:&:@:_elem <- new _elem:type, capacity
 136   *result <- put *result, data:offset, data
 137   return result
 138 ]
 139 
 140 def grow-buffer buf:&:buffer:_elem -> buf:&:buffer:_elem [
 141   local-scope
 142   load-inputs
 143   # double buffer size
 144   olddata:&:@:_elem <- get *buf, data:offset
 145   oldlen:num <- length *olddata
 146   newlen:num <- multiply oldlen, 2
 147   newdata:&:@:_elem <- new _elem:type, newlen
 148   *buf <- put *buf, data:offset, newdata
 149   # copy old contents
 150   i:num <- copy 0
 151   {
 152     done?:bool <- greater-or-equal i, oldlen
 153     break-if done?
 154     src:_elem <- index *olddata, i
 155     *newdata <- put-index *newdata, i, src
 156     i <- add i, 1
 157     loop
 158   }
 159 ]
 160 
 161 def buffer-full? in:&:buffer:_elem -> result:bool [
 162   local-scope
 163   load-inputs
 164   len:num <- get *in, length:offset
 165   s:&:@:_elem <- get *in, data:offset
 166   capacity:num <- length *s
 167   result <- greater-or-equal len, capacity
 168 ]
 169 
 170 # most broadly applicable definition of append to a buffer
 171 def append buf:&:buffer:_elem, x:_elem -> buf:&:buffer:_elem [
 172   local-scope
 173   load-inputs
 174   len:num <- get *buf, length:offset
 175   {
 176     # grow buffer if necessary
 177     full?:bool <- buffer-full? buf
 178     break-unless full?
 179     buf <- grow-buffer buf
 180   }
 181   s:&:@:_elem <- get *buf, data:offset
 182   *s <- put-index *s, len, x
 183   len <- add len, 1
 184   *buf <- put *buf, length:offset, len
 185 ]
 186 
 187 # most broadly applicable definition of append to a buffer of characters: just
 188 # call to-text
 189 def append buf:&:buffer:char, x:_elem -> buf:&:buffer:char [
 190   local-scope
 191   load-inputs
 192   text:text <- to-text x
 193   buf <- append buf, text
 194 ]
 195 
 196 # specialization for characters that is backspace-aware
 197 def append buf:&:buffer:char, c:char -> buf:&:buffer:char [
 198   local-scope
 199   load-inputs
 200   len:num <- get *buf, length:offset
 201   {
 202     # backspace? just drop last character if it exists and return
 203     backspace?:bool <- equal c, 8/backspace
 204     break-unless backspace?
 205     empty?:bool <- lesser-or-equal len, 0
 206     return-if empty?
 207     len <- subtract len, 1
 208     *buf <- put *buf, length:offset, len
 209     return
 210   }
 211   {
 212     # grow buffer if necessary
 213     full?:bool <- buffer-full? buf
 214     break-unless full?
 215     buf <- grow-buffer buf
 216   }
 217   s:text <- get *buf, data:offset
 218   *s <- put-index *s, len, c
 219   len <- add len, 1
 220   *buf <- put *buf, length:offset, len
 221 ]
 222 
 223 def append buf:&:buffer:_elem, t:&:@:_elem -> buf:&:buffer:_elem [
 224   local-scope
 225   load-inputs
 226   len:num <- length *t
 227   i:num <- copy 0
 228   {
 229     done?:bool <- greater-or-equal i, len
 230     break-if done?
 231     x:_elem <- index *t, i
 232     buf <- append buf, x
 233     i <- add i, 1
 234     loop
 235   }
 236 ]
 237 
 238 scenario append-to-empty-buffer [
 239   local-scope
 240   x:&:buffer:char <- new-buffer
 241   run [
 242     c:char <- copy 97/a
 243     x <- append x, c
 244     10:num/raw <- get *x, length:offset
 245     s:text <- get *x, data:offset
 246     11:char/raw <- index *s, 0
 247     12:char/raw <- index *s, 1
 248   ]
 249   memory-should-contain [
 250     10 <- 1  # buffer length
 251     11 <- 97  # a
 252     12 <- 0  # rest of buffer is empty
 253   ]
 254 ]
 255 
 256 scenario append-to-buffer [
 257   local-scope
 258   x:&:buffer:char <- new-buffer
 259   c:char <- copy 97/a
 260   x <- append x, c
 261   run [
 262     c <- copy 98/b
 263     x <- append x, c
 264     10:num/raw <- get *x, length:offset
 265     s:text <- get *x, data:offset
 266     11:char/raw <- index *s, 0
 267     12:char/raw <- index *s, 1
 268     13:char/raw <- index *s, 2
 269   ]
 270   memory-should-contain [
 271     10 <- 2  # buffer length
 272     11 <- 97  # a
 273     12 <- 98  # b
 274     13 <- 0  # rest of buffer is empty
 275   ]
 276 ]
 277 
 278 scenario append-grows-buffer [
 279   local-scope
 280   x:&:buffer:char <- new-buffer 3
 281   s1:text <- get *x, data:offset
 282   x <- append x, [abc]  # buffer is now full
 283   s2:text <- get *x, data:offset
 284   run [
 285     10:bool/raw <- equal s1, s2
 286     11:@:char/raw <- copy *s2
 287     +buffer-filled
 288     c:char <- copy 100/d
 289     x <- append x, c
 290     s3:text <- get *x, data:offset
 291     20:bool/raw <- equal s1, s3
 292     21:num/raw <- get *x, length:offset
 293     30:@:char/raw <- copy *s3
 294   ]
 295   memory-should-contain [
 296     # before +buffer-filled
 297     10 <- 1   # no change in data pointer after original append
 298     11 <- 3   # size of data
 299     12 <- 97  # data
 300     13 <- 98
 301     14 <- 99
 302     # in the end
 303     20 <- 0   # data pointer has grown after second append
 304     21 <- 4   # final length
 305     30 <- 6   # but data's capacity has doubled
 306     31 <- 97  # data
 307     32 <- 98
 308     33 <- 99
 309     34 <- 100
 310     35 <- 0
 311     36 <- 0
 312   ]
 313 ]
 314 
 315 scenario buffer-append-handles-backspace [
 316   local-scope
 317   x:&:buffer:char <- new-buffer
 318   x <- append x, [ab]
 319   run [
 320     c:char <- copy 8/backspace
 321     x <- append x, c
 322     s:text <- buffer-to-array x
 323     10:@:char/raw <- copy *s
 324   ]
 325   memory-should-contain [
 326     10 <- 1   # length
 327     11 <- 97  # contents
 328     12 <- 0
 329   ]
 330 ]
 331 
 332 scenario append-to-buffer-of-non-characters [
 333   local-scope
 334   x:&:buffer:text <- new-buffer 1/capacity
 335   # no errors
 336 ]
 337 
 338 def buffer-to-array in:&:buffer:_elem -> result:&:@:_elem [
 339   local-scope
 340   load-inputs
 341   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.ui</title>
</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>.ui</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/ranger/ranger/gui/ui.py">/home/hut/ranger/ranger/gui/ui.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="#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>
<a href="curses.html">curses</a><br>
</td><td width="25%" valign=top><a href="os.html">os</a><br>
<a href="socket.html">socket</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</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.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a>(<a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.ui.html#UI">UI</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="UI">class <strong>UI</strong></a>(<a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</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.ui.html#UI">UI</a></dd>
<dd><a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a></dd>
<dd><a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a></dd>
<dd><a href="ranger.shared.html#EnvironmentAware">ranger.shared.EnvironmentAware</a></dd>
<dd><a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a></dd>
<dd><a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a></dd>
<dd><a href="ranger.gui.curses_shortcuts.html#CursesShortcuts">ranger.gui.curses_shortcuts.CursesShortcuts</a></dd>
<dd><a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="UI-__init__"><strong>__init__</strong></a>(self, commandlist<font color="#909090">=None</font>, env<font color="#909090">=None</font>, fm<font color="#909090">=None</font>)</dt></dl>

<dl><dt><a name="UI-destroy"><strong>destroy</strong></a>(self)</dt><dd><tt>Destroy&nbsp;all&nbsp;widgets&nbsp;and&nbsp;turn&nbsp;off&nbsp;curses</tt></dd></dl>

<dl><dt><a name="UI-draw"><strong>draw</strong></a>(self)</dt><dd><tt>Draw&nbsp;all&nbsp;objects&nbsp;in&nbsp;the&nbsp;container</tt></dd></dl>

<dl><dt><a name="UI-finalize"><strong>finalize</strong></a>(self)</dt><dd><tt>Finalize&nbsp;every&nbsp;object&nbsp;in&nbsp;container&nbsp;and&nbsp;refresh&nbsp;the&nbsp;window</tt></dd></dl>

<dl><dt><a name="UI-get_next_key"><strong>get_next_key</strong></a>(self)</dt><dd><tt>Waits&nbsp;for&nbsp;key&nbsp;input&nbsp;and&nbsp;returns&nbsp;the&nbsp;pressed&nbsp;key</tt></dd></dl>

<dl><dt><a name="UI-handle_key"><strong>handle_key</strong></a>(self, key)</dt><dd><tt>Handles&nbsp;key&nbsp;input</tt></dd></dl>

<dl><dt><a name="UI-handle_mouse"><strong>handle_mouse</strong></a>(self)</dt><dd><tt>Handles&nbsp;mouse&nbsp;input</tt></dd></dl>

<dl><dt><a name="UI-initialize"><strong>initialize</strong></a>(self)</dt><dd><tt>initialize&nbsp;curses,&nbsp;then&nbsp;call&nbsp;setup&nbsp;(at&nbsp;the&nbsp;first&nbsp;time)&nbsp;and&nbsp;resize.</tt></dd></dl>

<dl><dt><a name="UI-redraw"><strong>redraw</strong></a>(self)</dt><dd><tt>Redraw&nbsp;all&nbsp;widgets</tt></dd></dl>

<dl><dt><a name="UI-redraw_window"><strong>redraw_window</strong></a>(self)</dt><dd><tt>Redraw&nbsp;the&nbsp;window.&nbsp;This&nbsp;only&nbsp;calls&nbsp;self.<strong>win</strong>.redrawwin().</tt></dd></dl>

<dl><dt><a name="UI-set_load_mode"><strong>set_load_mode</strong></a>(self, boolean)</dt></dl>

<dl><dt><a name="UI-setup"><strong>setup</strong></a>(self)</dt><dd><tt>Called&nbsp;after&nbsp;an&nbsp;<a href="#UI-initialize">initialize</a>()&nbsp;call.<br>
Override&nbsp;this!</tt></dd></dl>

<dl><dt><a name="UI-suspend"><strong>suspend</strong></a>(self)</dt><dd><tt>Turn&nbsp;off&nbsp;curses</tt></dd></dl>

<dl><dt><a name="UI-update_size"><strong>update_size</strong></a>(self)</dt><dd><tt>Update&nbsp;self.<strong>env</strong>.termsize.<br>
Extend&nbsp;this&nbsp;method&nbsp;to&nbsp;resize&nbsp;all&nbsp;widgets!</tt></dd></dl>

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

<dl><dt><strong>load_mode</strong> = False</dl>

<dl><dt><strong>mousemask</strong> = 268435455</dl>

<hr>
Methods inherited from <a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a>:<br>
<dl><dt><a name="UI-add_child"><strong>add_child</strong></a>(self, obj)</dt><dd><tt>Add&nbsp;the&nbsp;objects&nbsp;to&nbsp;the&nbsp;container.</tt></dd></dl>

<dl><dt><a name="UI-click"><strong>click</strong></a>(self, event)</dt><dd><tt>Recursively&nbsp;called&nbsp;on&nbsp;objects&nbsp;in&nbsp;container</tt></dd></dl>

<dl><dt><a name="UI-poke"><strong>poke</strong></a>(self)</dt><dd><tt>Recursively&nbsp;called&nbsp;on&nbsp;objects&nbsp;in&nbsp;container</tt></dd></dl>

<dl><dt><a name="UI-press"><strong>press</strong></a>(self, key)</dt><dd><tt>Recursively&nbsp;called&nbsp;on&nbsp;objects&nbsp;in&nbsp;container</tt></dd></dl>

<dl><dt><a name="UI-remove_child"><strong>remove_child</strong></a>(self, obj)</dt><dd><tt>Remove&nbsp;the&nbsp;object&nbsp;from&nbsp;the&nbsp;container.</tt></dd></dl>

<hr>
Methods inherited from <a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a>:<br>
<dl><dt><a name="UI-__bool__"><strong>__bool__</strong></a> = __nonzero__(self)</dt><dd><tt>Always&nbsp;True</tt></dd></dl>

<dl><dt><a name="UI-__contains__"><strong>__contains__</strong></a>(self, item)</dt><dd><tt>Is&nbsp;item&nbsp;inside&nbsp;the&nbsp;boundaries?<br>
item&nbsp;can&nbsp;be&nbsp;an&nbsp;iterable&nbsp;like&nbsp;[y,&nbsp;x]&nbsp;or&nbsp;an&nbsp;object&nbsp;with&nbsp;x&nbsp;and&nbsp;y&nbsp;methods.</tt></dd></dl>

<dl><dt><a name="UI-__nonzero__"><strong>__nonzero__</strong></a>(self)</dt><dd><tt>Always&nbsp;True</tt></dd></dl>

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

<dl><dt><a name="UI-contains_point"><strong>contains_point</strong></a>(self, y, x)</dt><dd><tt>Test&nbsp;whether&nbsp;the&nbsp;point&nbsp;(with&nbsp;absolute&nbsp;coordinates)&nbsp;lies<br>
within&nbsp;the&nbsp;boundaries&nbsp;of&nbsp;this&nbsp;object.</tt></dd></dl>

<dl><dt><a name="UI-resize"><strong>resize</strong></a>(self, y, x, hei<font color="#909090">=None</font>, wid<font color="#909090">=None</font>)</dt><dd><tt>Resize&nbsp;the&nbsp;widget</tt></dd></dl>

<hr>
Data and other attributes inherited from <a href="ranger.shared.html#EnvironmentAware">ranger.shared.EnvironmentAware</a>:<br>
<dl><dt><strong>env</strong> = None</dl>

<hr>
Data and other attributes inherited from <a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a>:<br>
<dl><dt><strong>fm</strong> = None</dl>

<hr>
Data descriptors inherited from <a href="ranger.shared.html#Awareness">ranger.shared.Awareness</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>
Methods inherited from <a href="ranger.gui.curses_shortcuts.html#CursesShortcuts">ranger.gui.curses_shortcuts.CursesShortcuts</a>:<br>
<dl><dt><a name="UI-addnstr"><strong>addnstr</strong></a>(self, *args)</dt></dl>

<dl><dt><a name="UI-addstr"><strong>addstr</strong></a>(self, *args)</dt></dl>

<dl><dt><a name="UI-color"><strong>color</strong></a>(self, *keys)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;from&nbsp;now&nbsp;on.</tt></dd></dl>

<dl><dt><a name="UI-color_at"><strong>color_at</strong></a>(self, y, x, wid, *keys)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;at&nbsp;the&nbsp;specified&nbsp;position</tt></dd></dl>

<dl><dt><a name="UI-color_reset"><strong>color_reset</strong></a>(self)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;to&nbsp;the&nbsp;default&nbsp;colors</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> = {}</dl>

</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>TERMINALS_WITH_TITLE</strong> = ('xterm', 'xterm-256color', 'rxvt', 'rxvt-256color', 'rxvt-unicode', 'aterm', 'Eterm', 'screen', 'screen-256color')</td></tr></table>
</body></html>
span id="L1152" class="LineNr">1152 done?:bool <- greater-or-equal start, len 1153 break-if done? 1154 end:num <- find-next s, delim, start 1155 # copy start..end into result[curr-result] 1156 dest:text <- copy-range s, start, end 1157 *result <- put-index *result, curr-result, dest 1158 # slide over to next slice 1159 start <- add end, 1 1160 curr-result <- add curr-result, 1 1161 loop 1162 } 1163 ] 1164 1165 scenario text-split-1 [ 1166 local-scope 1167 x:text <- new [a/b] 1168 run [ 1169 y:&:@:text <- split x, 47/slash 1170 10:num/raw <- length *y 1171 a:text <- index *y, 0 1172 b:text <- index *y, 1 1173 20:@:char/raw <- copy *a 1174 30:@:char/raw <- copy *b 1175 ] 1176 memory-should-contain [ 1177 10 <- 2 # length of result 1178 20:array:character <- [a] 1179 30:array:character <- [b] 1180 ] 1181 ] 1182 1183 scenario text-split-2 [ 1184 local-scope 1185 x:text <- new [a/b/c] 1186 run [ 1187 y:&:@:text <- split x, 47/slash 1188 10:num/raw <- length *y 1189 a:text <- index *y, 0 1190 b:text <- index *y, 1 1191 c:text <- index *y, 2 1192 20:@:char/raw <- copy *a 1193 30:@:char/raw <- copy *b 1194 40:@:char/raw <- copy *c 1195 ] 1196 memory-should-contain [ 1197 10 <- 3 # length of result 1198 20:array:character <- [a] 1199 30:array:character <- [b] 1200 40:array:character <- [c] 1201 ] 1202 ] 1203 1204 scenario text-split-missing [ 1205 local-scope 1206 x:text <- new [abc] 1207 run [ 1208 y:&:@:text <- split x, 47/slash 1209 10:num/raw <- length *y 1210 a:text <- index *y, 0 1211 20:@:char/raw <- copy *a 1212 ] 1213 memory-should-contain [ 1214 10 <- 1 # length of result 1215 20:array:character <- [abc] 1216 ] 1217 ] 1218 1219 scenario text-split-empty [ 1220 local-scope 1221 x:text <- new [] 1222 run [ 1223 y:&:@:text <- split x, 47/slash 1224 10:num/raw <- length *y 1225 ] 1226 memory-should-contain [ 1227 10 <- 0 # empty result 1228 ] 1229 ] 1230 1231 scenario text-split-empty-piece [ 1232 local-scope 1233 x:text <- new [a/b//c] 1234 run [ 1235 y:&:@:text <- split x:text, 47/slash 1236 10:num/raw <- length *y 1237 a:text <- index *y, 0 1238 b:text <- index *y, 1 1239 c:text <- index *y, 2 1240 d:text <- index *y, 3 1241 20:@:char/raw <- copy *a 1242 30:@:char/raw <- copy *b 1243 40:@:char/raw <- copy *c 1244 50:@:char/raw <- copy *d 1245 ] 1246 memory-should-contain [ 1247 10 <- 4 # length of result 1248 20:array:character <- [a] 1249 30:array:character <- [b] 1250 40:array:character <- [] 1251 50:array:character <- [c] 1252 ] 1253 ] 1254 1255 def split-first text:text, delim:char -> x:text, y:text [ 1256 local-scope 1257 load-inputs 1258 # empty text? return empty texts 1259 len:num <- length *text 1260 { 1261 empty?:bool <- equal len, 0 1262 break-unless empty? 1263 x:text <- new [] 1264 y:text <- new [] 1265 return 1266 } 1267 idx:num <- find-next text, delim, 0 1268 x:text <- copy-range text, 0, idx 1269 idx <- add idx, 1 1270 y:text <- copy-range text, idx, len 1271 ] 1272 1273 scenario text-split-first [ 1274 local-scope 1275 x:text <- new [a/b] 1276 run [ 1277 y:text, z:text <- split-first x, 47/slash 1278 10:@:char/raw <- copy *y 1279 20:@:char/raw <- copy *z 1280 ] 1281 memory-should-contain [ 1282 10:array:character <- [a] 1283 20:array:character <- [b] 1284 ] 1285 ] 1286 1287 def copy-range buf:text, start:num, end:num -> result:text [ 1288 local-scope 1289 load-inputs 1290 # if end is out of bounds, trim it 1291 len:num <- length *buf 1292 end:num <- min len, end 1293 # allocate space for result 1294 len <- subtract end, start 1295 result:text <- new character:type, len 1296 # copy start..end into result[curr-result] 1297 src-idx:num <- copy start 1298 dest-idx:num <- copy 0 1299 { 1300 done?:bool <- greater-or-equal src-idx, end 1301 break-if done? 1302 src:char <- index *buf, src-idx 1303 *result <- put-index *result, dest-idx, src 1304 src-idx <- add src-idx, 1 1305 dest-idx <- add dest-idx, 1 1306 loop 1307 } 1308 ] 1309 1310 scenario copy-range-works [ 1311 local-scope 1312 x:text <- new [abc] 1313 run [ 1314 y:text <- copy-range x, 1, 3 1315 1:@:char/raw <- copy *y 1316 ] 1317 memory-should-contain [ 1318 1:array:character <- [bc] 1319 ] 1320 ] 1321 1322 scenario copy-range-out-of-bounds [ 1323 local-scope 1324 x:text <- new [abc] 1325 run [ 1326 y:text <- copy-range x, 2, 4 1327 1:@:char/raw <- copy *y 1328 ] 1329 memory-should-contain [ 1330 1:array:character <- [c] 1331 ] 1332 ] 1333 1334 scenario copy-range-out-of-bounds-2 [ 1335 local-scope 1336 x:text <- new [abc] 1337 run [ 1338 y:text <- copy-range x, 3, 3 1339 1:@:char/raw <- copy *y 1340 ] 1341 memory-should-contain [ 1342 1:array:character <- [] 1343 ] 1344 ] 1345 1346 def parse-whole-number in:text -> out:num, error?:bool [ 1347 local-scope 1348 load-inputs 1349 out <- copy 0 1350 result:num <- copy 0 # temporary location 1351 i:num <- copy 0 1352 len:num <- length *in 1353 { 1354 done?:bool <- greater-or-equal i, len 1355 break-if done? 1356 c:char <- index *in, i 1357 x:num <- character-to-code c 1358 digit:num, error?:bool <- character-code-to-digit x 1359 return-if error? 1360 result <- multiply result, 10 1361 result <- add result, digit 1362 i <- add i, 1 1363 loop 1364 } 1365 # no error; all digits were valid 1366 out <- copy result 1367 ] 1368 1369 # (contributed by Ella Couch) 1370 recipe character-code-to-digit character-code:number -> result:number, error?:boolean [ 1371 local-scope 1372 load-inputs 1373 result <- copy 0 1374 error? <- lesser-than character-code, 48 # '0' 1375 return-if error? 1376 error? <- greater-than character-code, 57 # '9' 1377 return-if error? 1378 result <- subtract character-code, 48 1379 ] 1380 1381 scenario character-code-to-digit-contain-only-digit [ 1382 local-scope 1383 a:number <- copy 48 # character code for '0' 1384 run [ 1385 10:number/raw, 11:boolean/raw <- character-code-to-digit a 1386 ] 1387 memory-should-contain [ 1388 10 <- 0 1389 11 <- 0 # no error 1390 ] 1391 ] 1392 1393 scenario character-code-to-digit-contain-only-digit-2 [ 1394 local-scope 1395 a:number <- copy 57 # character code for '9' 1396 run [ 1397 1:number/raw, 2:boolean/raw <- character-code-to-digit a 1398 ] 1399 memory-should-contain [ 1400 1 <- 9 1401 2 <- 0 # no error 1402 ] 1403 ] 1404 1405 scenario character-code-to-digit-handles-codes-lower-than-zero [ 1406 local-scope 1407 a:number <- copy 47 1408 run [ 1409 10:number/raw, 11:boolean/raw <- character-code-to-digit a 1410 ] 1411 memory-should-contain [ 1412 10 <- 0 1413 11 <- 1 # error 1414 ] 1415 ] 1416 1417 scenario character-code-to-digit-handles-codes-larger-than-nine [ 1418 local-scope 1419 a:number <- copy 58 1420 run [ 1421 10:number/raw, 11:boolean/raw <- character-code-to-digit a 1422 ] 1423 memory-should-contain [ 1424 10 <- 0 1425 11 <- 1 # error 1426 ] 1427 ]