Skip to content

Commit

Permalink
Fixed 'sqlite' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cactusdualcore committed Feb 1, 2024
1 parent 2dcf5b1 commit d09289b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
13 changes: 7 additions & 6 deletions examples/cwd_aware_hinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ fn create_item(cwd: &str, cmd: &str, exit_status: i64) -> reedline::HistoryItem
}
}

fn create_filled_example_history(home_dir: &str, orig_dir: &str) -> Box<dyn reedline::History> {
fn create_filled_example_history(home_dir: &str, orig_dir: &str) -> impl reedline::History {
use reedline::History;
#[cfg(not(any(feature = "sqlite", feature = "sqlite-dynlib")))]
let mut history = Box::new(reedline::FileBackedHistory::new(100));
#[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
let mut history = Box::new(reedline::SqliteBackedHistory::in_memory().unwrap());
let mut history = reedline::SqliteBackedHistory::in_memory().unwrap();

history.save(create_item(orig_dir, "dummy", 0)).unwrap(); // add dummy item so ids start with 1
history.save(create_item(orig_dir, "ls /usr", 0)).unwrap();
Expand All @@ -56,11 +56,12 @@ fn main() -> io::Result<()> {
orig_dir.to_string_lossy().as_ref(),
);

let mut line_editor = Reedline::create()
.with_hinter(Box::new(
let mut line_editor = Reedline::builder()
.with_hints(
CwdAwareHinter::default().with_style(Style::new().bold().italic().fg(Color::Yellow)),
))
.with_history(history);
)
.with_history(history)
.build();

let prompt = DefaultPrompt::default();

Expand Down
14 changes: 6 additions & 8 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ fn main() -> reedline::Result<()> {
};

#[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
let history = Box::new(
reedline::SqliteBackedHistory::with_file(
"history.sqlite3".into(),
history_session_id,
Some(chrono::Utc::now()),
)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?,
);
let history = reedline::SqliteBackedHistory::with_file(
"history.sqlite3".into(),
history_session_id,
Some(chrono::Utc::now()),
)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
#[cfg(not(any(feature = "sqlite", feature = "sqlite-dynlib")))]
let history = FileBackedHistory::with_file(50, "history.txt".into())?;
let commands = vec![
Expand Down
11 changes: 6 additions & 5 deletions examples/transient_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ fn main() -> io::Result<()> {

let edit_mode = Emacs::new(keybindings);

let mut line_editor = Reedline::builder()
#[allow(unused_mut)]
let mut builder = Reedline::builder()
.with_hints(DefaultHinter::default().with_style(Style::new().fg(Color::LightGray)))
.with_completion(completer)
.add_menu(ReedlineMenu::EngineCompleter(completion_menu))
Expand All @@ -107,12 +108,12 @@ fn main() -> io::Result<()> {
.with_validator(CustomValidator {})
.with_ansi_colors(true)
.with_history_exclusion_prefix(String::from(" "))
.with_transient_prompt(TransientPrompt {})
.build();
.with_transient_prompt(TransientPrompt {});
#[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
{
line_editor = line_editor.with_history(Box::new(SqliteBackedHistory::in_memory().unwrap()));
}
builder = builder.with_history(SqliteBackedHistory::in_memory().unwrap());
};
let mut line_editor = builder.build();

let prompt = DefaultPrompt::default();

Expand Down

0 comments on commit d09289b

Please sign in to comment.