Skip to content

Commit 1ea1b89

Browse files
authored
Merge pull request #8 from hitenkoku/update-crates
replaced atty with isTerminal
2 parents 459044c + ed68652 commit 1ea1b89

File tree

4 files changed

+15
-39
lines changed

4 files changed

+15
-39
lines changed

Cargo.lock

+3-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ path = "src/bin.rs"
2323

2424
[dependencies]
2525
anyhow = "1.0"
26-
atty = "0.2"
2726
chrono = { version = "0.4.24", default-features = false, features = ["clock"] }
2827
clap = "4.0"
2928
file-chunker = "0.1.1"
30-
memmap2 = "0.6.1"
29+
memmap2 = "0.7.1"
3130
num_cpus = "1.13"
3231
rayon = "1.5"
3332
regex = "1.4.2"

src/bin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{anyhow, Result};
22
use clap::{Arg, Command};
33
use rayon::prelude::*;
4-
use std::fs;
4+
use std::{fs, io::IsTerminal};
55
use terminal_size::{terminal_size, Width};
66

77
use file_chunker::FileChunker;
@@ -66,11 +66,11 @@ fn main() -> Result<()> {
6666
let timestamp_format: &String = arg_matches.get_one::<String>("FORMAT").unwrap();
6767
let timestamps = match arg_matches.get_one::<String>("FILE") {
6868
None => {
69-
if atty::is(atty::Stream::Stdin) {
69+
if std::io::stdin().is_terminal() {
7070
eprintln!("Reading from standard input. Paste your log and then send EOF (e.g. by pressing ctrl-D).");
7171
}
7272

73-
krapslog::scan_for_timestamps(std::io::stdin(), &timestamp_format)
73+
krapslog::scan_for_timestamps(std::io::stdin(), timestamp_format)
7474
}
7575
Some(filename) => {
7676
let file = fs::File::open(filename)?;
@@ -83,7 +83,7 @@ fn main() -> Result<()> {
8383
Ok(chunker
8484
.chunks(count, Some('\n'))?
8585
.into_par_iter()
86-
.map(|chunk| krapslog::scan_for_timestamps(chunk, &timestamp_format))
86+
.map(|chunk| krapslog::scan_for_timestamps(chunk, timestamp_format))
8787
.filter_map(Result::ok)
8888
.collect::<Vec<Vec<i64>>>()
8989
.concat())

src/lib.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ where
5454
let date_finder = TimestampFinder::new(format)?;
5555
let timestamps = BufReader::new(reader)
5656
.lines()
57-
.filter_map(Result::ok)
57+
.map_while(Result::ok)
5858
.filter_map(|line| date_finder.find_timestamp(&line))
5959
.collect();
6060
Ok(timestamps)
@@ -99,10 +99,9 @@ pub fn build_time_markers(
9999
vertical_offset: index + 1,
100100
})
101101
.for_each(|time_marker| {
102-
match time_marker.render(&mut header_canvas) {
103-
Err(e) => eprintln!("couldn't render time marker: {}", e),
104-
_ => {}
105-
};
102+
if let Err(e) = time_marker.render(&mut header_canvas) {
103+
eprintln!("couldn't render time marker: {}", e);
104+
}
106105
});
107106

108107
footer_timestamp_offsets
@@ -115,10 +114,9 @@ pub fn build_time_markers(
115114
vertical_offset: footer_timestamp_offsets.len() - index,
116115
})
117116
.for_each(|time_marker| {
118-
match time_marker.render(&mut footer_canvas) {
119-
Err(e) => eprintln!("couldn't render time marker: {}", e),
120-
_ => {}
121-
};
117+
if let Err(e) = time_marker.render(&mut footer_canvas) {
118+
eprintln!("couldn't render time marker: {}", e);
119+
}
122120
});
123121

124122
(format!("{}", header_canvas), format!("{}", footer_canvas))

0 commit comments

Comments
 (0)