::
Library : nimcx.nim Module : cxprint.nim Status : stable License : MIT opensource Latest : 2022-07-28 Compiler : latest stable or devel branch OS : Linux Description : provides most printing functions for the librarysingleLine,doubleLine, draw a respective dash line in desired fgcol white and desired bgcol
Types
Cxline {.inheritable.} = object startpos*: int endpos*: int toppos*: int botpos*: int cxlinetext*: CxlineText cxlinetext2*: CxlineText cxLinetext3*: CxlineText cxlinetext4*: CxlineText cxlinetext5*: CxlineText cxlinetext6*: CxlineText cxLinetext7*: CxlineText cxlinetext8*: CxlineText cxlinetext9*: CxlineText cxlinetext10*: CxlineText cxLinetext11*: CxlineText cxlinetext12*: CxlineText showbrackets*: bool linecolor*: string linechar*: string dotleftcolor*: string dotrightcolor*: string linetype*: CxLineType newline*: string
CxlineText = object text*: string textcolor*: string textstyle*: set[Style] textpos*: int textbracketopen*: string textbracketclose*: string textbracketcolor*: string
CxLineType = enum cxHorizontal = "horizontal", cxVertical = "vertical"
Vars
msgLeftWidth = 8
Procs
proc decho(z: int = 2) {....raises: [IOError], tags: [WriteIOEffect], forbids: [].}
-
decho
blank lines creator default = 2 blank lines
decho(10)
to create 10 blank lines
proc dline(n: int = tw; lt: string = "-"; col: string = termwhite) {. ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
-
dline
draw a dashed line with given length in current terminal font color line char can be changed
dline(30) dline(30,"/+") dline(30,col= yellow)
proc dlineLn(n: int = tw; lt: string = "-"; col: string = termwhite) {. ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
-
dlineLn
draw a dashed line with given length in current terminal font color line char can be changed
and issue a new line
dline(50,":",green) dlineLn(30) dlineLn(30,"/+/") dlineLn(60,col = salmon)
proc doty(d: int; fgr: string = white; bgr: string = black; xpos: int = 1) {. ...raises: [IOError, ValueError], tags: [WriteIOEffect], forbids: [].}
-
doty
prints number d of widedot ⏺ style dots in given fore/background color
each dot is of char length 4 added a space in the back to avoid half drawn dots
if it is available on your system otherwise a rectangle may be shown
import nimcx printLnBiCol("Test for : doty\n",truetomato,lime,":",0,false,{}) dotyLn(22 ,lime) dotyLn(18 ,salmon,bgBlue) dotyLn(18 ,salmon,truetomato,xpos=10) # using a foregroundcolor as backgroundcolor will color the dots itself dotyLn(18 ,yaleblue,truetomatobg,xpos=10) # backgroundcolor with xxxxbg colors background and dots will be in foregroundcolor
proc dotyLn(dots: int; fgr: string = termwhite; bgr: string = black; xpos: int = 1) {....raises: [IOError, ValueError], tags: [WriteIOEffect], forbids: [].}
-
dotyLn
prints number d of widedot ⏺ style dots in given fore/background color and issues new line
may not be available on all systems
each dot is of char length 4 .. code-block:: nim import nimcx dotyLn(18,red,limebg,10)
proc doubleLine(xpos: int = 0; width: int = tw; fgcol = termwhite; bgcol = termblack; newLine: bool = true) {. ...raises: [IOError, ValueError], tags: [WriteIOEffect], forbids: [].}
proc hline(n: int = tw; col: string = white; xpos: int = 0; lt: string = "-"): string {. discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
- forward declaration
proc hlineLn(n: int = tw; col: string = white; xpos: int = 0; lt: string = "-"): string {. discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
- forward declaration
proc newCxlineText(): CxlineText {....raises: [], tags: [], forbids: [].}
proc print[T](astring: T; fgr: string = getFg(fgDefault); bgr: string = getBg(bgDefault); xpos: int = 0; fitLine: bool = false; centered: bool = false; styled: set[Style] = {})
proc printAlertMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printBAlertMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printBelpMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printBErrorMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printBiCol[T](s: varargs[T, `$`]; colLeft: string = yellowgreen; colRight: string = termwhite; sep: string = ":"; xpos: int = 0; centered: bool = false; styled: set[Style] = {})
proc printCodeMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printCxLine(aline: var Cxline) {....raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
-
printCxLine
prints a horizontal line for frames or other use with or without text , with or without brackets around the text as specified in an Cxline object the underlaying CxLine object is still further developed. cxline object is defined in cxglobal.nim
proc printEelpMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printErrorMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printf(formatStr: cstring) {.importc, header: "<stdio.h>", varargs, ...raises: [], tags: [], forbids: [].}
-
printf
make C printf function available
printf("This works %s and this %d,too ", "as expected" ,2)
proc printFailMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printHelpMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printHL(s: string; substr: string; col: string = termwhite; bgr: string = getBg(bgDefault)) {....raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
-
printHL
print and highlight all appearances of a substring
with a certain color
printHL("HELLO THIS IS A TEST","T",green)
this would highlight all T in green
proc printInfoMsg(info: string = "Info "; atext: string = ""; colLeft: string = lightslategray; colRight: string = rosyBrown; xpos: int = 1): string {. discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLn[T](astring: T; fgr: string = getFg(fgDefault); bgr: string = getBg(bgDefault); xpos: int = 0; fitLine: bool = false; centered: bool = false; styled: set[Style] = {})
proc printLnAlertMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnBAlertMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnBelpMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnBErrorMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnBiCol[T](s: varargs[T, `$`]; colLeft: string = yellowgreen; colRight: string = termwhite; sep: string = ":"; xpos: int = 0; centered: bool = false; styled: set[Style] = {})
proc printLnCodeMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnEelpMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnErrorMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnFailMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnHelpMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnHL(s: string; substr: string; col: string = lightcyan; bgr: string = getBg(bgDefault)) {....raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
-
printLnHL
print and highlight all appearances of a char or substring of a string
with a certain color and issue a new line
printLnHL("HELLO THIS IS A TEST","T",lime)
this would highlight all T in lime
proc printLnInfoMsg(info: string = "Info "; atext: string = ""; colLeft: string = lightslategray; colRight: string = rosyBrown; xpos: int = 1): string {. discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnOkMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnPassMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printLnRainbow[T](s: T; styled: set[Style] = {})
-
printLnRainbow
print multicolored string with styles , for available styles see print
and issues a new line
may not work with certain Rune
import nimcx loopy(0..100, block: printLnRainBow(cxpad(" ",tw),{styleReverse}) printLnRainBow(cxpad(" NimCx " * 18 ,tw - 18),{styleBright}) sleepy(0.01))
proc printLnStatusMsg(atext: string = ""; xpos: int = 1; colLeft = lightseagreen) {. ...raises: [IOError, ValueError], tags: [WriteIOEffect], forbids: [].}
proc printOKMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printPassMsg(atext: string = ""; xpos: int = 1): string {.discardable, ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
proc printRainbow(astr: string; styled: set[Style] = {}) {. ...raises: [IOError, ValueError], tags: [WriteIOEffect, ReadEnvEffect], forbids: [].}
- forward declaration
proc printStatusMsg(atext: string = ""; xpos: int = 1; colLeft = lightseagreen) {. ...raises: [IOError, ValueError], tags: [WriteIOEffect], forbids: [].}
proc singleLine(xpos: int = 0; width: int = tw; fgcol = termwhite; bgcol = termblack; newLine: bool = true) {. ...raises: [IOError, ValueError], tags: [WriteIOEffect], forbids: [].}
Macros
macro pdebug(n: varargs[typed]): untyped
-
pdebug
prints variable name and value in debug view mode
ex https://stackoverflow.com/questions/47443206/how-to-debug-print-a-variable-name-and-its-value-in-nim
Templates
template cxprint(xpos: int; args: varargs[untyped])
-
cxprint
xpos : position Calls styledWrite with args given
remember that first param must be xpos
Backgroundcolors defined in cxconsts.nim colorNames can be used , that is any color ending with xxxxxxbg like pastelpinkbg
template cxprintLn(xpos: int; args: varargs[untyped])
-
cxprintLn
print to a certain x position
xpos : position Calls styledEcho with args given
Backgroundcolors defined in cxconsts.nim colorNames can be used , that is any color ending with xxxxxxbg like pastelpinkbg
Another way to specify colors is using the pallettec olors as specified in cxconsts.nim: cxprintLn(0,cxfg(cxgrey0),cxbg(cxgrey9),"BLABLASTRING",cxfg(cxgreen3),"GREENSTRING")
remember that first item must be xpos and that wide unicode chars or Rune may not give desired result if written close to each other
cxprintLn(5,yaleblue,pastelbluebg,"this is a test ",trueblue,pastelpinkbg,styleReverse,stylebright," needed somme color change" cxprintln(0,trueblue,bgwhite," Yes ! ", yaleblue,truetomatobg," No ! ", trueblue,bgwhite,styleReverse," Yes ! ", truetomato,darkslatebluebg,styleBlink,styleBright," Oooh, it blinks too ! ")
template cxprintxy(xpos: int; ypos: int; args: varargs[untyped])
-
cxprint
print to a certain x , y position in the terminal xpos : x position ypos : y position starting from 0,0 Calls styledWrite with args given
enough space must be available in terminal window
Backgroundcolors defined in cxconsts.nim colorNames can be used , that is any color ending with xxxxxxbg like pastelpinkbg
template cxwrite(args: varargs[untyped])
-
cxwrite
Calls styledWrite with args given
Backgroundcolors defined in cxconsts.nim colorNames can be used , that is any color ending with xxxxxxbg like pastelpinkbg
x positioning via cxpos(x) x,y positioning via cxPosxy(x,y)
template cxwriteLn(args: varargs[untyped])
-
cxwriteLn
Calls styledWriteLine with args given
Backgroundcolors defined in cxconsts.nim colorNames can be used , that is any color ending with xxxxxxbg like pastelpinkbg
template dprint[T](s: T)
-
dprint
debug print shows contents of s in repr mode
usefull for debugging