summary refs log blame commit diff stats
path: root/ranger/gui/widgets/filelist.py
blob: 12f0c99ac52613fe758d095ea38a51633720fa70 (plain) (tree)
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - subx/039debug.cc</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy=">
<meta name="colorscheme" content="minimal-light">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; }
body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; }
a { color:inherit; }
* { font-size:12pt; font-size: 1em; }
.LineNr { }
.Constant { color: #008787; }
.Delimiter { color: #c000c0; }
.Special { color: #d70000; }
.Identifier { color: #af5f00; }
.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; }
.Comment { color: #005faf; }
.SalientComment { color: #0000af; }
-->
</style>

<script type='text/javascript'>
<!--

/* function to open any folds containing a jumped-to line before jumping to it */
function JumpToLine()
{
  var lineNum;
  lineNum = window.location.hash;
  lineNum = lineNum.substr(1); /* strip off '#' */

  if (lineNum.indexOf('L') == -1) {
    lineNum = 'L'+lineNum;
  }
  lineElem = document.getElementById(lineNum);
  /* Always jump to new location even if the line was hidden inside a fold, or
   * we corrected the raw number to a line ID.
   */
  if (lineElem) {
    lineElem.scrollIntoView(true);
  }
  return true;
}
if ('onhashchange' in window) {
  window.onhashchange = JumpToLine;
}

-->
</script>
</head>
<body onload='JumpToLine();'>
<a href='https://github.com/akkartik/mu/blob/master/subx/039debug.cc'>https://github.com/akkartik/mu/blob/master/subx/039debug.cc</a>
<pre id='vimCodeElement'>
<span id="L1" class="LineNr"> 1 </span><span class="SalientComment">//:: Some helpers for debugging.</span>
<span id="L2" class="LineNr"> 2 </span>
<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: Load the 'map' file generated during 'subx --map translate' when running 'subx --map --trace run'.</span>
<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: (It'll only affect the trace.)</span>
<span id="L5" class="LineNr"> 5 </span>
<span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span id="L7" class="LineNr"> 7 </span>map&lt;<span class="Comment">/*</span><span class="Comment">address</span><span class="Comment">*/</span><span class="Normal">uint32_t</span><span class="Delimiter">,</span> string&gt; <span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">;</span>  <span class="Comment">// used only by 'subx run'</span>
<span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(before &quot;End --map Settings&quot;)</span>
<span id="L9" class="LineNr"> 9 </span><a href='039debug.cc.html#L11'>load_map</a><span class="Delimiter">(</span><span class="Constant">&quot;map&quot;</span><span class="Delimiter">);</span>
<span id="L10" class="LineNr">10 </span><span class="Delimiter">:(code)</span>
<span id="L11" class="LineNr">11 </span><span class="Normal">void</span> <a href='039debug.cc.html#L11'>load_map</a><span class="Delimiter">(</span><span class="Normal">const</span> string&amp; map_filename<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span id="L12" class="LineNr">12 </span>  ifstream fin<span class="Delimiter">(</span>map_filename<span class="Delimiter">.</span>c_str<span class="Delimiter">());</span>
<span id="L13" class="LineNr">13 </span>  fin &gt;&gt; std::hex<span class="Delimiter">;</span>
<span id="L14" class="LineNr">14 </span>  <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L274'>has_data</a><span class="Delimiter">(</span>fin<span class="Delimiter">))</span> <span class="Delimiter">{</span>
<span id="L15" class="LineNr">15 </span>    <span class="Normal">uint32_t</span> addr = <span class="Constant">0</span><span class="Delimiter">;</span>
<span id="L16" class="LineNr">16 </span>    fin &gt;&gt; addr<span class="Delimiter">;</span>
<span id="L17" class="LineNr">17 </span>    string name<span class="Delimiter">;</span>
<span id="L18" class="LineNr">18 </span>    fin &gt;&gt; name<span class="Delimiter">;</span>
<span id="L19" class="LineNr">19 </span>    <a href='001help.cc.html#L252'>put</a><span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> addr<span class="Delimiter">,</span> name<span class="Delimiter">);</span>
<span id="L20" class="LineNr">20 </span>  <span class="Delimiter">}</span>
<span id="L21" class="LineNr">21 </span><span class="Delimiter">}</span>
<span id="L22" class="LineNr">22 </span>
<span id="L23" class="LineNr">23 </span><span class="Delimiter">:(after &quot;Run One Instruction&quot;)</span>
<span id="L24" class="LineNr">24 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L256'>contains_key</a><span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> EIP<span class="Delimiter">))</span>
<span id="L25" class="LineNr">25 </span>  <a href='003trace.cc.html#L183'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;== label &quot;</span> &lt;&lt; get<span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> EIP<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span>
<span id="L26" class="LineNr">26 </span>
<span id="L27" class="LineNr">27 </span><span class="Comment">//: If a label starts with '$watch-', make a note of the effective address</span>
<span id="L28" class="LineNr">28 </span><span class="Comment">//: computed by the next instruction. Start dumping out its contents to the</span>
<span id="L29" class="LineNr">29 </span><span class="Comment">//: trace after every subsequent instruction.</span>
<span id="L30" class="LineNr">30 </span>
<span id="L31" class="LineNr">31 </span><span class="Delimiter">:(after &quot;Run One Instruction&quot;)</span>
<span id="L32" class="LineNr">32 </span><a href='039debug.cc.html#L38'>dump_watch_points</a><span class="Delimiter">();</span>
<span id="L33" class="LineNr">33 </span><span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span id="L34" class="LineNr">34 </span>map&lt;string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>&gt; <span class="Special"><a href='039debug.cc.html#L34'>Watch_points</a></span><span class="Delimiter">;</span>
<span id="L35" class="LineNr">35 </span><span class="Delimiter">:(before &quot;End Reset&quot;)</span>
<span id="L36" class="LineNr">36 </span><span class="Special"><a href='039debug.cc.html#L34'>Watch_points</a></span><span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
<span id="L37" class="LineNr">37 </span><span class="Delimiter">:(code)</span>
<span id="L38" class="LineNr">38 </span><span class="Normal">void</span> <a href='039debug.cc.html#L38'>dump_watch_points</a><span class="Delimiter">()</span> <span class="Delimiter">{</span>
<span id="L39" class="LineNr">39 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L34'>Watch_points</a></span><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
<span id="L40" class="LineNr">40 </span>  <a href='003trace.cc.html#L186'>dbg</a> &lt;&lt; <span class="Constant">&quot;watch points:&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
<span id="L41" class="LineNr">41 </span>  <span class="Normal">for</span> <span class="Delimiter">(</span>map&lt;string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>&gt;::iterator p = <span class="Special"><a href='039debug.cc.html#L34'>Watch_points</a></span><span class="Delimiter">.</span>begin<span class="Delimiter">();</span>  p != <span class="Special"><a href='039debug.cc.html#L34'>Watch_points</a></span><span class="Delimiter">.</span>end<span class="Delimiter">();</span>  ++p<span class="Delimiter">)</span>
<span id="L42" class="LineNr">42 </span>    <a href='003trace.cc.html#L186'>dbg</a> &lt;&lt; <span class="Constant">&quot;  &quot;</span> &lt;&lt; p<span class="Delimiter">-&gt;</span>first &lt;&lt; <span class="Constant">&quot;: &quot;</span> &lt;&lt; <a href='010---vm.cc.html#L413'>HEXWORD</a> &lt;&lt; p<span class="Delimiter">-&gt;</span>second &lt;&lt; <span class="Constant">&quot; -&gt; &quot;</span> &lt;&lt; <a href='010---vm.cc.html#L413'>HEXWORD</a> &lt;&lt; <a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span>p<span class="Delimiter">-&gt;</span>second<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span>
<span id="L43" class="LineNr">43 </span><span class="Delimiter">}</span>
<span id="L44" class="LineNr">44 </span>
<span id="L45" class="LineNr">45 </span><span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span id="L46" class="LineNr">46 </span>string <span class="Special">Watch_this_effective_address</span><span class="Delimiter">;</span>
<span id="L47" class="LineNr">47 </span><span class="Delimiter">:(after &quot;Run One Instruction&quot;)</span>
<span id="L48" class="LineNr">48 </span><span class="Special">Watch_this_effective_address</span> = <span class="Constant">&quot;&quot;</span><span class="Delimiter">;</span>
<span id="L49" class="LineNr">49 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L256'>contains_key</a><span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> EIP<span class="Delimiter">)</span> &amp;&amp; <a href='001help.cc.html#L102'>starts_with</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> EIP<span class="Delimiter">),</span> <span class="Constant">&quot;$watch-&quot;</span><span class="Delimiter">))</span>
<span id="L50" class="LineNr">50 </span>  <span class="Special">Watch_this_effective_address</span> = get<span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> EIP<span class="Delimiter">);</span>
<span id="L51" class="LineNr">51 </span><span class="Delimiter">:(after &quot;Found effective_address(addr)&quot;)</span>
<span id="L52" class="LineNr">52 </span><span class="Normal">if</span> <span class="Delimiter">(</span>!<span class="Special">Watch_this_effective_address</span><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span>
<span id="L53" class="LineNr">53 </span>  <a href='003trace.cc.html#L186'>dbg</a> &lt;&lt; <span class="Constant">&quot;now watching &quot;</span> &lt;&lt; <a href='010---vm.cc.html#L413'>HEXWORD</a> &lt;&lt; addr &lt;&lt; <span class="Constant">&quot; for &quot;</span> &lt;&lt; <span class="Special">Watch_this_effective_address</span> &lt;&lt; end<span class="Delimiter">();</span>
<span id="L54" class="LineNr">54 </span>  <a href='001help.cc.html#L252'>put</a><span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L34'>Watch_points</a></span><span class="Delimiter">,</span> <span class="Special">Watch_this_effective_address</span><span class="Delimiter">,</span> addr<span class="Delimiter">);</span>
<span id="L55" class="LineNr">55 </span><span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->


                                                     

                                                                          

                            
                                                                          


                                                                                    


                                                            
                
                    
                                                       

                            


                                                 
 
                                 
                                                      
                                                               
                           
 

                                           
                                 

                                                  











                                                                                              
                                                                    




                                                                                        
 


                                                                                 
                                                            
                                                  





                                                                                        
 

                                                              
 

                                                        
 
                                              
                                                       
                                                                                    
                                          
                              
 





                                                                           

                                       
                                                
                                            
                                                    




                                                       
 
                                                                             

                                                                



                                                             


                                                           


                                                           
                                                                        
 
                                                         
                                                              
                             
                                                         
 


                                                                                          

                                                         
                                                                                    
 
                                                







                                                                                               
                                                                                   
                                     
                                                                                               
 



                                                                                 
                                                                                                  



                                                                             


                                                                                  

                                                                         

                                                                                    
 
                                          
 
                                   
                                                                                        
                                                    


                                          
                                                





                                                   


                                





                                                                                     



                                                                    













                                                                             
                                                    

                                                            
 


                                                                
                                       





                                                         
                                                             
                                                            
"""The FileList widget displays the contents of a directory or file."""
from . import Widget
from ..displayable import DisplayableContainer
from .pager import Pager
from ranger import log

class FileList(Widget, DisplayableContainer):
	main_display = False
	display_infostring = False
	scroll_begin = 0
	target = None
	postpone_drawing = False
	tagged_marker = '*'

	def __init__(self, win, level):
		DisplayableContainer.__init__(self, win)
		self.pager = Pager(self.win)
		self.add_obj(self.pager)
		self.level = level
	
	def resize(self, y, x, hei, wid):
		DisplayableContainer.resize(self, y, x, hei, wid)
		self.pager.resize(0, 0, hei, wid)

	def click(self, event):
		"""Handle a MouseEvent"""
		from ranger.fsobject.fsobject import T_DIRECTORY

		if not (event.pressed(1) or event.pressed(3)):
			return False

		if self.target is None:
			pass

		elif self.target.type is T_DIRECTORY:
			index = self.scroll_begin + event.y - self.y

			if event.pressed(1):
				if not self.main_display:
					self.fm.enter_dir(self.target.path)

				if index < len(self.target):
					self.fm.move_pointer(absolute = index)
			elif event.pressed(3):
				try:
					clicked_file = self.target[index]
					self.fm.enter_dir(clicked_file.path)
				except:
					pass

		else:
			if self.level > 0:
				self.fm.move_right()

		return True

	def has_preview(self):
		from ranger.fsobject.file import File
		from ranger.fsobject.directory import Directory

		if self.target is None:
			return False

		if isinstance(self.target, File):
			if not self._preview_this_file(self.target):
				return False

		return True

	def poke(self):
		self.target = self.env.at_level(self.level)

	def draw(self):
		"""Call either draw_file() or draw_directory()"""
		from ranger.fsobject.file import File
		from ranger.fsobject.directory import Directory

		self.pager.visible = False
		if self.target is None:
			pass
		elif type(self.target) == File:
			self.draw_file()
		elif type(self.target) == Directory:
			self.draw_directory()

		DisplayableContainer.draw(self)

	def finalize(self):
		if self.postpone_drawing:
			self.target.load_content_if_outdated()
			self.draw_directory()
			self.postpone_drawing = False

	def _preview_this_file(self, target):
		return target.document and not self.settings.preview_files

	def draw_file(self):
		"""Draw a preview of the file, if the settings allow it"""
		if not self.target.accessible:
			self.win.addnstr(self.y, self.x, "not accessible", self.wid)
			return

		if not self._preview_this_file(self.target):
			return
		
		try:
			f = open(self.target.path, 'r')
		except:
			pass
		else:
			self.pager.visible = True
			self.pager.set_source(f)

	def draw_directory(self):
		"""Draw the contents of a directory"""
		from ranger.fsobject.directory import Directory
		import stat

		base_color = ['in_display']

		self.target.use()

		if not self.target.content_loaded:
#			if self.target.force_load:
#				self.target.stopped = False
#
#			else:
#				if not self.target.stopped:
#					
#					if maxdirsize is not None and self.target.accessible \
#							and self.target.size > maxdirsize:
#						self.target.stopped = True
#
			maxdirsize = self.settings.max_dirsize_for_autopreview
			if not self.target.force_load and maxdirsize is not None \
					and self.target.accessible \
					and self.target.size > maxdirsize:
				self.color(base_color, 'error')
				self.win.addnstr(self.y, self.x, "no preview", self.wid)
				self.color_reset()
				return

			if self.settings.auto_load_preview:
				self.color(base_color)
				self.win.addnstr(self.y, self.x, "...", self.wid)
				self.postpone_drawing = True
				self.color_reset()
				return
			else:
				self.color(base_color, 'error')
				self.win.addnstr(self.y, self.x, "not loaded", self.wid)
				self.color_reset()
				return

		if not self.target.load_content_if_outdated():
			self.target.sort_if_outdated()

		if self.main_display:
			base_color.append('maindisplay')

		if not self.target.accessible:
			self.color(base_color, 'error')
			self.win.addnstr(self.y, self.x, "not accessible", self.wid)
			self.color_reset()
			return

		if self.target.empty():
			self.color(base_color, 'empty')
			self.win.addnstr(self.y, self.x, "empty", self.wid)
			self.color_reset()
			return

		self.set_scroll_begin()

		selected_i = self.target.pointer
		for line in range(self.hei):
			i = line + self.scroll_begin

			try:
				drawed = self.target[i]
			except IndexError:
				break

			this_color = base_color + list(drawed.mimetype_tuple)
			text = drawed.basename
			tagged = drawed.realpath in self.fm.tags

			if i == selected_i:
				this_color.append('selected')

			if drawed.marked:
				this_color.append('marked')

			if tagged:
				this_color.append('tagged')
				if self.main_display:
					text = self.tagged_marker + text

			if isinstance(drawed, Directory):
				this_color.append('directory')
			else:
				this_color.append('file')

			if drawed.stat is not None and drawed.stat.st_mode & stat.S_IXUSR:
				this_color.append('executable')

			if drawed.islink:
				this_color.append('link')
				this_color.append(drawed.exists and 'good' or 'bad')

			string = drawed.basename
			try:
				if self.main_display:
					if tagged:
						if self.wid > 1:
							self.win.addnstr(self.y + line, self.x,
									text, self.wid - 2)
					elif self.wid > 2:
						self.win.addnstr(self.y + line, self.x + 1,
								text, self.wid - 2)
				else:
					self.win.addnstr(self.y + line, self.x, text, self.wid)

				if self.display_infostring and drawed.infostring:
					info = drawed.infostring
					x = self.x + self.wid - 1 - len(info)
					if x > self.x:
						self.win.addstr(self.y + line, x, str(info) + ' ')
			except:
				# the last string will cause an error because
				# ncurses tries to move out of the bounds
				pass

			self.color_at(self.y + line, self.x, self.wid, this_color)

			if self.main_display and tagged and self.wid > 2:
				this_color.append('tag_marker')
				self.color_at(self.y + line, self.x,
						len(self.tagged_marker), this_color)

			self.color_reset()

	def get_scroll_begin(self):
		"""Determines scroll_begin (the position of the first displayed file)"""
		offset = self.settings.scroll_offset
		dirsize = len(self.target)
		winsize = self.hei
		halfwinsize = winsize // 2
		index = self.target.pointer or 0
		original = self.target.scroll_begin
		projected = index - original

		upper_limit = winsize - 1 - offset
		lower_limit = offset

		if original < 0:
			return 0

		if dirsize < winsize:
			return 0

		if halfwinsize < offset:
			return min( dirsize - winsize, max( 0, index - halfwinsize ))

		if original > dirsize - winsize:
			self.target.scroll_begin = dirsize - winsize
			return self.get_scroll_begin()

		if projected < upper_limit and projected > lower_limit:
			return original

		if projected > upper_limit:
			return min( dirsize - winsize,
					original + (projected - upper_limit))

		if projected < upper_limit:
			return max( 0,
					original - (lower_limit - projected))
		
		return original

	def set_scroll_begin(self):
		"""Updates the scroll_begin value"""
		self.scroll_begin = self.get_scroll_begin()
		self.target.scroll_begin = self.scroll_begin

	# TODO: does not work if options.scroll_offset is high,
	# relative > 1 and you scroll from scroll_begin = 1 to 0
	def scroll(self, relative):
		"""scroll by n lines"""
		self.set_scroll_begin()
		old_value = self.target.scroll_begin
		self.target.scroll_begin += relative
		self.set_scroll_begin()

		if self.target.scroll_begin == old_value:
			self.target.move(relative = relative)
			self.target.scroll_begin += relative