summary refs log blame commit diff stats
path: root/doc/pydoc/ranger.ext.command_parser.html
blob: 9e6fc95094aa4aa26c1fcdf370629dc2b39f20f6 (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.ext.command_parser</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.ext.html"><font color="#ffffff">ext</font></a>.command_parser</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/ext/command_parser.py">/home/hut/ranger/ranger/ext/command_parser.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="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.ext.command_parser.html#LazyParser">LazyParser</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="LazyParser">class <strong>LazyParser</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Parse&nbsp;commands&nbsp;and&nbsp;extract&nbsp;information<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="LazyParser-__add__"><strong>__add__</strong></a>(self, newpart)</dt></dl>

<dl><dt><a name="LazyParser-__init__"><strong>__init__</strong></a>(self, line)</dt></dl>

<dl><dt><a name="LazyParser-chunk"><strong>chunk</strong></a>(self, n, otherwise<font color="#909090">=''</font>)</dt><dd><tt>Chunks&nbsp;are&nbsp;pieces&nbsp;of&nbsp;the&nbsp;command&nbsp;seperated&nbsp;by&nbsp;spaces</tt></dd></dl>

<dl><dt><a name="LazyParser-rest"><strong>rest</strong></a>(self, n, otherwise<font color="#909090">=''</font>)</dt><dd><tt>Rests&nbsp;are&nbsp;the&nbsp;strings&nbsp;which&nbsp;come&nbsp;after&nbsp;each&nbsp;word.</tt></dd></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>
                                                                          
                                                        
                                                                               

                                                         
                                                        
                                                              

                                                         
 






















                               
 



                            
 
                                  
 

                        
 
                                                 
 
                    
 
                             
 





                                                   
 
                           
 
                                                                     
 
                  
 
                             
 
                         
 
                  
 



                                                                   
 
                      
              











































                                                                           
                     
         











                                                             
         









                                                  




                                                                     







                                            
import version

import server/forkserver
let forks = newForkServer()

import std/options
import std/os
import std/posix

import config/chapath
import config/config
import display/term
import io/serversocket
import local/client
import types/opt
import utils/strwidth
import utils/twtstr

import chakasu/charset

proc main() =
  let params = commandLineParams()

  proc version(long: static bool = false): string =
    result = "Chawan browser v0.1 "
    when defined(debug):
      result &= "(debug)"
    else:
      result &= "(release)"

  proc help(i: int) =
    let s = version() & """

Usage: cha [options] [URL(s) or file(s)...]
Options:
    --                          Interpret all following arguments as URLs
    -c, --css <stylesheet>      Pass stylesheet (e.g. -c 'a{color: blue}')
    -d, --dump                  Print page to stdout
    -h, --help                  Print this usage message
    -o, --opt <config>          Pass config options (e.g. -o 'page.q="quit()"')
    -r, --run <script/file>     Run passed script or file
    -v, --version               Print version information
    -C, --config <file>         Override config path
    -I, --input-charset <enc>   Specify document charset
    -M, --monochrome            Set color-mode to 'monochrome'
    -O, --display-charset <enc> Specify display charset
    -T, --type <type>           Specify content mime type
    -V, --visual                Visual startup mode"""

    if i == 0:
      stdout.write(s & '\n')
    else:
      stderr.write(s & '\n')
    quit(i)

  var ctype = none(string)
  var cs = CHARSET_UNKNOWN
  var pages: seq[string]
  var dump = false
  var visual = false
  var escape_all = false
  var opts: seq[string]
  var stylesheet = ""
  var configPath = none(string)

  var i = 0
  while i < params.len:
    let param = params[i]

    if escape_all: # after --
      pages.add(param)
      inc i
      continue

    proc getnext(): string =
      inc i
      if i < params.len:
        return params[i]
      help(1)

    proc pconfig() =
      configPath = some(getnext())

    proc pversion() =
      echo version(true)
      quit(0)

    proc pmonochrome() =
      opts.add("display.color-mode = monochrome")

    proc pvisual() =
      visual = true

    proc ptype() =
      ctype = some(getnext())

    proc pgetCharset(): Charset =
      let s = getnext()
      let cs = getCharset(s)
      if cs == CHARSET_UNKNOWN:
        stderr.write("Unknown charset " & s & "\n")
        quit(1)
      return cs

    proc pinput_charset() =
      cs = pgetCharset()

    proc poutput_charset() =
      opts.add("encoding.display-charset = '" & $pgetCharset() & "'")

    proc pdump() =
      dump = true

    proc pcss() =
      stylesheet &= getnext()

    proc popt() =
      opts.add(getnext())

    proc phelp() =
      help(0)

    proc prun() =
      let script = dqEscape(getnext())
      opts.add("start.startup-script = \"\"\"" & script & "\"\"\"")
      opts.add("start.headless = true")
      dump = true

    if param.len == 0:
      inc i
      continue

    const NeedsNextParam = {'C', 'I', 'O', 'T', 'c', 'o', 'r'}

    if param[0] == '-':
      if param.len == 1:
        # If param == "-", i.e. it is a single dash, then ignore it.
        # (Some programs use single-dash to read from stdin, but we do that
        # automatically when stdin is not a tty. So ignoring it entirely
        # is probably for the best.)
        inc i
        continue
      if param[1] != '-':
        for j in 1 ..< param.len:
          if j != param.high and param[j] in NeedsNextParam:
            # expecting next parameter, but not the last char...
            help(1)
          case param[j]
          of 'C': pconfig()
          of 'I': pinput_charset()
          of 'M': pmonochrome()
          of 'O': poutput_charset()
          of 'T': ptype()
          of 'V': pvisual()
          of 'c': pcss()
          of 'd': pdump()
          of 'h': phelp()
          of 'o': popt()
          of 'r': prun()
          of 'v': pversion()
          else: help(1)
      else:
        case param
        of "--config": pconfig()
        of "--input-charset": pinput_charset()
        of "--monochrome": pmonochrome()
        of "--output-charset": poutput_charset()
        of "--type": ptype()
        of "--visual": pvisual()
        of "--css": pcss()
        of "--dump": pdump()
        of "--help": phelp()
        of "--opt": popt()
        of "--run": prun()
        of "--version": pversion()
        of "--": escape_all = true
        else: help(1)
    else:
      pages.add(param)
    inc i

  let config = readConfig(configPath)
  for opt in opts:
    config.parseConfig(getCurrentDir(), opt, laxnames = true)
  config.css.stylesheet &= stylesheet

  set_cjk_ambiguous(config.display.double_width_ambiguous)

  if pages.len == 0 and stdin.isatty():
    if visual:
      pages.add(config.start.visual_home)
    else:
      let http = getEnv("HTTP_HOME")
      if http != "": pages.add(http)
      else:
        let www = getEnv("WWW_HOME")
        if www != "": pages.add(www)

  if pages.len == 0 and not config.start.headless:
    if stdin.isatty:
      help(1)

  forks.loadForkServerConfig(config)
  let tmpdir0 = config.external.tmpdir.unquote()
  if tmpdir0.isErr:
    stderr.write("Error unquoting external.tmpdir: " & tmpdir0.error)
    stderr.write("Exiting...")
    quit(1)
  SocketDirectory = tmpdir0.get

  let c = newClient(config, forks, getpid())
  try:
    c.launchClient(pages, ctype, cs, dump)
  except CatchableError:
    c.flushConsole()
    raise

main()