From 3866bec55e354f082e03314c1020697d4027db01 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Tue, 26 Mar 2019 14:53:59 +0100 Subject: [PATCH] head utility works --- head.nim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/head.nim b/head.nim index b9e6b09..c73da44 100644 --- a/head.nim +++ b/head.nim @@ -1,10 +1,18 @@ import cligen, os, streams import common -proc main(files:seq[string]) = +proc main(files:seq[string], lines=10, bytes=0) = for file in files: var s = newFileStream(file, fmRead) - while not s.atEnd: - write(stdout, s.readChar) + if bytes > 0: + var currentByte = 0 + while not s.atEnd and currentByte < bytes: + write(stdout, s.readChar) + inc currentByte + elif lines > 0: + var currentLine = 0 + while not s.atEnd and currentLine < lines: + echo s.readLine + inc currentLine dispatch(main, version=("version", nimbaseVersion))