migrated polling logic from virtterm branch to main

This commit is contained in:
2026-02-16 18:28:57 -05:00
parent d04dd4bc1e
commit 142194c100
7 changed files with 537 additions and 176 deletions

View File

@@ -3,14 +3,10 @@ pub mod readline;
pub mod statusline;
use readline::{FernVi, Readline};
use crate::{
expand::expand_prompt, libsh::error::ShResult, prelude::*, shopt::FernEditMode,
};
use crate::{expand::expand_prompt, libsh::error::ShResult, prelude::*};
/// Initialize the line editor
fn get_prompt() -> ShResult<String> {
pub fn get_prompt() -> ShResult<String> {
let Ok(prompt) = env::var("PS1") else {
// default prompt expands to:
//
@@ -26,18 +22,3 @@ fn get_prompt() -> ShResult<String> {
expand_prompt(&sanitized)
}
pub fn readline(edit_mode: FernEditMode, initial: Option<&str>) -> ShResult<String> {
let prompt = get_prompt()?;
let mut reader: Box<dyn Readline> = match edit_mode {
FernEditMode::Vi => {
let mut fern_vi = FernVi::new(Some(prompt))?;
if let Some(input) = initial {
fern_vi = fern_vi.with_initial(input)
}
Box::new(fern_vi) as Box<dyn Readline>
}
FernEditMode::Emacs => todo!(), // idk if I'm ever gonna do this one actually, I don't use emacs
};
reader.readline()
}