diff --git a/less.nim b/less.nim new file mode 100644 index 0000000..d91d851 --- /dev/null +++ b/less.nim @@ -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)) \ No newline at end of file diff --git a/more.nim b/more.nim new file mode 100644 index 0000000..dd8530c --- /dev/null +++ b/more.nim @@ -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)) diff --git a/nimbase.nimble b/nimbase.nimble index 4de5f75..2ddd14a 100644 --- a/nimbase.nimble +++ b/nimbase.nimble @@ -8,6 +8,6 @@ requires "nim >= 0.19.4" requires "cligen >= 0.9.19" 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"