all repos — nifty @ 2a8262c36baf39a880f4fbbcdba53cff7ac56a60

A tiny (pseudo) package manager and script runner.

lib/messaging.nim

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
import
  terminal,
  strutils

import
  minimline

proc foreground(str: string, color: ForegroundColor) =
  stdout.setForegroundColor(color)
  stdout.write(str)
  resetAttributes()

proc printGreen*(str: string) =
  foreground(str, fgGreen)
  
proc printRed*(str: string) =
  foreground(str, fgRed)
  
proc printYellow*(str: string) =
  foreground(str, fgYellow)
  
proc printBlue*(str: string) =
  foreground(str, fgBlue)
  
proc confirm*(q: string): bool =
  printYellow("(!) " & q & " [y/n]: ")
  var ed = initEditor()
  let answer = ed.readLine().toLowerAscii[0]
  if answer == 'y':
    return true
  return false

proc printValue*(key, value: string) =
  printBlue("    -> $1: " % key)
  printGreen(value)
  resetAttributes()
  stdout.write("\n")

proc editValue*(key: string, value = ""): string =
  printBlue("    -> $1: " % key)
  var ed = initEditor()
  result = ed.edit(value)
  
proc printDeleted*(label, value: string) =
  printRed("--- ")
  echo label & ": " & value

proc printAdded*(label, value: string) =
  printGreen("+++ ")
  echo label & ": " & value