Skip to content

Commit

Permalink
feat: add support for reading from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
max-niederman committed May 2, 2023
1 parent 0bc5807 commit c7b7717
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,20 @@ impl Opt {
fn gen_contents(&self) -> Option<Vec<String>> {
match &self.contents {
Some(path) => {
let file = fs::File::open(path).expect("Error reading language file.");
let lines: Vec<String> = io::BufReader::new(file)
.lines()
.filter_map(Result::ok)
.collect();
let lines: Vec<String> = if path.as_os_str() == "-" {
std::io::stdin()
.lock()
.lines()
.filter_map(Result::ok)
.collect()
} else {
let file = fs::File::open(path).expect("Error reading language file.");
io::BufReader::new(file)
.lines()
.filter_map(Result::ok)
.collect()
};

Some(lines.iter().map(String::from).collect())
}
None => {
Expand Down Expand Up @@ -169,8 +178,11 @@ impl State {

fn main() -> crossterm::Result<()> {
let opt = Opt::from_args();
let config = opt.config();
if opt.debug {
dbg!(&opt);
}

let config = opt.config();
if opt.debug {
dbg!(&config);
}
Expand Down

0 comments on commit c7b7717

Please sign in to comment.