Skip to content

Commit

Permalink
Merge pull request #7 from Toorero/main
Browse files Browse the repository at this point in the history
Reexport `reedline` and fix dependency on `clap_complete`
  • Loading branch information
HKalbasi authored Aug 14, 2024
2 parents cd8e620 + cd8bd9a commit dd65b45
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ path = "src/lib.rs"

[dependencies]
clap = { version = "4.4.10", features = ["derive"] }
clap_complete = { version = "4.5.2", features = ["unstable-dynamic"] }
clap_complete = { version = "=4.5.16", features = ["unstable-dynamic", "unstable-command"] }
console = "0.15.7"
nu-ansi-term = "0.50.0"
reedline = "0.32.0"
Expand Down
4 changes: 3 additions & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::path::PathBuf;

use clap::{Parser, ValueEnum};
use clap_repl::reedline::{
DefaultPrompt, DefaultPromptSegment, FileBackedHistory, Reedline, Signal,
};
use clap_repl::ClapEditor;
use reedline::{DefaultPrompt, DefaultPromptSegment, FileBackedHistory, Reedline, Signal};

#[derive(Debug, Parser)]
#[command(name = "")] // This name will show up in clap's error messages, so it is important to set it to "".
Expand Down
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::{ffi::OsString, marker::PhantomData, path::PathBuf, str::FromStr};
use clap::{Parser, Subcommand};
use console::style;
use nu_ansi_term::{Color, Style};

// reexport reedline to prevent version mixups
pub use reedline;
use reedline::{
default_emacs_keybindings, DefaultHinter, DefaultPrompt, Emacs, IdeMenu, KeyModifiers,
MenuBuilder, Prompt, Reedline, ReedlineEvent, ReedlineMenu, Signal, Span,
Expand All @@ -28,7 +31,7 @@ struct ReedCompleter<C: Parser + Send + Sync + 'static> {
impl<C: Parser + Send + Sync + 'static> reedline::Completer for ReedCompleter<C> {
fn complete(&mut self, line: &str, pos: usize) -> Vec<reedline::Suggestion> {
let cmd = C::command();
let mut cmd = clap_complete::dynamic::shells::CompleteCommand::augment_subcommands(cmd);
let mut cmd = clap_complete::dynamic::command::CompleteCommand::augment_subcommands(cmd);
let args = Shlex::new(line);
let mut args = std::iter::once("".to_owned())
.chain(args)
Expand All @@ -50,8 +53,8 @@ impl<C: Parser + Send + Sync + 'static> reedline::Completer for ReedCompleter<C>
candidates
.into_iter()
.map(|c| reedline::Suggestion {
value: c.0.to_string_lossy().into_owned(),
description: c.1.map(|x| x.to_string()),
value: c.get_content().to_string_lossy().into_owned(),
description: c.get_help().map(|x| x.to_string()),
style: None,
extra: None,
span,
Expand Down

0 comments on commit dd65b45

Please sign in to comment.