Skip to content

Commit

Permalink
chore: embed assets on debug & update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
latipun7 committed Mar 4, 2023
1 parent 2e4b590 commit 05be26a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 91 deletions.
72 changes: 1 addition & 71 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "charasay"
version = "1.0.0"
version = "1.0.1"
authors = ["Latif Sulistyo <[email protected]>"]
edition = "2021"
description = "The future of cowsay 🐮! Colorful characters saying something 🗨️."
repository = "https://github.com/latipun7/charasay"
license = "MIT"
readme = "readme.md"
keywords = ["cowsay", "print", "ansi"]
categories = [
"command-line-utilities",
Expand All @@ -21,7 +22,7 @@ name = "chara"
[dependencies]
clap = { version = "4.1.8", features = ["derive"] }
clap_complete = "4.1.4"
rust-embed = { version = "6.4.2", features = ["interpolate-folder-path"] }
rust-embed = { version = "6.4.2", features = ["debug-embed"] }
textwrap = { version = "0.16.0", features = ["terminal_size"] }
unicode-width = "0.1.10"
regex = "1.7.1"
Expand Down
28 changes: 24 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,30 @@ while this make us all happy 😁.

## Installation

### AUR

For Arch Linux, package available via AUR. Example install this with AUR helper:

```console
yay -S charasay
```

### Cargo

If you have `rustup` or `cargo`, this tool available on crates.io. Install this with:

```console
cargo install charasay
```

### Manual

Just donwload from the [release page](https://github.com/latipun7/charasay/releases)
for your compatible Operating System, then extract the zip archive, give permission
to execute on extracted file, then place it on your `PATH`.

Alternatively, clone this repository, then build this with `cargo build --release`.

### Prerequisites

To display characters, your terminal needs to support true color (24-bit color).
Expand Down Expand Up @@ -65,8 +85,8 @@ on how to add completions.

For updated usage please consult to help command.

```sh
chara --help # example output
```console
$ chara --help
The future of cowsay 🐮! Colorful characters saying something 🗨️.

Usage: chara <COMMAND>
Expand All @@ -82,8 +102,8 @@ Options:
-V, --version Print version
```

```sh
chara help say # example output
```console
$ chara help say
Make the character say something

Usage: chara say [OPTIONS] [MESSAGE]...
Expand Down
30 changes: 18 additions & 12 deletions src/bin/chara.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::io::{stdin, stdout, Read};
use std::{
io::{stdin, stdout, Read},
path::PathBuf,
};

use charasay::{format_character, list_chara};
use clap::{Command, CommandFactory, Parser, Subcommand};
Expand All @@ -7,17 +10,17 @@ use rand::seq::SliceRandom;
use textwrap::termwidth;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
#[command(author, version, about, long_about, name = "chara")]
struct Cli {
#[command(subcommand)]
subcommands: Subcommands,
command: Commands,
}

#[derive(Subcommand, Debug)]
enum Subcommands {
enum Commands {
/// Make the character say something.
Say {
/// Messages that chara want to say/think. If empty, read from STDIN.
/// Messages that chara want to say/think. If empty, read from standard input.
message: Vec<String>,

/// Choose random chara.
Expand All @@ -36,7 +39,7 @@ enum Subcommands {
#[arg(short, long)]
width: Option<usize>,

/// Which chara should say/think
/// Which chara should say/think.
#[arg(short = 'f', long = "file")]
chara: Option<String>,
},
Expand All @@ -49,19 +52,22 @@ enum Subcommands {
},

/// TODO: Convert pixel-arts PNG to chara files.
Convert,
Convert {
/// PNG file path.
image: PathBuf,
},
}

fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
generate(gen, cmd, "chara".to_string(), &mut stdout());
generate(gen, cmd, cmd.get_name().to_string(), &mut stdout());
}

fn main() {
let cli = Cli::parse();

// Run subcommands if match
match cli.subcommands {
Subcommands::Say {
match cli.command {
Commands::Say {
message,
random,
all,
Expand Down Expand Up @@ -110,7 +116,7 @@ fn main() {
}
}

Subcommands::Completions { shell } => {
Commands::Completions { shell } => {
let mut cmd = Cli::command();
let gen = match shell {
Some(s) => s,
Expand All @@ -120,6 +126,6 @@ fn main() {
print_completions(gen, &mut cmd);
}

Subcommands::Convert => {}
Commands::Convert { image: _ } => {}
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use textwrap::fill;
use unicode_width::UnicodeWidthStr;

#[derive(RustEmbed, Debug)]
#[folder = "$CARGO_MANIFEST_DIR/src/charas"]
#[folder = "src/charas"]
struct Asset;

struct SpeechBubble {
Expand Down Expand Up @@ -206,5 +206,5 @@ pub fn format_character(messages: &str, chara: &String, max_width: usize, think:
pub fn list_chara() -> Vec<String> {
Asset::iter()
.map(|file| file.as_ref().replace(".chara", ""))
.collect::<Vec<String>>()
.collect()
}

0 comments on commit 05be26a

Please sign in to comment.