Giter VIP home page Giter VIP logo

colorize's Introduction

colorize

libcolorize provide simple text colorization for terminal emulator, using ansi escape characters.

To build libcolorize just do :

> rustc lib.rs

libcolorize is really simple to use, see this short example !

extern crate colorize;
// Import the trait implemented for &'static str and ~str
use colorize::AnsiColor;
// Import the colors for the global
use colorize::{BrightRed, Blue};

pub fn main() {
    // Set some global colors
    colorize::global_fg(BrightRed);
    colorize::global_bg(Blue);
    // ^~~~ These settings are reset to default at the end.

    // You can use specific colors or style on a given str,
    // the globals colors are restored after !

    // Write a green underlined text on a yellow background !
    println!("{}", "Hello World !".green().underlined().yellowb());

    // Use bright or normal colors
    println!("{}", "Bright Green foreground and Magenta background !".b_green().magentab());
}

colorize's People

Contributors

artemgr avatar crazysacx avatar jeremyletang avatar robertg avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

colorize's Issues

Fix example code in README

Code:

extern crate colorize;
// Import the trait implemented for &'static str and ~str
use colorize::AnsiColor;
// Import the colors for the global
use colorize::{BrightRed, Blue};

pub fn main() {
    // Set some global colors
    colorize::global_fg(BrightRed);
    colorize::global_bg(Blue);
    // ^~~~ These settings are reset to default at the end.

    // You can use specific colors or style on a given str,
    // the globals colors are restored after !

    // Write a green underlined text on a yellow background !
    println!("{}", "Hello World !".greenf().underline().yellowb());

    // Use bright or normal colors
    println!("{}", "Bright Green foreground and Magenta background !".b_greenf().magentab());
}

Output:

       Fresh colorize v0.0.1 (https://github.com/jeremyletang/colorize.git?ref=ab5f038c641230ea241b6d2410062e8b22693f6d#ab5f038c)
   Compiling cs246test v0.0.1 (file:///Users/rgawdzik/dev/cs246test)
     Running `rustc /Users/rgawdzik/dev/cs246test/src/main.rs --crate-name cs246test --crate-type bin -g --out-dir /Users/rgawdzik/dev/cs246test/target --dep-info /Users/rgawdzik/dev/cs246test/target/.fingerprint/cs246test-75a75b6da226fb91/dep-bin-cs246test -L /Users/rgawdzik/dev/cs246test/target -L /Users/rgawdzik/dev/cs246test/target/deps --extern colorize=/Users/rgawdzik/dev/cs246test/target/deps/libcolorize-2a03534959cde361.dylib --extern colorize=/Users/rgawdzik/dev/cs246test/target/deps/libcolorize-2a03534959cde361.rlib`
/Users/rgawdzik/dev/cs246test/src/main.rs:17:36: 17:44 error: type `&'static str` does not implement any method in scope named `greenf`
/Users/rgawdzik/dev/cs246test/src/main.rs:17     println!("{}", "Hello World !".greenf().underline().yellowb());
                                                                                ^~~~~~~~
/Users/rgawdzik/dev/cs246test/src/main.rs:20:71: 20:81 error: type `&'static str` does not implement any method in scope named `b_greenf`
/Users/rgawdzik/dev/cs246test/src/main.rs:20     println!("{}", "Bright Green foreground and Magenta background !".b_greenf().magentab());
                                                                                                                   ^~~~~~~~~~
/Users/rgawdzik/dev/cs246test/src/main.rs:17:20: 17:66 error: unable to infer enough type information to locate the impl of the trait `core::fmt::Show` for the type `<generic #309>`; type annotations required
/Users/rgawdzik/dev/cs246test/src/main.rs:17     println!("{}", "Hello World !".greenf().underline().yellowb());
                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/Users/rgawdzik/dev/cs246test/src/main.rs:17:5: 17:68 note: expansion site
/Users/rgawdzik/dev/cs246test/src/main.rs:17:20: 17:66 note: the trait `core::fmt::Show` must be implemented because it is required by `core::fmt::secret_show`
/Users/rgawdzik/dev/cs246test/src/main.rs:17     println!("{}", "Hello World !".greenf().underline().yellowb());
                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/Users/rgawdzik/dev/cs246test/src/main.rs:17:5: 17:68 note: expansion site
/Users/rgawdzik/dev/cs246test/src/main.rs:20:20: 20:92 error: unable to infer enough type information to locate the impl of the trait `core::fmt::Show` for the type `<generic #497>`; type annotations required
/Users/rgawdzik/dev/cs246test/src/main.rs:20     println!("{}", "Bright Green foreground and Magenta background !".b_greenf().magentab());
                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/Users/rgawdzik/dev/cs246test/src/main.rs:20:5: 20:94 note: expansion site
/Users/rgawdzik/dev/cs246test/src/main.rs:20:20: 20:92 note: the trait `core::fmt::Show` must be implemented because it is required by `core::fmt::secret_show`
/Users/rgawdzik/dev/cs246test/src/main.rs:20     println!("{}", "Bright Green foreground and Magenta background !".b_greenf().magentab());
                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/Users/rgawdzik/dev/cs246test/src/main.rs:20:5: 20:94 note: expansion site
error: aborting due to 4 previous errors
Could not compile `cs246test`.

Caused by:
  Process didn't exit successfully: `rustc /Users/rgawdzik/dev/cs246test/src/main.rs --crate-name cs246test --crate-type bin -g --out-dir /Users/rgawdzik/dev/cs246test/target --dep-info /Users/rgawdzik/dev/cs246test/target/.fingerprint/cs246test-75a75b6da226fb91/dep-bin-cs246test -L /Users/rgawdzik/dev/cs246test/target -L /Users/rgawdzik/dev/cs246test/target/deps --extern colorize=/Users/rgawdzik/dev/cs246test/target/deps/libcolorize-2a03534959cde361.dylib --extern colorize=/Users/rgawdzik/dev/cs246test/target/deps/libcolorize-2a03534

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.