Implemented assignments, working on job control
This commit is contained in:
@@ -66,7 +66,7 @@ impl<'e> FernHist {
|
||||
pub fn new() -> Self {
|
||||
Self { file_path: None, entries: HistEntries::new(), max_len: 1000, flags: HistFlags::empty() }
|
||||
}
|
||||
pub fn from_path(file_path: PathBuf) -> ShResult<'e,Self> {
|
||||
pub fn from_path(file_path: PathBuf) -> ShResult<Self> {
|
||||
let mut new_hist = FernHist::new();
|
||||
new_hist.file_path = Some(file_path);
|
||||
new_hist.load_hist()?;
|
||||
@@ -76,14 +76,14 @@ impl<'e> FernHist {
|
||||
let id = self.len() + 1;
|
||||
HistEntry::new(body.to_string(), id)
|
||||
}
|
||||
pub fn init_hist_file(&mut self) -> ShResult<'e,()> {
|
||||
pub fn init_hist_file(&mut self) -> ShResult<()> {
|
||||
let Some(path) = self.file_path.clone() else {
|
||||
return Ok(());
|
||||
};
|
||||
self.save(&path)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn load_hist(&mut self) -> ShResult<'e,()> {
|
||||
pub fn load_hist(&mut self) -> ShResult<()> {
|
||||
let Some(file_path) = self.file_path.clone() else {
|
||||
return Err(
|
||||
ShErr::simple(
|
||||
|
||||
@@ -9,16 +9,16 @@ use rustyline::{error::ReadlineError, history::{FileHistory, History}, Config, E
|
||||
|
||||
use crate::{libsh::{error::ShResult, term::{Style, Styled}}, prelude::*};
|
||||
|
||||
fn init_rl<'s>() -> ShResult<'s,Editor<FernReadline,FernHist>> {
|
||||
let hist = FernHist::default();
|
||||
fn init_rl<'s>() -> ShResult<Editor<FernReadline,FileHistory>> {
|
||||
let rl = FernReadline::new();
|
||||
let config = Config::default();
|
||||
let mut editor = Editor::with_history(config,hist)?;
|
||||
let mut editor = Editor::new()?;
|
||||
editor.set_helper(Some(rl));
|
||||
editor.load_history(&Path::new("/home/pagedmov/.fernhist"))?;
|
||||
Ok(editor)
|
||||
}
|
||||
|
||||
pub fn read_line<'s>() -> ShResult<'s,String> {
|
||||
pub fn read_line<'s>() -> ShResult<String> {
|
||||
assert!(isatty(STDIN_FILENO).unwrap());
|
||||
let mut editor = init_rl()?;
|
||||
let prompt = "$ ".styled(Style::Green | Style::Bold);
|
||||
match editor.readline(&prompt) {
|
||||
|
||||
@@ -47,7 +47,11 @@ impl Hint for FernHint {
|
||||
impl Hinter for FernReadline {
|
||||
type Hint = FernHint;
|
||||
fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option<Self::Hint> {
|
||||
let ent = ctx.history().search(line, pos, rustyline::history::SearchDirection::Reverse).ok()??;
|
||||
let ent = ctx.history().search(
|
||||
line,
|
||||
ctx.history().len() - 1,
|
||||
rustyline::history::SearchDirection::Reverse
|
||||
).ok()??;
|
||||
let entry_raw = ent.entry.get(pos..)?.to_string();
|
||||
Some(FernHint::new(entry_raw))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user