Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): make it possible to use as a lib #2

Merged
merged 1 commit into from
Dec 29, 2023
Merged
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
99 changes: 56 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ratatui = "0.25.0"
crossterm = "0.27.0"
colors-transform = "0.2.11"
ratatui = { version = "0.25.0", optional = true }
crossterm = { version = "0.27.0", optional = true }
clipboard = "0.5.0"

[[bin]]
# necessary to avoid including crossterm / ratatui in the lib
name = "material"
required-features = ["cli"]

[features]
cli = ["ratatui", "crossterm"]
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Material

A material design color palette for the terminal

<img src="https://i.ibb.co/2MDKmh7/Screenshot-2022-08-02-at-16-43-12.png" alt="drawing" width="400"/>
Expand All @@ -17,12 +18,41 @@ brew install material
First, install [Rust](https://www.rust-lang.org/tools/install) (using the recommended `rustup` installation method) and then

```bash
cargo install material
cargo install material --locked --features=cli
```

## Usage

Run the command ``material`` in the terminal.
Type the color code to copy its hex color to the clipboard. Type Esc to exit.

## As a library

This crate can also be used as a library in your own apps.

```bash
cargo add material
```

```rust
use material_colors::colors;

assert_eq!(colors::RED_50.to_string(), "#ffebee");
assert_eq!(colors::RED_100.to_string(), "#ffcdd2");
```

### From Ratatui

Colors provided by the library can be converted to [Ratatui](https://ratatui.rs) colors. Just
enable the `ratatui` feature.

```bash
cargo add material --features=ratatui
```

```rust
use material_colors::colors;
use ratatui::prelude::*;

let line = Line::styled("hello world", Style::new().fg(colors::RED_50.into()));
```
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl App {
color.iter().for_each(|color_variant| {
if color_variant.0.to_lowercase() == self.input.to_lowercase() {
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
ctx.set_contents(color_variant.1.to_owned()).unwrap();
ctx.set_contents(color_variant.1.to_string()).unwrap();
self.message = format!("{} copied to clipboard!", color_variant.1);
}
})
Expand Down
Loading