Add (wip) more and less
This commit is contained in:
parent
5d328998f8
commit
847cd55617
3 changed files with 62 additions and 1 deletions
9
less.nim
Normal file
9
less.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import cligen, terminal
|
||||||
|
import common
|
||||||
|
|
||||||
|
proc main(files:seq[string]) =
|
||||||
|
addQuitProc(resetAttributes)
|
||||||
|
addQuitProc(showCursor)
|
||||||
|
err "asdf"
|
||||||
|
|
||||||
|
dispatch(main, version=("version", nimbaseVersion))
|
||||||
52
more.nim
Normal file
52
more.nim
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import cligen, terminal
|
||||||
|
import common
|
||||||
|
|
||||||
|
proc redraw(lineBuffer:seq[string], topLine:int) =
|
||||||
|
eraseScreen(stdout)
|
||||||
|
for i in topLine .. topLine + terminalHeight():
|
||||||
|
writeLine(stdout, lineBuffer[i])
|
||||||
|
let percent = (100 * (topLine / lineBuffer.len)).int
|
||||||
|
stdout.styledWrite(fgBlack, bgWhite, "--More--(" & $(percent) & "%)")
|
||||||
|
|
||||||
|
proc main(files:seq[string]) =
|
||||||
|
if files.len == 0:
|
||||||
|
err "more: bad usage"
|
||||||
|
quit 1
|
||||||
|
addQuitProc(resetAttributes)
|
||||||
|
var lineBuffer:seq[string]
|
||||||
|
for file in files:
|
||||||
|
for line in lines(file):
|
||||||
|
lineBuffer.add(line)
|
||||||
|
if lineBuffer.len < terminalHeight():
|
||||||
|
for line in lineBuffer:
|
||||||
|
writeLine(stdout, line)
|
||||||
|
return
|
||||||
|
let
|
||||||
|
minTopLine = 0
|
||||||
|
maxTopLine = lineBuffer.high - terminalHeight()
|
||||||
|
var
|
||||||
|
command = '\0'
|
||||||
|
topLine = minTopLine
|
||||||
|
while true:
|
||||||
|
redraw(lineBuffer, topLine)
|
||||||
|
command = getch()
|
||||||
|
if command == 'q':
|
||||||
|
break
|
||||||
|
if command == 'j':
|
||||||
|
inc topLine
|
||||||
|
if topLine > maxTopLine: topLine = maxTopLine
|
||||||
|
if command == 'k':
|
||||||
|
dec topLine
|
||||||
|
if topLine < minTopLine: topLine = minTopLine
|
||||||
|
if command == 'f':
|
||||||
|
topLine += terminalHeight()
|
||||||
|
if topLine > maxTopLine: topLine = maxTopLine
|
||||||
|
if command == 'b':
|
||||||
|
topLine -= terminalHeight()
|
||||||
|
if topLine < minTopLine: topLine = minTopLine
|
||||||
|
if command == 'g':
|
||||||
|
topLine = minTopLine
|
||||||
|
if command == 'G':
|
||||||
|
topLine = maxTopLine
|
||||||
|
|
||||||
|
dispatch(main, version=("version", nimbaseVersion))
|
||||||
|
|
@ -8,6 +8,6 @@ requires "nim >= 0.19.4"
|
||||||
requires "cligen >= 0.9.19"
|
requires "cligen >= 0.9.19"
|
||||||
requires "stint >= 0.0.1"
|
requires "stint >= 0.0.1"
|
||||||
|
|
||||||
bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "nl", "pwd", "rev", "rm", "seq", "shuf", "sleep", "sub", "tail", "tac", "tee", "touch", "true", "wc", "yes"]
|
bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "more", "mul", "nl", "pwd", "rev", "rm", "seq", "shuf", "sleep", "sub", "tail", "tac", "tee", "touch", "true", "wc", "yes"]
|
||||||
|
|
||||||
binDir = "bin"
|
binDir = "bin"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue