Improvements and WIP wc
This commit is contained in:
parent
94c57b1da2
commit
b7e5108379
10 changed files with 60 additions and 16 deletions
12
head.nim
12
head.nim
|
|
@ -1,10 +1,12 @@
|
|||
import cligen, os, streams
|
||||
import cligen, os
|
||||
import common
|
||||
|
||||
proc main(files:seq[string], lines=10, bytes=0) =
|
||||
proc main(files:seq[string], lines=10, bytes=0, quiet=false) =
|
||||
# if files.len == 0:
|
||||
# files.add "-"
|
||||
for file in files:
|
||||
if files.len > 1 and not quiet:
|
||||
writeLine(stdout, "==> " & (if file == "-": "standard input" else: file) & " <==")
|
||||
var f = if file == "-": stdin
|
||||
else: open(file, fmRead)
|
||||
if bytes > 0:
|
||||
|
|
@ -14,8 +16,10 @@ proc main(files:seq[string], lines=10, bytes=0) =
|
|||
inc currentByte
|
||||
elif lines > 0:
|
||||
var currentLine = 0
|
||||
while not f.endOfFile and currentLine < lines:
|
||||
writeLine(stdout, f.readLine)
|
||||
for line in lines(f):
|
||||
if currentLine >= lines:
|
||||
break
|
||||
writeLine(stdout, line)
|
||||
inc currentLine
|
||||
|
||||
dispatch(main, version=("version", nimbaseVersion))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue