Skip to content

Commit

Permalink
retry_command -> cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Jun 1, 2024
1 parent 59e3094 commit fe26809
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/archived.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Archived {
lines: Snapshot<listbox::State>,
highlight_style: ContentStyle,
case_insensitive: bool,
retry_command: Option<String>,
cmd: Option<String>,
}

impl promkit::Finalizer for Archived {
Expand All @@ -44,7 +44,7 @@ impl promkit::Renderer for Archived {
event,
&mut self.text_editor_snapshot,
&mut self.lines,
self.retry_command.clone(),
self.cmd.clone(),
);
if self
.text_editor_snapshot
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn run(
lines: listbox::State,
highlight_style: ContentStyle,
case_insensitive: bool,
retry_command: Option<String>,
cmd: Option<String>,
) -> anyhow::Result<()> {
Prompt {
renderer: Archived {
Expand All @@ -100,7 +100,7 @@ pub fn run(
lines: Snapshot::new(lines),
highlight_style,
case_insensitive,
retry_command,
cmd,
},
}
.run()
Expand Down
4 changes: 2 additions & 2 deletions src/archived/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn default(
event: &Event,
text_editor_snapshot: &mut Snapshot<text_editor::State>,
logs_snapshot: &mut Snapshot<listbox::State>,
retry_command: Option<String>,
cmd: Option<String>,
) -> anyhow::Result<PromptSignal> {
let text_editor_state = text_editor_snapshot.after_mut();
let logs_state = logs_snapshot.after_mut();
Expand All @@ -28,7 +28,7 @@ pub fn default(
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
}) => {
if retry_command.is_some() {
if cmd.is_some() {
// Exiting archive mode here allows
// the caller to re-enter streaming mode,
// as it is running in an infinite loop.
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct Args {
long_help = "This command is invoked initially and
whenever a retry is triggered according to key mappings."
)]
pub retry_command: Option<String>,
pub cmd: Option<String>,
}

impl Drop for Args {
Expand Down Expand Up @@ -187,7 +187,7 @@ async fn main() -> anyhow::Result<()> {
Duration::from_millis(args.render_interval_millis),
args.queue_capacity,
args.case_insensitive,
args.retry_command.clone(),
args.cmd.clone(),
)
.await
{
Expand Down Expand Up @@ -222,7 +222,7 @@ async fn main() -> anyhow::Result<()> {
},
highlight_style,
args.case_insensitive,
args.retry_command.clone(),
args.cmd.clone(),
)?;

// Re-enable raw mode and hide the cursor again here
Expand Down
10 changes: 4 additions & 6 deletions src/sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub async fn run(
render_interval: Duration,
queue_capacity: usize,
case_insensitive: bool,
retry_command: Option<String>,
cmd: Option<String>,
) -> anyhow::Result<(Signal, VecDeque<String>)> {
let keymap = ActiveKeySwitcher::new("default", keymap::default);
let size = crossterm::terminal::size()?;
Expand All @@ -96,10 +96,8 @@ pub async fn run(
let canceler = CancellationToken::new();

let canceled = canceler.clone();
let streaming = if let Some(retry_command) = retry_command.clone() {
tokio::spawn(
async move { cmd::execute(&retry_command, tx, retrieval_timeout, canceled).await },
)
let streaming = if let Some(cmd) = cmd.clone() {
tokio::spawn(async move { cmd::execute(&cmd, tx, retrieval_timeout, canceled).await })
} else {
tokio::spawn(async move { stdin::streaming(tx, retrieval_timeout, canceled).await })
};
Expand Down Expand Up @@ -145,7 +143,7 @@ pub async fn run(
loop {
let event = event::read()?;
let mut text_editor = shared_text_editor.write().await;
signal = keymap.get()(&event, &mut text_editor, retry_command.clone())?;
signal = keymap.get()(&event, &mut text_editor, cmd.clone())?;
if signal == Signal::GotoArchived || signal == Signal::GotoStreaming {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/sig/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::Signal;
pub fn default(
event: &Event,
state: &mut text_editor::State,
retry_command: Option<String>,
cmd: Option<String>,
) -> anyhow::Result<Signal> {
match event {
Event::Key(KeyEvent {
Expand All @@ -24,7 +24,7 @@ pub fn default(
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
}) => {
if retry_command.is_some() {
if cmd.is_some() {
return Ok(Signal::GotoStreaming);
}
}
Expand Down

0 comments on commit fe26809

Please sign in to comment.