Added 'read_key' builtin that allows widget scripts to handle input

This commit is contained in:
2026-03-03 20:39:09 -05:00
parent a300e54ee8
commit c642a96da7
12 changed files with 433 additions and 72 deletions

View File

@@ -87,6 +87,7 @@ pub trait ShResultExt {
fn blame(self, span: Span) -> Self;
fn try_blame(self, span: Span) -> Self;
fn promote_err(self, span: Span) -> Self;
fn is_flow_control(&self) -> bool;
}
impl<T> ShResultExt for Result<T, ShErr> {
@@ -101,6 +102,9 @@ impl<T> ShResultExt for Result<T, ShErr> {
fn promote_err(self, span: Span) -> Self {
self.map_err(|e| e.promote(span))
}
fn is_flow_control(&self) -> bool {
self.as_ref().is_err_and(|e| e.is_flow_control())
}
}
#[derive(Clone, Debug)]
@@ -179,6 +183,9 @@ impl ShErr {
pub fn simple(kind: ShErrKind, msg: impl Into<String>) -> Self {
Self { kind, src_span: None, labels: vec![], sources: vec![], notes: vec![msg.into()], io_guards: vec![] }
}
pub fn is_flow_control(&self) -> bool {
self.kind.is_flow_control()
}
pub fn promote(mut self, span: Span) -> Self {
if self.notes.is_empty() {
return self
@@ -356,6 +363,18 @@ pub enum ShErrKind {
Null,
}
impl ShErrKind {
pub fn is_flow_control(&self) -> bool {
matches!(self,
Self::CleanExit(_) |
Self::FuncReturn(_) |
Self::LoopContinue(_) |
Self::LoopBreak(_) |
Self::ClearReadline
)
}
}
impl Display for ShErrKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let output = match self {