GithubHelp home page GithubHelp logo

victoriaroseb / jcolor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dialex/jcolor

0.0 0.0 0.0 2.94 MB

An easy syntax to format your strings with colored fonts and backgrounds.

License: MIT License

Java 100.00%

jcolor's Introduction

Travis build Maven Central Codacy Badge License Donate

JColor (formerly Java Colored Debug Printer) offers you an easy syntax to print messages with a colored font or background on a terminal.

Screenshots

JColor running on iTerm (macOS)

How it looks on different platforms: macOS iTerm (above), Windows 10 PowerShell 6, Windows 10 Console, IntelliJ

Usage

The screenshot was the result of running this demo code:

// Use Case 1: use Ansi.colorize() to format inline
System.out.println(colorize("This text will be yellow on magenta", YELLOW_TEXT(), MAGENTA_BACK()));
System.out.println("\n");

// Use Case 2: compose Attributes to create your desired format
Attribute[] myFormat = new Attribute[]{RED_TEXT(), YELLOW_BACK(), BOLD()};
System.out.println(colorize("This text will be red on yellow", myFormat));
System.out.println("\n");

// Use Case 3: AnsiFormat is syntactic sugar for an array of Attributes
AnsiFormat fWarning = new AnsiFormat(GREEN_TEXT(), BLUE_BACK(), BOLD());
System.out.println(colorize("AnsiFormat is just a pretty way to declare formats", fWarning));
System.out.println(fWarning.format("...and use those formats without calling colorize() directly"));
System.out.println("\n");

// Use Case 4: you can define your formats and use them throughout your code
AnsiFormat fInfo = new AnsiFormat(CYAN_TEXT());
AnsiFormat fError = new AnsiFormat(YELLOW_TEXT(), RED_BACK());
System.out.println(fInfo.format("This info message will be cyan"));
System.out.println("This normal message will not be formatted");
System.out.println(fError.format("This error message will be yellow on red"));
System.out.println("\n");

// Use Case 5: we support bright colors
AnsiFormat fNormal = new AnsiFormat(MAGENTA_BACK(), YELLOW_TEXT());
AnsiFormat fBright = new AnsiFormat(BRIGHT_MAGENTA_BACK(), BRIGHT_YELLOW_TEXT());
System.out.println(fNormal.format("You can use normal colors ") + fBright.format(" and bright colors too"));

// Use Case 6: we support 8-bit colors
System.out.println("Any 8-bit color (0-255), as long as your terminal supports it:");
for (int i = 0; i <= 255; i++) {
    Attribute txtColor = TEXT_COLOR(i);
    System.out.print(colorize(String.format("%4d", i), txtColor));
}
System.out.println("\n");

// Use Case 7: we support true colors (RGB)
System.out.println("Any TrueColor (RGB), as long as your terminal supports it:");
for (int i = 0; i <= 300; i++) {
    Attribute bkgColor = BACK_COLOR(randomInt(255), randomInt(255), randomInt(255));
    System.out.print(colorize("   ", bkgColor));
}
System.out.println("\n");

// Credits
System.out.print("This example used JColor 5.0.0   ");
System.out.print(colorize("\tMADE ", BOLD(), BRIGHT_YELLOW_TEXT(), GREEN_BACK()));
System.out.println(colorize("IN PORTUGAL\t", BOLD(), BRIGHT_YELLOW_TEXT(), RED_BACK()));
System.out.println("I hope you find it useful ;)");

Installation

You can import this dependency through Maven or Gradle:

  • JColor v5.* supports Java +8, Linux, macOS, Windows 10
  • JCDP v4.* supports Java +8, Linux, macOS, Windows 10
  • JCDP v3.* supports Java +8, Linux, macOS, Windows
  • JCDP v2.* supports Java +6, Linux, macOS, Windows

Useful links

License

JColor, former JCDP Copyright (C) 2011-* Diogo Nunes This program is licensed under the terms of the MIT License and it comes with ABSOLUTELY NO WARRANTY. For more details check LICENSE.

Credits

A big thanks to all contributors, namely @xafero who maven-ized this project.

jcolor's People

Contributors

dialex avatar xafero avatar codedojoofficial avatar flawedspirit avatar extollite avatar

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.