summary refs log tree commit diff stats
path: root/examples/README
blob: ca5148533bc9eba90540d976a5320767a68c477f (plain) (blame)
1
2
3
4
5
6
7
8
The files in this directory contain applications or extensions of ranger which
are put here for your inspiration and as references.

In order to use a plugin from this directory, you need to copy it to
~/.config/ranger/plugins/

Note that if you update ranger to a new minor version (for example,
from 1.6.* to 1.7.0), your outdated plugins WILL break and crash ranger.
g.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 */
import os
import streams
import tables

import io/request
import ips/serialize
import types/url

proc loadDir(url: URL, path: string, ostream: Stream) =
  ostream.swrite(0)
  ostream.swrite(200) # ok
  ostream.swrite(newHeaderList({"Content-Type": "text/html"}.toTable()))
  ostream.write("""
<HTML>
<HEAD>
<BASE HREF="""" & $url & """">
<TITLE>Directory list of """ & path & """</TITLE>
</HEAD>
<BODY>
<H1>Directory list of """ & path & """</H1>
[DIR]&nbsp; <A HREF="../">../</A></br>
""")
  for pc, file in walkDir(path, relative = true):
    case pc
    of pcDir:
      ostream.write("[DIR]&nbsp; ")
    of pcFile:
      ostream.write("[FILE] ")
    of pcLinkToDir, pcLinkToFile:
      ostream.write("[LINK] ")
    var fn = file
    if pc == pcDir:
      fn &= '/'
    ostream.write("<A HREF=\"" & fn & "\">" & fn & "</A>")
    if pc in {pcLinkToDir, pcLinkToFile}:
      ostream.write(" -> " & expandSymlink(path / file))
    ostream.write("<br>")
  ostream.write("""
</BODY>
</HTML>""")
  ostream.flush()

proc loadSymlink(path: string, ostream: Stream) =
  discard

proc loadFile*(url: URL, ostream: Stream) =
  when defined(windows) or defined(OS2) or defined(DOS):
    let path = url.path.serialize_unicode_dos()
  else:
    let path = url.path.serialize_unicode()
  let istream = newFileStream(path, fmRead)
  if istream == nil:
    if dirExists(path):
      loadDir(url, path, ostream)
    elif symlinkExists(path):
      loadSymlink(path, ostream)
    else:
      ostream.swrite(-1) # error
      ostream.flush()
  else:
    ostream.swrite(0)
    ostream.swrite(200) # ok
    ostream.swrite(newHeaderList())
    while not istream.atEnd:
      const bufferSize = 4096
      var buffer {.noinit.}: array[bufferSize, char]
      while true:
        let n = readData(istream, addr buffer[0], bufferSize)
        if n == 0:
          break
        ostream.writeData(addr buffer[0], n)
        ostream.flush()
        if n < bufferSize:
          break