Skip to content
πŸ–οΈ Paint your terminal output like Picasso 🎨
V Shell AMPL
Branch: master
Clone or download
Latest commit 75e1761 Nov 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create FUNDING.yml Nov 22, 2019
.gitignore initial commit Nov 11, 2019
LICENSE Create LICENSE Nov 12, 2019
README.md Update README.md Nov 22, 2019
colors.v initial commit Nov 11, 2019
constants.v initial commit Nov 11, 2019
crayon.v
crayon_test.v initial commit Nov 11, 2019
parser.v initial commit Nov 11, 2019
styles.v initial commit Nov 11, 2019
test.sh initial commit Nov 11, 2019
utils.v initial commit Nov 11, 2019
v.mod initial commit Nov 11, 2019
vpkg.json initial commit Nov 11, 2019

README.md

πŸ–οΈ Crayon

An extremely simple way to turn your bland terminal output into beautifully styled text.

Installation:

Install using vpkg

vpkg get https://github.com/thecodrr/crayon

Install using v's builtin vpm (you will need to import the module with: import thecodrr.crayon with this method of installation):

v install thecodrr.crayon

Install using git:

cd path/to/your/project
git clone https://github.com/thecodrr/crayon
# Or add it as a submodule
git submodule add https://github.com/thecodrr/crayon crayon && git submodule update --init --recursive

Then in the wherever you want to use it:

import crayon

And that's it!

Usage

crayon.new(texts ...string)

Initializes a new Crayon for the specified text. You can pass multiple strings in the texts argument. Nesting Crayons is supported (see example below).

crayon.new returns a Chalk by default. Turn it into a styled string using the .str() function

crayon.new("Hello", crayon.new("world").bold().str()).cyan().underline().str()

crayon.color(text string)

Use this to style the text using the template API.

crayon.color("{bold.underline I am bold and underlined} and I am not")

Each template starts with { and ends with }. All styles must come at the beginning without any spaces. This function returns a string by default. You can use rgb function as rgb(92,92,92) to use custom colors.

Nested templates are currently not supported (WIP) so keep in mind that.

crayon.strip_text(text string)

Strip a styled string of all the styles returning a pure & clean string

The Crayon struct

The template API uses these same names just without the () except for the rgb usage.

Styles:

bold()

italic()

reverse()

underline()

strikethrough()

dim()

slow_blink()

rapid_blink()

Colors:

For background colors just put bg_ before each method

black()

white()

red()

green()

yellow()

blue()

magenta()

cyan()

light_gray()

dark_gray()

light_red()

light_green()

light_yellow()

light_blue()

light_magenta()

light_cyan()

RGB Support

rbg(int,int,int)

Other Methods:

strip() Strip the Crayon of all styles. Returns a string

len() Get the actual length of the styled string. Same as doing strip().len()

print()Print the styled stringtoterminal.

print_with(...string)Print the styled string to terminal with some additional strings

Projects Using Crayon:

  1. thecodrr.boxx

Find this library useful? ❀️

Support it by joining stargazers for this repository. ⭐️ or buy me a cup of coffee And follow me for my next creations! 🀩

License

Copyright (c) 2019 Abdullah Atta

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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 OR COPYRIGHT HOLDERS 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.
You can’t perform that action at this time.