Initial commit and implementation.

This commit is contained in:
2025-12-19 11:36:34 -06:00
commit 0f40bc9ae4
3 changed files with 60 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/hr
.*.sw?

14
hr.nimble Normal file
View File

@@ -0,0 +1,14 @@
# Package
version = "0.1.0"
author = "Jonathan Bernard"
description = "Simple CLI utility to print a horizontal rule with an optional header"
license = "MIT"
srcDir = "src"
bin = @["hr"]
# Dependencies
requires "nim >= 2.2.6"
requires @["cliutils >= 0.11.0", "docopt"]

44
src/hr.nim Normal file
View File

@@ -0,0 +1,44 @@
import std/[strutils, terminal, unicode]
import cliutils, docopt
# This is just an example to get you started. A typical binary package
# uses this file as the main entry point of the application.
const VERSION = "0.1.0"
const USAGE = """Usage:
hr [<heading>] [options]
Options:
-c, --color <color> Color to make the rule.
-d, --double-rule Draw as ═══════════
-C, --char <char> Character to use to make the rule
"""
when isMainModule:
try:
let args = docopt(USAGE, version = VERSION)
let color =
if args["--color"]: parseEnum[TerminalColors]("c" & $args["--color"])
else: cDefault
let ruleChar =
if args["--char"]: $args["--char"]
elif args["--double-rule"]: ""
else: ""
stdout.writeLine(termFmt(
repeat(ruleChar, terminalWidth()),
fg = color, bg = cDefault))
if args["<heading>"]:
let heading = $args["<heading>"]
let padding = max(0, (terminalWidth() - runeLen(heading)) div 2)
stdout.writeLine(termFmt(
repeat(" ", padding) & heading & repeat(" ", padding),
fg = color, bg = cDefault))
except:
stderr.writeLine("hf - FATAL: " & getCurrentExceptionMsg())
stderr.writeLine(getCurrentException().getStackTrace())
quit(QuitFailure)