parent
49a1eac1b6
commit
f2ebcdc16e
3 changed files with 19 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
import std/[os, posix, posix_utils]
|
||||
import lib/prnt
|
||||
|
||||
proc `<`(t1, t2: Time): bool {.borrow.}
|
||||
|
||||
|
@ -19,5 +20,4 @@ for dir in params:
|
|||
if latest[1] < tim:
|
||||
latest = (file.path, tim)
|
||||
|
||||
stdout.write latest[0]
|
||||
stdout.flushFile
|
||||
prnt latest[0]
|
||||
|
|
11
src/lib/prnt.nim
Normal file
11
src/lib/prnt.nim
Normal file
|
@ -0,0 +1,11 @@
|
|||
import std/terminal
|
||||
|
||||
let isTty = stdout.isatty
|
||||
|
||||
proc prnt*(what: string) =
|
||||
## Writes to stdout.
|
||||
## If the stdout is a tty, appends a newline.
|
||||
## Otherwise, no newline is inserted.
|
||||
stdout.write what
|
||||
if isTty: stdout.write "\n"
|
||||
stdout.flushFile
|
|
@ -1,4 +1,5 @@
|
|||
import std/[os, random, strutils]
|
||||
import std/[os, random, strutils, sugar]
|
||||
import lib/prnt
|
||||
|
||||
const selection = Digits + Letters
|
||||
|
||||
|
@ -10,8 +11,8 @@ let
|
|||
|
||||
randomize()
|
||||
|
||||
# todo: write helper proc that only writes newline if it's a tty
|
||||
for _ in 0 ..< length:
|
||||
stdout.write selection.sample
|
||||
let res = collect:
|
||||
for _ in 0 ..< length:
|
||||
selection.sample
|
||||
|
||||
stdout.flushFile
|
||||
prnt cast[string](res)
|
||||
|
|
Loading…
Reference in a new issue