52 lines
1.6 KiB
Nim
52 lines
1.6 KiB
Nim
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))
|