In case youre new to golang, I write instructions explicitly. Here I use word "line" instead of "string" to specify that its a construct of this particular library.
"Line" is ln struct field
which we populate by chaining(calling) methods on newly created struct instance.
And finally print with
Action | Command |
---|---|
Open your golang project and make sure you have go.mod |
go mod init MODULE_NAME go mod tidy |
Download library to your local folder /home/LOCALUSER/go/pkg/mod/github.com/r00m3 |
go get github.com/r00m3/lines go mod tidy |
Create new string named w for later use | w := "World" |
Create new "line" named ln | ln := lines.New{} |
Keep adding properties(by chaining methods) to your newly created ln | ln. |
Add black background to your line |
ln. BG_black(). |
Add bright green foreground to your line |
ln. BG_black(). FG_BR_green(). |
Add text "Hello" to your line |
ln. BG_black(). FG_BR_green(). ADD("Hello"). |
Carriage return("enter") on your line |
ln. BG_black(). FG_BR_green(). ADD("Hello"). ASCII_new_ln(). |
Add print specifier("placeholder") "%s" |
ln. BG_black(). FG_BR_green(). ADD("Hello"). ASCII_new_ln(). ADD("%s"). |
Another carriage return("enter") on your line |
ln. BG_black(). FG_BR_green(). ADD("Hello"). ASCII_new_ln(). ADD("%s"). ASCII_new_ln(). |
Resets all text attributes to defaults. "Terminal prints" in "normal text" after this. |
ln. BG_black(). FG_BR_green(). ADD("Hello"). ASCII_new_ln(). ADD("%s"). ASCII_new_ln(). RESET(). |
Your string("line") is now styled, formatted and ready to be
printed. Print it. Dont forget to supply arguments for "%s" placeholder. We use w from earlier w := "World" |
ln. BG_black(). FG_BR_green(). ADD("Hello"). ASCII_new_ln(). ADD("%s"). ASCII_new_ln(). RESET(). PRINT(w) |