Giter Club home page Giter Club logo

cfonts's Introduction

     ██████╗ ███████╗  ██████╗  ███╗   ██╗ ████████╗ ███████╗
    ██╔════╝ ██╔════╝ ██╔═══██╗ ████╗  ██║ ╚══██╔══╝ ██╔════╝
    ██║      █████╗   ██║   ██║ ██╔██╗ ██║    ██║    ███████╗
    ██║      ██╔══╝   ██║   ██║ ██║╚██╗██║    ██║    ╚════██║
    ╚██████╗ ██║      ╚██████╔╝ ██║ ╚████║    ██║    ███████║
     ╚═════╝ ╚═╝       ╚═════╝  ╚═╝  ╚═══╝    ╚═╝    ╚══════╝

cfont styles

api example

crates badge crates docs tests build status npm cfonts Coverage Status

This is a silly little command line tool for sexy ANSI fonts in the console. Give your cli some love.

Implementations

Rust

Read more in the Rust folder.

Nodejs

Read more in the Nodejs folder.

Install

Rust

brew install cfonts
yay -S cfonts
sudo dnf install cfonts
nix-env -iA nixos.cfonts
sudo port install cfonts
cargo install cfonts

NodeJs

npm i cfonts -g
yarn global add cfonts

Usage

Using the CLI is easy.

Usage: cfonts  "<value>" [option1] <input1> [option2] <input1>,<input2> [option3] etc...

At any point you can run the help command to get a full list of commands and how to use them.

$ cfonts --help

Supported Characters

A P 4 $
B Q 5 %
C R 6 &
D S 7 (
E T 8 )
F U 9 /
G V ! :
H W ? ;
I X . ,
J Y + '
K Z - "
L 0 _ (space)
M 1 =
N 2 @
O 3 #

The | character will be replaced with a line break

Options

-h, --help

Type: <command>
Default value: none

This shows a list of all available options.

$ cfonts --help

Help command

-V, --version

Type: <command>
Default value: none

This shows the installed version.

$ cfonts --version

Version command

text

Type: <string>
Default value: ""

This is the "text input" to be converted into a nice font.
The | character will be replaced with a line break.

$ cfonts "Hello world"

Text command

-f, --font

Type: <string>
Default value: "block"

This is the font face you want to use. So far this plugin ships with with following font faces:

$ cfonts "text" --font "chrome"

Font command

  • block [colors: 2] (default) block font style
  • slick [colors: 2] slick font style
  • tiny [colors: 1] tiny font style
  • grid [colors: 2] grid font style
  • pallet [colors: 2] pallet font style
  • shade [colors: 2] shade font style
  • chrome [colors: 3] chrome font style
  • simple [colors: 1] simple font style
  • simpleBlock [colors: 1] simple-block font style
  • 3d [colors: 2] 3d font style
  • simple3d [colors: 1] simple-3d font style
  • huge [colors: 2] huge font style
  • console [colors: 1] console font style

-a, --align

Type: <string>
Default value: "left"

You can align your text in the terminal with this option. Use the keywords below:

  • left (default)
  • center
  • right
  • top (Will be ignored if used with the spaceless option)
  • bottom (Will be ignored if used with the spaceless option)
$ cfonts "text" --align "center"

Align command

-c, --colors

Type: <string list>
Default value: ['system']

With this setting you can set the colors for your font. Use the below color strings or a hex color.
Provide colors in a comma-separated string, eg: red,blue. (no spaces)
If you use a hex color make sure you include the # prefix. (In most terminals wrap the hex in quotes)
The system color falls back to the system color of your terminal.

💡 There are environment variables that can affect the display of colors in your terminal.

  • system (default)
  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright
  • #ff8800 (any valid hex color)
  • #f80 (short form is supported as well)
$ cfonts "text" --colors white,"#f80"

Colors command

-g, --gradient

Type: <string list>
Default value: false

With this setting you can set a gradient over your output.
This setting supersedes the color open.
The gradient requires two colors, a start color and an end color from left to right.
(If you want to set your own colors for the gradient, use the transition option.)
cfonts will then generate a gradient through as many colors as it can find to make the output most impressive.
Provide two colors in a comma-separated string, eg: red,blue. (no spaces)
If you use a hex color make sure you include the # prefix. (In the terminal wrap the hex in quotes)

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray
  • grey
  • #ff8800 (any valid hex color)
  • #f80 (short form is supported as well)
$ cfonts "text" --gradient red,"#f80"

Gradient command

-i, --independent-gradient

Type: <boolean>
Default value: false

Set this option to re-calculate the gradient colors for each new line.
Only works in combination with the gradient option.

$ cfonts "text|next line" --gradient red,"#f80" --independent-gradient

Independent gradient command

-t, --transition-gradient

Type: <boolean>
Default value: false

Set this option to generate your own gradients. Each color set in the gradient option will then be transitioned to directly. This option allows you to specify more than just two colors for your gradient.
Only works in combination with the gradient option.

$ cfonts "text" --gradient red,"#f80",green,blue --transition-gradient

Independent gradient command

-b, --background

Type: <string>
Default value: "transparent"

With this setting you can set the background colors for the output. Use the below color strings. Provide the background color from the below supported list, eg: 'white'

  • transparent (default)
  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • blackBright
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright
  • #ff8800 (any valid hex color)
  • #f80 (short form is supported as well)
$ cfonts "text" --background "Green"

Background command

-l, --letter-spacing

Type: <integer>
Default value: 1

Set this option to widen the space between characters.

$ cfonts "text" --letter-spacing 2

Letter spacing command

-z, --line-height

Type: <integer>
Default value: 1

Set this option to widen the space between lines.

$ cfonts "text" --line-height 2

Line height command

-s, --spaceless

Type: <boolean>
Default value: false

Set this option to false if you don't want the plugin to insert two empty lines on top and on the bottom of the output.

$ cfonts "text" --spaceless

Spaceless command

-m, --max-length

Type: <integer>
Default value: 0

This option sets the maximum characters that will be printed on one line.
cfonts detects the size of your terminal but you can opt out and determine your own max width.
0 means no max width and the text will break at the edge of the terminal window.

$ cfonts "text" --max-length 15

Max length command

-e, --env

Type: <string>
Default value: cli

This option lets you use cfonts to generate HTML instead of ANSI code.
Note that max-length will be set to very large.

$ cfonts "text" --env browser

Max length command

Consistency

cfonts detects what colors are supported on your platform. It sets a level of support automatically. In cfonts you can override this by passing in the FORCE_COLOR environment variable.

FORCE_COLOR=3 cfonts "hello world" -c "#0088ff"

You can also use the NO_COLOR environment variable to set no color output for environments like CI.

NO_COLOR="" cfonts "hello world" -c "#0088ff"

💡 FORCE_COLOR overrides NO_COLOR if both are set.

Color consistency via env vars

License

Copyleft (c) 2023 Dominik Wilkowski. Licensed under the GNU GPL-3.0-or-later.

cfonts's People

Contributors

0xflotus avatar abhijit-hota avatar ag0x00 avatar alcir avatar alextrastero avatar curtisgibby avatar dominikwilkowski avatar leifhelm avatar markseuffert avatar matei-radu avatar nav1s avatar papb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cfonts's Issues

d.ts

可以提供typescript d.ts 类型声明吗?

Is there any way to use this in python?

Sorry if this is a dumb question, but is there any way to use this in python? I can't just copy paste, it completely breaks. I know there's a version of this made in python, called python-cfonts, by frostming, but the gradients don't look good. I know the console supports more colors, but is there a way to use it in python? TIA!

color detection not working as intended?

If I set TERM=xterm-256color or TERM=xterm, I don't get a smooth gradient transition, but it works if I set FORCE_COLOR=3.

Does this mean color detection is not working as intended?

About license of porting library

As you may know, I am maintaining a Python port of cfonts.

At beginning, I just translate node js code to Python, but after the major refactor, I write my own code to implement new features. I would like to know if I can apply a different license other than GPL2.0, say, MIT?

Panic with gradient and font "console"

To reproduce:

$ cfonts "$(seq 200)" -f console -g red,magenta
thread 'main' panicked at src/gradient.rs:443:32:
range end index 3 out of range for slice of length 2
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This bug depends on the width of the terminal and the length of the text.
If you can't reproduce the panic, try it in a narrower window or increase the seq argument.

Throws when run non-interactively

When this module is used in a process that runs non-interactively (non-TTY, for example, when it's a child process), it throws:

TypeError {
    message: 'Cannot read property \'width\' of undefined',
  }

  Object.render (node_modules/cfonts/index.js:464:121)

I would suggest using term-size instead of window-size, as it works even when non-TTY. Alternatively, you could fall back to a width of 80.

error: unknown option `-t'

$ npm install -g cfonts
/home/chaz/.local/bin/cfonts -> /home/chaz/.local/lib/node_modules/cfonts/bin/font.js
/home/chaz/.local/lib
└── [email protected]

$ which cfonts
~/.local/bin/cfonts

$ cfonts

 Ouch: Please provide text to convert with cfonts -t "Text"
       Run cfonts --help for more infos

$ cfonts -t "Text"

  error: unknown option `-t'

If I can provide any more useful information please let me know.

Should be possible to not have a background color

screen shot 2018-04-07 at 17 44 54

This is how it looks in my terminal by default. Pretty ugly, since the default black background doesn't match my terminal background. I think the default should be no background color, but I would be happy with having a 'none' option too.

center text

could you add an option to center text horizontally?

Brew: No available formula

brew install cfonts

Warning: No available formula with the name "cfonts". Did you mean conftest?
==> Searching for similarly named formulae...
This similarly named formula was found:
conftest
To install it, run:
  brew install conftest
==> Searching for a previously deleted formula (in the last
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

New lines with \n instead of |

When using CFonts.say() I think it would be nice to be able to add a new line. An example of this might be:

CFonts.say( `Please some stuff \n Some stuff on a new line`, {
  font:  'console',
  align: 'center',
  colors: [ 'white' ],
});

I understand that you can do:

CFonts.say( `Please some stuff | Some stuff on a new line`, {
  font:  'console',
  align: 'center',
  colors: [ 'white' ],
});

Happy for this to be closed if it's not possible. I just thought it would be nice to mimic default console.log behaviour in this instance.

throws 'userColors[color].toLowerCase() is not a function'

If my program contains custom properties for Array, then CheckInput() throws a "TypeError: userColors[color].toLowerCase() is not a function" error. This is because for (var color in userColors) iterates over both the array elements and the custom properties. I believe changing for...in to for...of will fix it. To reproduce:

Array.prototype.foo = () => { return 0; };
const cfonts = require('cfonts');
cfonts.say('Hello', { colors: [ 'green' ] });

Classic ASCII Art Banner

Hi,

do you have an example for the classic ASCII art banner that draws my String with lines in Rust?

Can cfonts be webpacked?

When I build my project with webpack,then run the .js file, I got error:

Error: ENOENT: no such file or directory, open '/package.json'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:343:35)

Can webpack cfonts into one file? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.