#color #background-color #output #console #print #console-log #log

ltpp-output

An atomic output library based on Rust that supports output functionalities through functions, builders, and other methods. It allows customization of text and background colors.

13 stable releases (3 major)

3.0.0 Nov 29, 2024
2.0.0 Nov 29, 2024
1.1.1 Oct 27, 2024
0.4.0 Oct 21, 2024
0.1.3 Oct 20, 2024

#252 in Rust patterns

Download history 999/week @ 2024-10-18 427/week @ 2024-10-25 60/week @ 2024-11-01 9/week @ 2024-11-08 3/week @ 2024-11-15 1/week @ 2024-11-22 224/week @ 2024-11-29 159/week @ 2024-12-06

387 downloads per month

MIT license

69KB
1K SLoC

LTPP-RUST-OUTPUT

Official Documentation

Description

  • An atomic output library based on Rust that supports output functionalities through functions, builders, and other methods. It allows customization of text and background colors.

Features

  • Supports formatted output of the current time.
  • Allows customization of text color, background color, font weight, and other configurations.
  • Supports defining structures for output messages.
  • Supports defining builders for output messages.
  • Supports single-line output for multiple tasks.
  • Supports multi-line output for multiple tasks.
  • Ensures atomic output operations.

Installation

To install ltpp-output run cmd:

cargo add ltpp-output

Code Examples

Struct Output

Using output Function

use ltpp_output::*;
output(Output {
    text: "test_output_struct",
    text_color: ColorType::Use(Color::Default),
    text_bg_color: ColorType::Color256(0x000000),
    show_time: true,
    time_text_color: ColorType::Rgb(255, 255, 255),
    time_bg_color: ColorType::Use(Color::Yellow),
    split: " => ",
    split_color: ColorType::Use(Color::Cyan),
    split_bg_color: ColorType::Use(Color::Yellow),
    endl: true,
    ..Default::default()
});

Using output Method

use ltpp_output::*;
Output {
    text: "test_output_struct_output",
    text_color: ColorType::Use(Color::Default),
    text_bg_color: ColorType::Use(Color::Blue),
    show_time: true,
    time_text_color: ColorType::Rgb(255, 255, 255),
    time_bg_color: ColorType::Use(Color::Yellow),
    split: " => ",
    split_color: ColorType::Use(Color::Cyan),
    split_bg_color: ColorType::Use(Color::Yellow),
    endl: true,
    ..Default::default()
}
.output();

Array of Structs

use ltpp_output::*;
OutputList(vec![
    Output {
        text: "test_output_list_struct_1",
        text_color: ColorType::Use(Color::Default),
        text_bg_color: ColorType::Color256(0x000000),
        show_time: true,
        time_text_color: ColorType::Rgb(255, 255, 255),
        time_bg_color: ColorType::Use(Color::Yellow),
        split: " => ",
        split_color: ColorType::Use(Color::Cyan),
        split_bg_color: ColorType::Use(Color::Yellow),
        endl: false,
        ..Default::default()
    },
    Output {
        text: "test_output_struct_output_2",
        text_color: ColorType::Use(Color::Default),
        text_bg_color: ColorType::Use(Color::Blue),
        show_time: true,
        time_text_color: ColorType::Rgb(255, 255, 255),
        time_bg_color: ColorType::Use(Color::Yellow),
        split: " => ",
        split_color: ColorType::Use(Color::Cyan),
        split_bg_color: ColorType::Use(Color::Yellow),
        endl: true,
        ..Default::default()
    },
])
.output();

Builder Output

Using output Function

use ltpp_output::*;
output(
    OutputBuilder::new_from(Output::default())
        .set_text("test_output_builder")
        .set_text_color(ColorType::Color256(0xffffff))
        .set_text_bg_color(ColorType::Color256(0xffffff))
        .set_split_bg_color(ColorType::Color256(0xffffff))
        .set_time_text_color(ColorType::Rgb(255, 200, 255))
        .set_text_blod(true)
        .set_time_text_blod(true)
        .set_show_time(true)
        .set_endl(true)
        .build(),
);

Using output Method

use ltpp_output::*;
OutputBuilder::new()
    .set_text("test_output_builder_output")
    .set_text_bg_color(ColorType::Color256(0xffffff))
    .set_text_color(ColorType::Color256(0xffffff))
    .set_time_text_color(ColorType::Rgb(255, 200, 255))
    .set_text_blod(true)
    .set_time_text_blod(true)
    .set_show_time(true)
    .set_endl(true)
    .build()
    .output();

Array Builder

use ltpp_output::*;
OutputListBuilder::new_from(vec![Output::default()])
    .add(
        OutputBuilder::new()
            .set_text("text")
            .set_text_bg_color(ColorType::Use(Color::Blue))
            .set_endl(false)
            .build(),
    )
    .add(Output {
        text: "test_new_from_output_list_builder_1",
        text_color: ColorType::Use(Color::Default),
        text_bg_color: ColorType::Color256(0x3f3f3f),
        split: " => ",
        split_color: ColorType::Use(Color::Cyan),
        split_bg_color: ColorType::Use(Color::Yellow),
        endl: false,
        ..Default::default()
    })
    .add(Output {
        text: "test_new_from_output_list_builder_2",
        text_color: ColorType::Use(Color::Default),
        text_bg_color: ColorType::Use(Color::Cyan),
        split: " => ",
        split_color: ColorType::Use(Color::Cyan),
        split_bg_color: ColorType::Use(Color::Yellow),
        endl: true,
        ..Default::default()
    })
    .run();

Output Macros

Passing Struct

use ltpp_output::*;
output_macro!(Output {
    text: "test_proc_macro",
    text_color: ColorType::default(),
    text_bg_color: ColorType::Use(Color::Yellow),
    show_time: true,
    time_text_color: ColorType::Use(Color::Green),
    time_bg_color: ColorType::Color256(0xffffff),
    split: " => ",
    split_color: ColorType::Use(Color::Cyan),
    split_bg_color: ColorType::Use(Color::Yellow),
    endl: true,
    ..Default::default()
});

Passing Builder

use ltpp_output::*;
output_macro!(OutputBuilder::new()
    .set_text("test_output_builder")
    .set_text_color(ColorType::Use(Color::Cyan))
    .set_time_text_color(ColorType::Use(Color::Blue))
    .set_text_blod(true)
    .set_time_text_blod(true)
    .set_show_time(true)
    .set_endl(true)
    .build());

Multiple Inputs

use ltpp_output::*;
output_macro!(
    Output {
        text: "test_proc_macro",
        text_color: ColorType::default(),
        text_bg_color: ColorType::Use(Color::Yellow),
        show_time: true,
        time_text_color: ColorType::Use(Color::Green),
        time_bg_color: ColorType::Color256(0xffffff),
        split: " => ",
        split_color: ColorType::Use(Color::Cyan),
        split_bg_color: ColorType::Use(Color::Yellow),
        endl: true,
        ..Default::default()
    },
    OutputBuilder::new()
        .set_text("test_output_builder1")
        .set_text_color(ColorType::Color256(0xffffff))
        .set_time_text_color(ColorType::Rgb(255, 200, 255))
        .set_text_blod(true)
        .set_time_text_blod(true)
        .set_show_time(true)
        .set_endl(true)
        .build(),
    OutputBuilder::new()
        .set_text("test_output_builder2")
        .set_text_color(ColorType::Color256(0xffffff))
        .set_time_text_color(ColorType::Rgb(255, 200, 255))
        .set_text_blod(true)
        .set_time_text_blod(true)
        .set_show_time(true)
        .set_endl(true)
        .build()
);

Color Usage

  • ColorType::Use: Use built-in colors.
  • ColorType::Color256: Hexadecimal colors.
  • ColorType::Rgb: RGB color (r, g, b).

ColorType::Use

ColorType::Use(Color::White)

ColorType::Color256

ColorType::Color256(0xffffff)

ColorType::Rgb

ColorType::Rgb(255, 255, 255)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Contact

For any inquiries, please reach out to the author at ltpp-universe root@ltpp.vip.

No runtime deps