Add abortable flag so that prompts can be skipped

pull/1/head
trivernis 1 year ago
parent 9cf4d225d7
commit e588990df0
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: DFFFCC2C7A02DB45

@ -18,11 +18,24 @@ impl DialogPlugin {
if let Some(val) = default_val { if let Some(val) = default_val {
confirm.default(val); confirm.default(val);
} }
let result = confirm.prompt()?;
Ok(Value::Bool { if call.has_flag("abortable") {
val: result, let result = confirm.prompt_opt()?;
span: call.head,
}) if let Some(val) = result {
Ok(Value::Bool {
val,
span: call.head,
})
} else {
Ok(Value::Nothing { span: call.head })
}
} else {
let result = confirm.prompt()?;
Ok(Value::Bool {
val: result,
span: call.head,
})
}
} }
} }

@ -33,6 +33,7 @@ impl Plugin for DialogPlugin {
SyntaxShape::String, SyntaxShape::String,
"The question to ask the user.", "The question to ask the user.",
) )
.switch("abortable", "If set users can abort the prompt.", None)
.named( .named(
"default", "default",
SyntaxShape::Boolean, SyntaxShape::Boolean,
@ -47,6 +48,8 @@ impl Plugin for DialogPlugin {
SyntaxShape::List(Box::new(SyntaxShape::String)), SyntaxShape::List(Box::new(SyntaxShape::String)),
"The items out of which one can be selected.", "The items out of which one can be selected.",
) )
.switch("fuzzy", "To add a fuzzy search to the select.", None)
.switch("abortable", "If set users can abort the prompt.", None)
.named( .named(
"prompt", "prompt",
SyntaxShape::String, SyntaxShape::String,

@ -28,12 +28,25 @@ impl DialogPlugin {
select.default(def); select.default(def);
} }
let selection = select.prompt()?; if call.has_flag("abortable") {
let selected_item = options.remove(selection); if let Some(selection) = select.prompt_opt()? {
let selected_item = options.remove(selection);
Ok(Value::String { Ok(Value::String {
val: selected_item, val: selected_item,
span: call.head, span: call.head,
}) })
} else {
Ok(Value::Nothing { span: call.head })
}
} else {
let selection = select.prompt()?;
let selected_item = options.remove(selection);
Ok(Value::String {
val: selected_item,
span: call.head,
})
}
} }
} }

Loading…
Cancel
Save