@@ -15,6 +15,7 @@ use crate::plugins::{
15
15
} ;
16
16
use crate :: priority:: Priority ;
17
17
use crate :: recent:: RecentUseStorage ;
18
+ use clap:: Parser ;
18
19
use flume:: { Receiver , Sender } ;
19
20
use futures:: { future, SinkExt , Stream , StreamExt } ;
20
21
use pop_launcher:: {
@@ -23,6 +24,7 @@ use pop_launcher::{
23
24
} ;
24
25
use regex:: Regex ;
25
26
use slab:: Slab ;
27
+ use std:: usize;
26
28
use std:: {
27
29
cmp:: Ordering ,
28
30
collections:: { HashMap , HashSet } ,
@@ -32,6 +34,33 @@ use std::{
32
34
33
35
pub type PluginKey = usize ;
34
36
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
+
35
64
pub enum Event {
36
65
Request ( Request ) ,
37
66
Response ( ( PluginKey , PluginResponse ) ) ,
@@ -67,6 +96,7 @@ pub fn store_cache(storage: &RecentUseStorage) {
67
96
}
68
97
69
98
pub async fn main ( ) {
99
+ let args = Args :: parse ( ) ;
70
100
let cachepath = ensure_cache_path ( ) ;
71
101
let read_recent = || -> Result < RecentUseStorage , Box < dyn std:: error:: Error > > {
72
102
let cachepath = std:: fs:: File :: open ( cachepath?) ?;
@@ -94,7 +124,9 @@ pub async fn main() {
94
124
let ( output_tx, output_rx) = flume:: bounded ( 16 ) ;
95
125
96
126
// 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) ;
98
130
99
131
// Responses from the service will be streamed to stdout
100
132
let responder = async move {
@@ -119,6 +151,7 @@ pub struct Service<O> {
119
151
plugins : Slab < PluginConnector > ,
120
152
search_scheduled : bool ,
121
153
recent : RecentUseStorage ,
154
+ args : Args ,
122
155
}
123
156
124
157
impl < O : futures:: Sink < Response > + Unpin > Service < O > {
@@ -133,9 +166,15 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
133
166
plugins : Slab :: new ( ) ,
134
167
search_scheduled : false ,
135
168
recent,
169
+ args : Args :: default ( ) ,
136
170
}
137
171
}
138
172
173
+ fn with_args ( mut self , args : Args ) -> Self {
174
+ self . args = args;
175
+ self
176
+ }
177
+
139
178
pub async fn exec ( mut self , input : impl Stream < Item = Request > ) {
140
179
let ( service_tx, service_rx) = flume:: bounded ( 1 ) ;
141
180
let stream = plugins:: external:: load:: from_paths ( ) ;
@@ -284,7 +323,7 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
284
323
regex,
285
324
isolate_with,
286
325
Box :: new ( move || {
287
- let ( request_tx, request_rx) = flume:: bounded ( 8 ) ;
326
+ let ( request_tx, request_rx) = flume:: bounded ( 20 ) ;
288
327
289
328
let init = init. clone ( ) ;
290
329
let service_tx = service_tx. clone ( ) ;
@@ -593,10 +632,12 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
593
632
} ) ;
594
633
}
595
634
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
598
639
} else {
599
- 8
640
+ self . args . max_search
600
641
} ;
601
642
602
643
let mut windows = Vec :: with_capacity ( take) ;
0 commit comments