Skip to content

Commit

Permalink
Support piped stdin for graphviz
Browse files Browse the repository at this point in the history
  • Loading branch information
togatoga committed Jun 23, 2024
1 parent ff44598 commit 63987d6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/bin/kanpyo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum SubCommand {
Graphviz {
/// Input text to analyze
#[arg(index = 1)]
input: String,
input: Option<String>,
/// Dictionary
#[arg(short, long, value_enum, default_value = "ipa")]
dict: Dict,
Expand Down Expand Up @@ -96,12 +96,23 @@ impl KanpyoCommand {
}
}
fn graphviz(
input: String,
input: Option<String>,
dict: Dict,
custom_dict: Option<PathBuf>,
dpi: usize,
full_state: bool,
) {
let input = match input {
Some(text) => text,
None => {
let mut buf = String::new();
std::io::stdin()
.read_line(&mut buf)
.expect("failed to read from stdin");
buf
}
};

let tokenzier = KanpyoCommand::tokenizer(dict, custom_dict);
let lattice = kanpyo::lattice::Lattice::build(&tokenzier.dict, &input);
kanpyo::graphviz::Graphviz { lattice }.graphviz(dpi, full_state);
Expand Down

0 comments on commit 63987d6

Please sign in to comment.