Style terminal outputs in a minimal, macro-based, and dead simple way.

Related tags

Command-line sty
Overview

sty 🌈

Crates.io docs-rs Downloads

$\mathbb{\color{red}{Style \ } \color{lightblue}{terminal}\ \color{black}{outputs \ }\color{gray}{\ in\ a} \color{magenta}{\ minimal}\color{gray}{,} \color{lightyellow}{\ macro\ based}\color{gray}{,}\ and \color{lightgreen}{\ dead\ simple} \color{gray}{\ way.}}$

Code Backgroud Bright Bright background
$\mathbb{\color{black}{â– }}$ black bg_black
$\mathbb{\color{gray}{â– }}$ gray bg_gray
$\mathbb{\color{white}{â– }}$ white bg_white white_bright bg_white_bright
$\mathbb{\color{red}{â– }}$ red bg_red red_bright bg_red_bright
$\mathbb{\color{green}{â– }}$ green bg_green green_bright bg_green_bright
$\mathbb{\color{yellow}{â– }}$ yellow bg_yellow yello_bright bg_yellow_bright
$\mathbb{\color{blue}{â– }}$ blue bg_blue blue_bright bg_blue_bright
$\mathbb{\color{magenta}{â– }}$ magenta bg_magenta magenta_bright bg_magenta_bright
$\mathbb{\color{cyan}{â– }}$ cyan bg_cyan cyan_bright bg_cyan_bright

bold italic underline strikethrough overline dim inverse hidden reset

Highlights

  • Macro-based: Increases compile-time efficiency and boosts safety.
  • Innovative Styling: Compose styles in an array-like format such as [red, bold, underline].
  • Extensive Type Support: All types implementing std::fmt::Display trait are supported, offering wide-ranging adaptability.
  • Full Color and Style support: Modifiers / Foreground colors / Background colors / Bright foreground colors / Bright background colors.
  • Zero dependencies: Cleaner code-base with no third-party interference.
  • Supports tty detection: Avoids styling when the tty lacks color support, Use set_color_enabled for manual enable control.

Documentation

docs-rs

Installation

This crate works with Cargo. Add the following to your Cargo.toml dependencies section:

[dependencies]
sty = "0.3"

Basic usage

use sty::{
    sty,
    style::{red, underline},
};
// or
// use sty::{ sty, red, underline };

println!("{}", sty!("Hello world!", [red]));

// Use `sty!` macro for combination of multiple styles
println!("{}", sty!("Hello world!", [red, underline]));

// Use `sty!` macro for multiple input types
println!("{}", sty!(123, [red, underline]));

// Use style function is simple for `&str` input
println!("{}", red("Hello world!"));
println!("{}", underline(&red("Hello world!")));

Tip

In style combinations, the styles that are specified later take precedence, For example:

use sty::{ sty, style::* };
sty!("str", [red, green, blue]); // blue
sty!("str", [red, underline, reset]); // reset

Tip

If tty environment does not support color, default output will be printed without any styling, Use set_color_enabled for manual enable control, For example:

use sty::{ set_color_enabled, is_color_enabled, sty, style::* };
let enabled = is_color_enabled();
set_color_enabled(false);
sty!("123", [red]); // no color
set_color_enabled(true);
sty!("123", [red]); // red
set_color_enabled(enabled);

sty! Macro

The sty! macro is a powerful utility conveniently used to apply a collection of style manipulations to your input. This macro allows you to seamlessly incorporate text properties with an intuitive syntax.

use sty::{ sty, style::{red, underline} };
println!("{}", sty!("Hello world!", [red, underline]));

In this example, red and underline are both style transformations, and the sty! macro returns a newly styled text instance with all these styling elements applied. Multiple styles can be applied simultaneously, and the output will be a combination of all.

Supported input types

For any type that has implemented the std::fmt::Display trait, like:

  • &str
  • String
  • numbers(usize, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64)
  • bool
  • ...

Style function

Each style function can be combine with sty! macro or used separately, for example:

use sty::{
    sty,
    style::{red, underline},
};
// or
// use sty::{ sty, red, underline };

sty!("Hello world!", [red, underline]);
// or
red("Hello world!");

Tip

The standalone style function only supports &str input type.

All style functions are as follows:

  • Modifiers

    • reset
    • bold
    • dim
    • italic
    • underline
    • overline
    • inverse
    • hidden
    • strikethrough
  • Foreground colors

    • black
    • red
    • green
    • yellow
    • blue
    • magenta
    • cyan
    • white
    • gray
  • Background colors

    • bg_black
    • bg_red
    • bg_green
    • bg_yellow
    • bg_blue
    • bg_magenta
    • bg_cyan
    • bg_white
    • bg_gray
  • Bright foreground colors

    • red_bright
    • green_bright
    • yellow_bright
    • blue_bright
    • magenta_bright
    • cyan_bright
    • white_bright
  • Bright background colors

    • bg_red_bright
    • bg_green_bright
    • bg_yellow_bright
    • bg_blue_bright
    • bg_magenta_bright
    • bg_cyan_bright
    • bg_white_bright

Contribution

CONTRIBUTING

You might also like...
A simple and efficient terminal UI implementation with ratatui.rs for getting quick insights from csv files right on the terminal
A simple and efficient terminal UI implementation with ratatui.rs for getting quick insights from csv files right on the terminal

CSV-GREP csv-grep is an intuitive TUI application writting with ratatui.rs for reading, viewing and quickly analysing csv files right on the terminal.

ChatGPT CLI - A minimal assistant in the terminal
ChatGPT CLI - A minimal assistant in the terminal

ChatGPT CLI A lightweight ChatGPT CLI - Chat completion. Interact with ChatGPT from your terminal and save the conversation in a text file. Get starte

Semantic find-and-replace using tree-sitter-based macro expansion

Semantic find-and-replace using tree-sitter-based macro expansion

Simple, safe way to store and distribute tensors

Safetensors Ruby 🙂 Simple, safe way to store and distribute tensors Supports Torch.rb and Numo Installation Add this line to your application’s Gemfi

A user-friendly TUI for secure file transfers, with arrow-key and VIM-style navigation
A user-friendly TUI for secure file transfers, with arrow-key and VIM-style navigation

gsftp SFTP with an interactive text-based user interface (TUI). Transfer files through an encrypted connection with a visual interface, so you can see

Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.

Sleek: SQL Formatter ✨ Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability an

Command-line tool that provides a workflow for extending, editing, diffing, and writing to vim-style grep lines.

Grug Grug is a command-line tool that provides a workflow for expanding, editing, diffing, and writing edits to files using vim-styled grep lines (suc

Simple macros to write colored and formatted text to a terminal. Based on `termcolor`, thus also cross-platform.
Simple macros to write colored and formatted text to a terminal. Based on `termcolor`, thus also cross-platform.

Bunt: simple macro-based terminal colors and styles bunt offers macros to easily print colored and formatted text to a terminal. It is just a convenie

A simple, opinionated way to run containers for tests in your Rust project.

rustainers rustainers is a simple, opinionated way to run containers for tests. TLDR More information about this crate can be found in the crate docum

Owner
斯人
Make it work, make it right, make it fast.
斯人
A dead simple ANSI terminal color painting library for Rust.

yansi A dead simple ANSI terminal color painting library for Rust. use yansi::Paint; print!("{} light, {} light!", Paint::green("Green"), Paint::red(

Sergio Benitez 169 Dec 25, 2022
Simple terminal file manager(vi-style keybindings) written in rust

rust-tfm rust-tfm is a terminal file manager written in rust heavily inspired by lf and ranger, and also inspired by suckless software. rust-tfm.mp4 F

Jiao ShiJie 9 Sep 26, 2023
Outputs a random number of 🌈's

Rainbows Outputs a random number of ?? 's. Rust implementation of rainbows. ?? Installation Install Rust and Cargo Run cargo install rainbows $ rainbo

Junho Yeo 6 Oct 8, 2021
create and test the style and formatting of text in your terminal applications

description: create and test the style and formatting of text in your terminal applications docs: https://docs.rs/termstyle termstyle is a library tha

Rett Berg 18 Jul 3, 2021
A dead simple functional testing tool for command line applications

Pharaoh : build that test pyramid! What it is Pharaoh is a dead simple, no permission needed, functional test runner for command line applications, wr

Kevin Sztern 17 Dec 13, 2021
A Turing-complete but dead-simple spaced repetition CLI that helps you learn stuff.

Forne — Learn Stuff Forne is a Turing-complete spaced repetition engine to help you learn stuff your way. What does that mean? Well, there are a few p

Sam Brew 9 May 12, 2023
Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.

cargo-hoist Dead simple cargo subcommand to hoist cargo-built binaries into scope. stable Install | User Docs | Crate Docs | Reference | Contributing

refcell.eth 6 Nov 9, 2023
Rust no-BS Dead Man's Switch TUI

Dead Man's Switch This is a simple implementation of a Dead Man's Switch. Use at your own risk. Check the f****(as in friendly) code. Dead man's switc

Jose Storopoli 7 Apr 25, 2024
The-way - A code snippets manager for your terminal.

The Way A code snippets manager for your terminal. Record and retrieve snippets you use every day, or once in a blue moon, without having to spin up a

OutOfCheeseError 254 Jan 7, 2023
Terminal UI for erhanbaris/smartcalc, a new way to do calculations on-the-fly

smartcalc-tui Terminal UI for erhanbaris/smartcalc, a new way to do calculations on-the-fly. From the README: Do your calculation on text based querie

Aaron Ross 12 Sep 14, 2022