Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reexport reedline and fix dependency on clap_complete #7

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading