Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: msrv

on:
push:
branches: [master]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Sources
uses: actions/checkout@v3

- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.54.0
override: true

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --all --all-features --verbose
38 changes: 38 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: style

on:
push:
branches: [master]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
style:
runs-on: ubuntu-latest

steps:
- name: Checkout Sources
uses: actions/checkout@v3

- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- name: Check Code Format
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check

- name: Code Lint
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all --all-features --all-targets -- -D warnings
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: test

on:
push:
branches: [master]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
toolchain: [stable, beta, nightly]
runs-on: ${{ matrix.platform }}

steps:
- name: Checkout Sources
uses: actions/checkout@v3

- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --all --all-features --verbose
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "yansi"
version = "0.6.0-dev"
edition = "2018"
authors = ["Sergio Benitez <sb@sergio.bz>"]
repository = "https://github.com/SergioBenitez/yansi"
documentation = "https://docs.rs/yansi"
Expand All @@ -10,10 +11,7 @@ readme = "README.md"
license = "MIT/Apache-2.0"
categories = ["command-line-interface"]

[badges]
travis-ci = { repository = "SergioBenitez/yansi", branch = "master" }

[dependencies]

[dev-dependencies]
serial_test = "0.6"
serial_test = { version = "0.9", default-features = false }
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# yansi

[![Build Status](https://travis-ci.org/SergioBenitez/yansi.svg?branch=master)](https://travis-ci.org/SergioBenitez/yansi)
[![Build Status](https://github.com/SergioBenitez/yansi/workflows/test/badge.svg)](https://github.com/SergioBenitez/yansi/actions)
[![Current Crates.io Version](https://img.shields.io/crates/v/yansi.svg)](https://crates.io/crates/yansi)
[![Documentation](https://docs.rs/yansi/badge.svg)](https://docs.rs/yansi)
[![MSRV](https://img.shields.io/badge/rustc-1.54+-blue.svg)](https://blog.rust-lang.org/2021/07/29/Rust-1.54.0.html)

A dead simple ANSI terminal color painting library for Rust.

Expand Down
4 changes: 2 additions & 2 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt;

use {Paint, Style};
use crate::{Paint, Style};

/// An enum representing an ANSI color code.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Copy, Clone)]
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Color {
Style::new(self)
}

pub(crate) fn ansi_fmt(&self, f: &mut fmt::Write) -> fmt::Result {
pub(crate) fn ansi_fmt(&self, f: &mut dyn fmt::Write) -> fmt::Result {
match *self {
Color::Unset => Ok(()),
Color::Default => write!(f, "9"),
Expand Down
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,16 @@
//! [_masked_]: #masking
//! [_wrap_]: #wrapping

#[macro_use] mod macros;
#[macro_use]
mod macros;

#[cfg(test)] mod tests;
mod windows;
mod color;
mod paint;
mod style;
mod color;
#[cfg(test)]
mod tests;
mod windows;

pub use color::Color;
pub use style::Style;
pub use paint::Paint;
pub use crate::color::Color;
pub use crate::paint::Paint;
pub use crate::style::Style;
44 changes: 32 additions & 12 deletions src/paint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

use style::{Style, Property};
use color::Color;
use crate::color::Color;
use crate::style::{Property, Style};

/// A structure encapsulating an item and styling.
///
Expand Down Expand Up @@ -112,7 +112,10 @@ impl<T> Paint<T> {
/// ```
#[inline]
pub fn new(item: T) -> Paint<T> {
Paint { item, style: Style::default() }
Paint {
item,
style: Style::default(),
}
}

/// Constructs a new `Paint` structure encapsulating `item` with the active
Expand Down Expand Up @@ -202,8 +205,17 @@ impl<T> Paint<T> {
Paint::new(item).fg(Color::Fixed(color))
}

constructors_for!(T, black: Black, red: Red, green: Green, yellow: Yellow,
blue: Blue, magenta: Magenta, cyan: Cyan, white: White);
constructors_for!(
T,
black: Black,
red: Red,
green: Green,
yellow: Yellow,
blue: Blue,
magenta: Magenta,
cyan: Cyan,
white: White
);

/// Retrieves the style currently set on `self`.
///
Expand Down Expand Up @@ -332,14 +344,22 @@ impl<T> Paint<T> {
self
}

style_builder_for!(Paint<T>, |paint| paint.style.properties,
bold: BOLD, dimmed: DIMMED, italic: ITALIC,
underline: UNDERLINE, blink: BLINK, invert: INVERT,
hidden: HIDDEN, strikethrough: STRIKETHROUGH);
style_builder_for!(
Paint<T>,
|paint| paint.style.properties,
bold: BOLD,
dimmed: DIMMED,
italic: ITALIC,
underline: UNDERLINE,
blink: BLINK,
invert: INVERT,
hidden: HIDDEN,
strikethrough: STRIKETHROUGH
);
}

macro_rules! impl_fmt_trait {
($trait:ident, $fmt:expr) => (
($trait:ident, $fmt:expr) => {
impl<T: fmt::$trait> fmt::$trait for Paint<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if Paint::is_enabled() && self.style.wrap {
Expand All @@ -362,7 +382,7 @@ macro_rules! impl_fmt_trait {
}
}
}
)
};
}

impl_fmt_trait!(Display, "{}");
Expand Down Expand Up @@ -458,6 +478,6 @@ impl Paint<()> {
/// ```
#[inline]
pub fn enable_windows_ansi() -> bool {
::windows::enable_ansi_colors()
crate::windows::enable_ansi_colors()
}
}
46 changes: 31 additions & 15 deletions src/style.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::hash::{Hash, Hasher};
use std::fmt::{self, Display};
use std::hash::{Hash, Hasher};
use std::ops::BitOr;

use {Paint, Color};
use crate::{Color, Paint};

#[derive(Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Copy, Clone)]
pub struct Property(u8);
Expand All @@ -29,7 +29,10 @@ impl Property {

#[inline(always)]
pub fn iter(self) -> Iter {
Iter { index: 0, properties: self }
Iter {
index: 0,
properties: self,
}
}
}

Expand Down Expand Up @@ -181,7 +184,7 @@ macro_rules! checker_for {
}

#[inline]
fn write_spliced<T: Display>(c: &mut bool, f: &mut fmt::Write, t: T) -> fmt::Result {
fn write_spliced<T: Display>(c: &mut bool, f: &mut dyn fmt::Write, t: T) -> fmt::Result {
if *c {
write!(f, ";{}", t)
} else {
Expand Down Expand Up @@ -280,10 +283,18 @@ impl Style {
self
}

style_builder_for!(Style, |style| style.properties,
bold: BOLD, dimmed: DIMMED, italic: ITALIC,
underline: UNDERLINE, blink: BLINK, invert: INVERT,
hidden: HIDDEN, strikethrough: STRIKETHROUGH);
style_builder_for!(
Style,
|style| style.properties,
bold: BOLD,
dimmed: DIMMED,
italic: ITALIC,
underline: UNDERLINE,
blink: BLINK,
invert: INVERT,
hidden: HIDDEN,
strikethrough: STRIKETHROUGH
);

/// Constructs a new `Paint` structure that encapsulates `item` with the
/// style set to `self`.
Expand Down Expand Up @@ -363,11 +374,16 @@ impl Style {
self.wrap
}

checker_for!(bold (is_bold): BOLD, dimmed (is_dimmed): DIMMED,
italic (is_italic): ITALIC, underline (is_underline): UNDERLINE,
blink (is_blink): BLINK, invert (is_invert): INVERT,
hidden (is_hidden): HIDDEN,
strikethrough (is_strikethrough): STRIKETHROUGH);
checker_for!(
bold(is_bold): BOLD,
dimmed(is_dimmed): DIMMED,
italic(is_italic): ITALIC,
underline(is_underline): UNDERLINE,
blink(is_blink): BLINK,
invert(is_invert): INVERT,
hidden(is_hidden): HIDDEN,
strikethrough(is_strikethrough): STRIKETHROUGH
);

#[inline(always)]
fn is_plain(&self) -> bool {
Expand Down Expand Up @@ -408,7 +424,7 @@ impl Style {
/// }
/// }
/// ```
pub fn fmt_prefix(&self, f: &mut fmt::Write) -> fmt::Result {
pub fn fmt_prefix(&self, f: &mut dyn fmt::Write) -> fmt::Result {
// A user may just want a code-free string when no styles are applied.
if self.is_plain() {
return Ok(());
Expand Down Expand Up @@ -470,7 +486,7 @@ impl Style {
/// }
/// }
/// ```
pub fn fmt_suffix(&self, f: &mut fmt::Write) -> fmt::Result {
pub fn fmt_suffix(&self, f: &mut dyn fmt::Write) -> fmt::Result {
if self.is_plain() {
return Ok(());
}
Expand Down
Loading