commit c67a0e78eb94d630a2c3527afbdd19846ed866b8 Author: ge Date: Wed Jul 20 23:10:55 2022 +0300 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc175b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +hr +hr.1.gz diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9791a7a --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +PREFIX := "$$HOME/.local" + +all: + nimble build + rst2man src/hr.1.rst | gzip -9 -c > hr.1.gz + +install: + install -D hr $(PREFIX)/bin/hr + install -D hr.1.gz $(PREFIX)/share/man/man1/hr.1.gz diff --git a/README.md b/README.md new file mode 100644 index 0000000..6771432 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# hr + +A horizontal ruler for your terminal. + +Just another implementation of [hr](https://github.com/LuRsT/hr/wiki#alternative-hrs=) on Nim language. + +# Installation + +``` +make +make install +``` diff --git a/hr.nimble b/hr.nimble new file mode 100644 index 0000000..6887221 --- /dev/null +++ b/hr.nimble @@ -0,0 +1,14 @@ +# Package + +version = "0.1.0" +author = "ge" +description = "A horizontal ruler for your terminal" +license = "Unlicense" +srcDir = "src" +bin = @["hr"] + + +# Dependencies + +requires "nim >= 1.6.6" +requires "ncurses >= 1.0.2" diff --git a/src/hr.1.rst b/src/hr.1.rst new file mode 100644 index 0000000..5dd68d0 --- /dev/null +++ b/src/hr.1.rst @@ -0,0 +1,44 @@ +== +hr +== + +------------------------------------ +A horizontal ruler for your terminal +------------------------------------ + +:Author: ge +:Copyright: Unlicense +:Date: 2022 Jul 20 +:Manual section: 1 +:Version: baf 0.1.0 + +SYNOPSIS +======== + +hr ... + +DESCRIPTION +=========== + +Print line with passed characters till the end of terminal window. + +EXAMPLES +======== + +:: + + $ hr '*' + *************************************** + + $ hr '#--' + #--#--#--#--#--#--#--#--#--#--#--#--#-- + + $ hr + - + + ++++++++++++++++++++++++++++++++++++++++ + ---------------------------------------- + ++++++++++++++++++++++++++++++++++++++++ + +SEE ALSO +======== + +``ncurses``\(3X) diff --git a/src/hr.nim b/src/hr.nim new file mode 100644 index 0000000..6b0229f --- /dev/null +++ b/src/hr.nim @@ -0,0 +1,53 @@ +#[ + hr - A horizontal ruler for your terminal. + + This is free and unencumbered software released into the public domain. + + Anyone is free to copy, modify, publish, use, compile, sell, or + distribute this software, either in source code form or as a compiled + binary, for any purpose, commercial or non-commercial, and by any + means. + + In jurisdictions that recognize copyright laws, the author or authors + of this software dedicate any and all copyright interest in the + software to the public domain. We make this dedication for the benefit + of the public at large and to the detriment of our heirs and + successors. We intend this dedication to be an overt act of + relinquishment in perpetuity of all present and future rights to this + software under copyright law. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + For more information, please refer to +]# + +import std/os +import std/strutils +import ncurses + +var + cols: cint + params: seq[string] + +let win = initscr() # Initialise screen + +# Get terminal lines and columns +cols = getmaxx(win); endwin() + +when declared(commandLineParams): + params = commandLineParams() +else: + discard + +if paramCount() == 0: + params = @["="] + +# Draw horisontal rule +for str in params: + echo str.repeat(cols)[0 .. (cols - 1)]