Skip to content

Commit

Permalink
Merge pull request #6 from fox0430/devel
Browse files Browse the repository at this point in the history
v0.3.2
  • Loading branch information
fox0430 authored Nov 28, 2018
2 parents e344f8f + 044b36a commit 2cdefbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ nyat is cat clone. Written in nim. (=^・・^=)

-n Display line number

-b number nonempty output lines
-b Number nonempty output lines

-s suppress repeated empty output lines
-s Suppress repeated empty output lines

## Installation
```sh
Expand Down
17 changes: 11 additions & 6 deletions src/nyat.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, unicode, sequtils, posix
import os, unicode, sequtils, posix, strutils

type
FileNameAndOption = tuple[fileNameList: seq[string], options: seq[char]]
Expand Down Expand Up @@ -69,32 +69,37 @@ proc setBufferList(fileNameList: seq[string]): seq[seq[string]] =
for i in 0 ..< fileNameList.len:
result.add(openFile(fileNameList[i]))

proc setLineNumber(digit, currentNumber: int): string =
return " ".repeat(2) & $currentNumber & " ".repeat(digit - ($(currentNumber)).len + 1)

proc displayBuffer(buffer: seq[string], option: OptionList) =
var
lineNumber = 1
writeLine = ""
ignoreLine = false

let lineNumberDigit = ($buffer.len).len

for i in 0 ..< buffer.len:
if i < buffer.high and option.squeezeBlank:
if buffer[i] == "" and buffer[i + 1] == "":
ignoreLine = true

if option.numberNoBlank:
if buffer[i] != "":
writeLine = " " & $lineNumber & " "
writeLine = setLineNumber(lineNumberDigit, lineNumber)
lineNumber.inc
else:
writeLine = ""

if option.setLineNumber:
writeLine = " " & $lineNumber & " "
elif option.setLineNumber:
writeLine = setLineNumber(lineNumberDigit, lineNumber)
lineNumber.inc

if ignoreLine == false:
echo writeLine & buffer[i]
echo $writeLine & buffer[i]

ignoreLine = false
writeLine = ""

when isMainModule:
if commandLineParams().len == 0:
Expand Down

0 comments on commit 2cdefbb

Please sign in to comment.