├── .gitignore ├── LICENSE ├── fab.nimble ├── readme.md └── src └── fab.nim /.gitignore: -------------------------------------------------------------------------------- 1 | nimcache/ 2 | fab 3 | test1 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Anirudh Oppiliappan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /fab.nimble: -------------------------------------------------------------------------------- 1 | # Package 2 | 3 | version = "0.4.3" 4 | author = "Anirudh" 5 | description = "Print fabulously in your terminal" 6 | license = "MIT" 7 | srcDir = "src" 8 | 9 | # Dependencies 10 | 11 | requires "nim >= 0.19.0" 12 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | > Print fabulously in your terminal (in Nim). 6 | 7 | Fab is a really cool text formatting package for Nim. Using Fab is super easy, it's as simple as: 8 | ```Nim 9 | import fab 10 | 11 | blue("hey i'm blue!") 12 | bold("this is bold text") 13 | que("what?") 14 | ``` 15 | 16 | ## Installation 17 | ```console 18 | $ nimble install fab 19 | ``` 20 | 21 | ## Screenshot 22 | ![screenshot](https://0x0.st/swP6.png) 23 | 24 | ## Colors 25 | ![colors](https://0x0.st/swPI.png) 26 | 27 | ## Styles 28 | ![styles](https://0x0.st/swPl.png) 29 | 30 | ## Labels 31 | ![labels](https://0x0.st/swP0.png) 32 | 33 | ### Color procs 34 | ``` 35 | blue(), yellow(), red(), green(), white(), purple(), black(), cyan() 36 | ``` 37 | 38 | ### Style procs 39 | ``` 40 | bold(), italics(), strike(), under() 41 | ``` 42 | 43 | ### Label procs 44 | ``` 45 | que(), info(), run(), bad(), good() 46 | ``` 47 | 48 | ```nim 49 | Style 50 | styleBright, # bright text 51 | styleDim, # dim text 52 | styleUnknown, # unknown 53 | styleUnderscore, # underscored text 54 | styleBlink, # blinking/bold text 55 | styleHidden # hidden text 56 | ``` 57 | 58 | #### Example 59 | ```nim 60 | blue("this is bold and blue", sty = {styleBright}) 61 | ``` 62 | 63 | ```nim 64 | ForegroundColor 65 | fgBlack, # black 66 | fgRed, # red 67 | fgGreen, # green 68 | fgYellow, # yellow 69 | fgBlue, # blue 70 | fgMagenta, # magenta 71 | fgCyan, # cyan 72 | fgWhite # white 73 | ``` 74 | 75 | #### Example 76 | ```nim 77 | bold("this is bold and red", fg = fgRed) 78 | ``` 79 | 80 | #### More examples 81 | ```nim 82 | blue("this is bold and underlined blue", sty = {styleBright, styleUnderscore}, nl = false) # no newline 83 | 84 | dim("this is yellow and dim", fg = fgYellow) 85 | ``` 86 | 87 | ## Inspiration 88 | This project was heavily inspired by [@s0md3v](https://github.com/s0me3v)'s [Hue](https://github.com/s0md3v/hue). 89 | 90 | ## Contributing 91 | Bad code? New feature in mind? Open an issue. Better still, learn [Nim](https://nim-lang.org/documentation.html) and shoot a PR :sparkles: 92 | 93 | ## Credits 94 | Thanks a bunch to [@kaushalmodi](https://github.com/kaushalmodi) for the complete rewrite. It's all pretty much his now. 95 | 96 | ## License 97 | MIT © [Anirudh Oppiliappan](https://icyphox.sh) 98 | -------------------------------------------------------------------------------- /src/fab.nim: -------------------------------------------------------------------------------- 1 | import terminal 2 | 3 | template fabEcho*(s: string; fg: ForegroundColor; styleSet: set[Style] = {}; newline = true; brightFg = false) = 4 | setForeGroundColor(fg, brightFg) 5 | s.writeStyled(styleSet) 6 | resetAttributes() 7 | if newline: 8 | echo "" 9 | 10 | # colors 11 | proc blue*(s: string; sty: set[Style] = {}; nl = true) = 12 | fabEcho(s, fgBlue, sty, nl) 13 | 14 | proc yellow*(s: string; sty: set[Style] = {}; nl = true) = 15 | fabEcho(s, fgYellow, sty, nl) 16 | 17 | proc green*(s: string; sty: set[Style] = {}; nl = true) = 18 | fabEcho(s, fgGreen, sty, nl) 19 | 20 | proc red*(s: string; sty: set[Style] = {}; nl = true) = 21 | fabEcho(s, fgRed, sty, nl) 22 | 23 | proc white*(s: string; sty: set[Style] = {}; nl = true) = 24 | fabEcho(s, fgWhite, sty, nl) 25 | 26 | proc purple*(s: string; sty: set[Style] = {}; nl = true) = 27 | fabEcho(s, fgMagenta, sty, nl) 28 | 29 | proc cyan*(s: string; sty: set[Style] = {}; nl = true) = 30 | fabEcho(s, fgCyan, sty, nl) 31 | 32 | proc black*(s: string; sty: set[Style] = {}; nl = true) = 33 | fabEcho(s, fgBlack, sty, nl) 34 | 35 | proc grey*(s: string; sty: set[Style] = {}; nl = true) = 36 | fabEcho(s, fgBlack, sty, nl, brightFg = true) 37 | 38 | proc orange*(s: string; sty: set[Style] = {}; nl = true) = 39 | fabEcho(s, fgYellow, sty, nl, brightFg = true) 40 | 41 | # styles 42 | proc bold*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 43 | fabEcho(s, fg, {styleBright} + sty, nl) 44 | 45 | # https://github.com/nim-lang/Nim/pull/8048 46 | proc italic*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 47 | fabEcho(s, fg, {styleItalic} + sty, nl) 48 | 49 | proc reverse*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 50 | fabEcho(s, fg, {styleReverse} + sty, nl) 51 | 52 | proc under*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 53 | fabEcho(s, fg, {styleUnderscore} + sty, nl) 54 | 55 | proc blink*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 56 | fabEcho(s, fg, {styleBlink} + sty, nl) 57 | 58 | proc dim*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 59 | fabEcho(s, fg, {styleDim} + sty, nl) 60 | 61 | proc hidden*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 62 | fabEcho(s, fg, {styleHidden} + sty, nl) 63 | 64 | # https://github.com/nim-lang/Nim/pull/8048 65 | # template strike*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 66 | # fabEcho(s, fg, {styleStrikethrough} + sty, nl) 67 | 68 | 69 | # labels 70 | proc fabLabelEcho*(label: string; lFg: ForegroundColor; s: string; sFg: ForegroundColor; styleSet: set[Style] = {}; newline = true; brightFg = false) = 71 | fabEcho(label, lFg, styleSet, false, brightFg) 72 | stdout.write(" ") 73 | fabEcho(s, sFg, styleSet, false, brightFg) 74 | if newline: 75 | echo "" 76 | 77 | proc que*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 78 | fabLabelEcho("[?]", fgBlue, s, fg, sty, nl) 79 | 80 | proc info*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 81 | fabLabelEcho("[!]", fgYellow, s, fg, sty, nl) 82 | 83 | proc bad*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 84 | fabLabelEcho("[!]", fgRed, s, fg, sty, nl) 85 | 86 | proc good*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 87 | fabLabelEcho("[+]", fgGreen, s, fg, sty, nl) 88 | 89 | proc run*(s: string; fg: ForegroundColor = fgWhite; sty: set[Style] = {}; nl = true) = 90 | fabLabelEcho("[~]", fgWhite, s, fg, sty, nl) 91 | 92 | when isMainModule: 93 | echo "" 94 | bold "COLORS" 95 | blue("this is blue") 96 | echo "ordinary text" 97 | blue("this is bold blue", sty = {styleBright}) 98 | 99 | blue("this is blue", nl = false) # no newline 100 | yellow(" this is bold yellow ", sty = {styleBright}, nl = false) # no newline 101 | blue("this is bold and underlined blue", sty = {styleBright, styleUnderscore}, nl = false) # no newline 102 | blue(" this is blue") 103 | 104 | red("this is red") 105 | yellow("this is yellow") 106 | green("this is green") 107 | white("this is white") 108 | white("this is white in reverse", sty = {styleReverse}) 109 | purple("this is purple") 110 | cyan("this is cyan") 111 | black("this is black", nl = false); echo "<-- text in black foreground to the left" 112 | grey("this is grey") 113 | orange("""this is orange?/"bright yellow"""") 114 | 115 | echo "" 116 | bold "STYLES" 117 | dim("this is dim") 118 | yellow("this is yellow") 119 | dim("this is yellow and dim", fg = fgYellow) 120 | echo "this is regular" 121 | bold("this is bold") 122 | italic("this is italics/shows up reversed on terminals not supporting italics") 123 | reverse("this is reverse") 124 | under("this is underlined") 125 | blink("this is blinking!") 126 | italic("this is italics and bold!", sty = {styleBright}) 127 | dim("this is dim and reverse!", sty = {styleReverse}) 128 | bold("this is bold and reverse and red!!", fg = fgRed, sty = {styleReverse}) 129 | 130 | white("before hidden text 'abcdefghijklm'", nl = false) # no newline 131 | hidden("abcdefghijklm", nl = false) # no newline 132 | white("after hidden text") 133 | 134 | # echo strike("this is striked") 135 | 136 | echo "" 137 | bold "LABELS" 138 | que("what?") 139 | info("fyi") 140 | bad("you suck") 141 | bad("everything in red bold", fg = fgRed, sty = {styleBright}) 142 | good("yay!") 143 | run("hacking in progress...") 144 | run("everything in bold", sty = {styleBright}) 145 | --------------------------------------------------------------------------------