Skip to content

Commit 0e01b09

Browse files
wash2mmstick
authored andcommitted
feat: add arguments for max responses
1 parent 9f8f17a commit 0e01b09

File tree

6 files changed

+180
-9
lines changed

6 files changed

+180
-9
lines changed

Cargo.lock

Lines changed: 116 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/src/find/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum Event {
1818
}
1919

2020
pub async fn main() {
21-
let (event_tx, event_rx) = flume::bounded::<Event>(8);
21+
let (event_tx, event_rx) = flume::bounded::<Event>(20);
2222

2323
// Channel for cancelling searches that are in progress.
2424
let (interrupt_tx, interrupt_rx) = flume::bounded::<()>(1);

plugins/src/scripts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl App {
9999
}
100100

101101
async fn reload(&mut self) {
102-
let (tx, rx) = flume::bounded::<ScriptInfo>(8);
102+
let (tx, rx) = flume::bounded::<ScriptInfo>(20);
103103

104104
let mut queue = VecDeque::new();
105105

service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition.workspace = true
88
anyhow.workspace = true
99
async-oneshot = "0.5.9"
1010
async-trait = "0.1.83"
11+
clap = { version = "4.5.27", features = ["derive"] }
1112
dirs.workspace = true
1213
futures.workspace = true
1314
futures_codec = "0.4.1"

service/src/client.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@ use tokio::io::{AsyncBufReadExt, AsyncWriteExt};
88
use tokio::process;
99
use tokio_stream::wrappers::LinesStream;
1010

11+
use crate::Args;
12+
1113
#[derive(Debug)]
1214
pub struct IpcClient {
1315
pub child: process::Child,
1416
pub stdin: process::ChildStdin,
1517
}
1618

1719
impl IpcClient {
18-
pub fn new() -> io::Result<(Self, impl Stream<Item = Response>)> {
20+
pub fn new_with_args(args: Args) -> io::Result<(Self, impl Stream<Item = Response>)> {
1921
let mut child = process::Command::new("pop-launcher")
22+
.args(&[
23+
"--max-open",
24+
args.max_open.to_string().as_str(),
25+
"--max-files",
26+
args.max_files.to_string().as_str(),
27+
"--max-search",
28+
args.max_search.to_string().as_str(),
29+
])
2030
.stdin(std::process::Stdio::piped())
2131
.stdout(std::process::Stdio::piped())
2232
.spawn()?;
@@ -46,6 +56,10 @@ impl IpcClient {
4656
Ok((client, responses))
4757
}
4858

59+
pub fn new() -> io::Result<(Self, impl Stream<Item = Response>)> {
60+
Self::new_with_args(Args::default())
61+
}
62+
4963
pub async fn send(&mut self, request: Request) -> io::Result<()> {
5064
let mut request_json = serde_json::to_string(&request)
5165
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;

service/src/lib.rs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::plugins::{
1515
};
1616
use crate::priority::Priority;
1717
use crate::recent::RecentUseStorage;
18+
use clap::Parser;
1819
use flume::{Receiver, Sender};
1920
use futures::{future, SinkExt, Stream, StreamExt};
2021
use pop_launcher::{
@@ -23,6 +24,7 @@ use pop_launcher::{
2324
};
2425
use regex::Regex;
2526
use slab::Slab;
27+
use std::usize;
2628
use std::{
2729
cmp::Ordering,
2830
collections::{HashMap, HashSet},
@@ -32,6 +34,33 @@ use std::{
3234

3335
pub type PluginKey = usize;
3436

37+
/// Bounds for the number of service responses.
38+
#[derive(Parser, Debug, Clone, Copy)]
39+
#[command(version, about, long_about = None)]
40+
pub struct Args {
41+
/// Max number of files in a response.
42+
#[arg(short, long, default_value_t = 100)]
43+
pub max_files: usize,
44+
45+
/// Max number of open windows in a response.
46+
#[arg(short, long, default_value_t = 8)]
47+
pub max_open: usize,
48+
49+
/// Max number of generic items in a response.
50+
#[arg(short, long, default_value_t = 8)]
51+
pub max_search: usize,
52+
}
53+
54+
impl Default for Args {
55+
fn default() -> Self {
56+
Args {
57+
max_files: 100,
58+
max_open: 8,
59+
max_search: 8,
60+
}
61+
}
62+
}
63+
3564
pub enum Event {
3665
Request(Request),
3766
Response((PluginKey, PluginResponse)),
@@ -67,6 +96,7 @@ pub fn store_cache(storage: &RecentUseStorage) {
6796
}
6897

6998
pub async fn main() {
99+
let args = Args::parse();
70100
let cachepath = ensure_cache_path();
71101
let read_recent = || -> Result<RecentUseStorage, Box<dyn std::error::Error>> {
72102
let cachepath = std::fs::File::open(cachepath?)?;
@@ -94,7 +124,9 @@ pub async fn main() {
94124
let (output_tx, output_rx) = flume::bounded(16);
95125

96126
// Service will operate for as long as it is being awaited
97-
let service = Service::new(output_tx.into_sink(), recent).exec(input_stream);
127+
let service = Service::new(output_tx.into_sink(), recent)
128+
.with_args(args)
129+
.exec(input_stream);
98130

99131
// Responses from the service will be streamed to stdout
100132
let responder = async move {
@@ -119,6 +151,7 @@ pub struct Service<O> {
119151
plugins: Slab<PluginConnector>,
120152
search_scheduled: bool,
121153
recent: RecentUseStorage,
154+
args: Args,
122155
}
123156

124157
impl<O: futures::Sink<Response> + Unpin> Service<O> {
@@ -133,9 +166,15 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
133166
plugins: Slab::new(),
134167
search_scheduled: false,
135168
recent,
169+
args: Args::default(),
136170
}
137171
}
138172

173+
fn with_args(mut self, args: Args) -> Self {
174+
self.args = args;
175+
self
176+
}
177+
139178
pub async fn exec(mut self, input: impl Stream<Item = Request>) {
140179
let (service_tx, service_rx) = flume::bounded(1);
141180
let stream = plugins::external::load::from_paths();
@@ -284,7 +323,7 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
284323
regex,
285324
isolate_with,
286325
Box::new(move || {
287-
let (request_tx, request_rx) = flume::bounded(8);
326+
let (request_tx, request_rx) = flume::bounded(20);
288327

289328
let init = init.clone();
290329
let service_tx = service_tx.clone();
@@ -593,10 +632,12 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
593632
});
594633
}
595634

596-
let take = if last_query.starts_with('/') | last_query.starts_with('~') {
597-
100
635+
let take = if last_query.is_empty() {
636+
self.args.max_open
637+
} else if last_query.starts_with('/') | last_query.starts_with('~') {
638+
self.args.max_files
598639
} else {
599-
8
640+
self.args.max_search
600641
};
601642

602643
let mut windows = Vec::with_capacity(take);

0 commit comments

Comments
 (0)