Skip to content

Commit 62725ec

Browse files
authored
Merge pull request #3 from ynqa/v0.1.1/main
v0.1.1
2 parents 84be9a2 + 85989fb commit 62725ec

File tree

6 files changed

+49
-16
lines changed

6 files changed

+49
-16
lines changed

Cargo.lock

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

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sigrs"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["ynqa <un.pensiero.vano@gmail.com>"]
55
edition = "2021"
66
description = "Interactive grep (for streaming)"

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Interactive grep
2222
based on key inputs at any given moment.
2323
- Additionally, by starting in this mode,
2424
it is also possible to grep through static data such as files.
25+
- like [ugrep](https://github.com/Genivia/ugrep) with `-Q` option.
2526

2627
## Installation
2728

@@ -114,11 +115,13 @@ Options:
114115
--retrieval-timeout <RETRIEVAL_TIMEOUT_MILLIS>
115116
Timeout to read a next line from the stream in milliseconds. [default: 10]
116117
--render-interval <RENDER_INTERVAL_MILLIS>
117-
Interval to render a log line in milliseconds. [default: 10]
118+
Interval to render a line in milliseconds. [default: 10]
118119
-q, --queue-capacity <QUEUE_CAPACITY>
119-
Queue capacity to store the logs. [default: 1000]
120-
--archived
120+
Queue capacity to store lines. [default: 1000]
121+
-a, --archived
121122
Archived mode to grep through static data.
123+
-i, --ignore-case
124+
Case insensitive search.
122125
-h, --help
123126
Print help (see more with '--help')
124127
-V, --version

src/archived.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct Archived {
1919
text_editor_snapshot: Snapshot<text_editor::State>,
2020
lines: Snapshot<listbox::State>,
2121
highlight_style: ContentStyle,
22+
case_insensitive: bool,
2223
}
2324

2425
impl promkit::Finalizer for Archived {
@@ -63,7 +64,14 @@ impl promkit::Renderer for Archived {
6364
.listbox
6465
.items()
6566
.par_iter()
66-
.filter_map(|line| sig::styled(&query, &line.to_string(), self.highlight_style))
67+
.filter_map(|line| {
68+
sig::styled(
69+
&query,
70+
&line.to_string(),
71+
self.highlight_style,
72+
self.case_insensitive,
73+
)
74+
})
6775
.collect();
6876

6977
self.lines.after_mut().listbox = listbox::Listbox::from_iter(list);
@@ -76,13 +84,15 @@ pub fn run(
7684
text_editor: text_editor::State,
7785
lines: listbox::State,
7886
highlight_style: ContentStyle,
87+
case_insensitive: bool,
7988
) -> anyhow::Result<()> {
8089
Prompt {
8190
renderer: Archived {
8291
keymap: ActiveKeySwitcher::new("default", keymap::default),
8392
text_editor_snapshot: Snapshot::new(text_editor),
8493
lines: Snapshot::new(lines),
8594
highlight_style,
95+
case_insensitive,
8696
},
8797
}
8898
.run()

src/main.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,40 @@ pub struct Args {
3737
#[arg(
3838
long = "render-interval",
3939
default_value = "10",
40-
help = "Interval to render a log line in milliseconds.",
40+
help = "Interval to render a line in milliseconds.",
4141
long_help = "Adjust this value to prevent screen flickering
42-
when a large volume of logs is rendered in a short period."
42+
when a large volume of lines is rendered in a short period."
4343
)]
4444
pub render_interval_millis: u64,
4545

4646
#[arg(
4747
short = 'q',
4848
long = "queue-capacity",
4949
default_value = "1000",
50-
help = "Queue capacity to store the logs.",
51-
long_help = "Queue capacity for storing logs.
52-
This value is used for temporary storage of log data
50+
help = "Queue capacity to store lines.",
51+
long_help = "Queue capacity for storing lines.
52+
This value is used for temporary storage of lines
5353
and should be adjusted based on the system's memory capacity.
54-
Increasing this value allows for more logs to be stored temporarily,
55-
which can be beneficial when digging deeper into logs with the digger."
54+
Increasing this value allows for more lines to be stored temporarily,
55+
which can be beneficial when digging deeper into lines with the digger."
5656
)]
5757
pub queue_capacity: usize,
5858

5959
#[arg(
60+
short = 'a',
6061
long = "archived",
6162
default_value = "false",
6263
help = "Archived mode to grep through static data."
6364
)]
6465
pub archived: bool,
66+
67+
#[arg(
68+
short = 'i',
69+
long = "ignore-case",
70+
default_value = "false",
71+
help = "Case insensitive search."
72+
)]
73+
pub case_insensitive: bool,
6574
}
6675

6776
impl Drop for Args {
@@ -139,6 +148,7 @@ async fn main() -> anyhow::Result<()> {
139148
lines: Default::default(),
140149
},
141150
highlight_style,
151+
args.case_insensitive,
142152
)?;
143153
} else {
144154
let queue = sig::run(
@@ -158,6 +168,7 @@ async fn main() -> anyhow::Result<()> {
158168
Duration::from_millis(args.retrieval_timeout_millis),
159169
Duration::from_millis(args.render_interval_millis),
160170
args.queue_capacity,
171+
args.case_insensitive,
161172
)
162173
.await?;
163174

@@ -189,6 +200,7 @@ async fn main() -> anyhow::Result<()> {
189200
lines: Default::default(),
190201
},
191202
highlight_style,
203+
args.case_insensitive,
192204
)?;
193205
}
194206

src/sig.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ use promkit::{
2121
mod keymap;
2222
use crate::{stdin, terminal::Terminal};
2323

24-
fn matched(queries: &[&str], line: &str) -> anyhow::Result<Vec<Match>> {
24+
fn matched(queries: &[&str], line: &str, case_insensitive: bool) -> anyhow::Result<Vec<Match>> {
2525
let mut matched = Vec::new();
2626
RegexMatcherBuilder::new()
27+
.case_insensitive(case_insensitive)
2728
.build_many(queries)?
2829
.find_iter_at(line.as_bytes(), 0, |m| {
2930
if m.start() >= line.as_bytes().len() {
@@ -35,7 +36,12 @@ fn matched(queries: &[&str], line: &str) -> anyhow::Result<Vec<Match>> {
3536
Ok(matched)
3637
}
3738

38-
pub fn styled(query: &str, line: &str, highlight_style: ContentStyle) -> Option<StyledGraphemes> {
39+
pub fn styled(
40+
query: &str,
41+
line: &str,
42+
highlight_style: ContentStyle,
43+
case_insensitive: bool,
44+
) -> Option<StyledGraphemes> {
3945
let piped = &query
4046
.split('|')
4147
.map(|s| s.trim())
@@ -47,7 +53,7 @@ pub fn styled(query: &str, line: &str, highlight_style: ContentStyle) -> Option<
4753
if query.is_empty() {
4854
Some(styled)
4955
} else {
50-
match matched(piped, line) {
56+
match matched(piped, line, case_insensitive) {
5157
Ok(matches) => {
5258
if matches.is_empty() {
5359
None
@@ -71,6 +77,7 @@ pub async fn run(
7177
retrieval_timeout: Duration,
7278
render_interval: Duration,
7379
queue_capacity: usize,
80+
case_insensitive: bool,
7481
) -> anyhow::Result<VecDeque<String>> {
7582
let keymap = ActiveKeySwitcher::new("default", keymap::default);
7683
let size = crossterm::terminal::size()?;
@@ -112,6 +119,7 @@ pub async fn run(
112119
&text_editor.texteditor.text_without_cursor().to_string(),
113120
&line,
114121
highlight_style,
122+
case_insensitive,
115123
) {
116124
let matrix = styled.matrixify(size.0 as usize, size.1 as usize, 0).0;
117125
let term = readonly_term.read().await;

0 commit comments

Comments
 (0)