pub struct SlashCommands { /* private fields */ }Expand description
Pi-compatible slash-command completion over a fixed Command palette.
/ at a line start opens ranked name completion, the first argument
completes against candidates, and usage text ghosts after the cursor
(pi buildSubcommandInlineHint).
Implementations§
Source§impl SlashCommands
impl SlashCommands
Sourcepub fn new(commands: impl Into<Box<[Command]>>) -> Self
pub fn new(commands: impl Into<Box<[Command]>>) -> Self
Wraps a command palette for Editor::set_completion.
Examples found in repository?
examples/chat/demo.rs (line 755)
752 pub fn new(ctx: &UiContext) -> Self {
753 let editor = Rc::new(RefCell::new({
754 let mut editor = Editor::new(EditorOptions::default());
755 editor.set_completion(Box::new(SlashCommands::new(demo_commands())));
756 editor
757 }));
758 let edit_outcome = Rc::new(RefCell::new(None));
759 let work = Rc::new(RefCell::new(WorkState {
760 working: true,
761 since: Duration::ZERO,
762 fade: Tween::settled(GREEN),
763 }));
764 let model = Rc::new(RefCell::new(Str::new_static("Fable 5++")));
765 let pane = EditorPane::new()
766 .input(DemoInput::new(Rc::clone(&editor), Rc::clone(&edit_outcome)))
767 .status(DemoStatus::new(Rc::clone(&work), Rc::clone(&model), ctx.charset));
768 let attachments = pane.attachments();
769 let editor_ui = Ui::from_root(pane, 0, ctx.clone());
770 Self {
771 started_at: Instant::now(),
772 ctx: ctx.clone(),
773 cancel_hint: ctx.charset.icon(Icon::Cancellable),
774 editor_ui,
775 editor,
776 edit_outcome,
777 work,
778 last_working: true,
779 model,
780 attachments,
781 transcript: vec![Entry::Command],
782 drawn_entries: 0,
783 transcript_rows: 0,
784 appended_messages: 0,
785 emitted_shards: 0,
786 last_viewport: Size::new(0, 0),
787 height_floor: 0,
788 frame: Frame::new(Size::new(0, 0)),
789 live_panel: None,
790 live_rows: std::array::from_fn(|_| LiveRowCache::new()),
791 live_label_scratch: StrMut::with_capacity(40),
792 right_inset: 0,
793 switch_requested: false,
794 }
795 }Trait Implementations§
Source§impl EditorCompletion for SlashCommands
impl EditorCompletion for SlashCommands
Source§fn hint(&mut self, text: &str, cursor: usize) -> Option<Str>
fn hint(&mut self, text: &str, cursor: usize) -> Option<Str>
Pi-style usage ghosting: bare /name shows the command’s own
usage; a partial argument shows its remaining characters plus
usage; a chosen argument ghosts the usage words not yet typed.
Source§fn suggest(&mut self, text: &str, cursor: usize) -> Option<Suggestions>
fn suggest(&mut self, text: &str, cursor: usize) -> Option<Suggestions>
Dropdown suggestions for the current text and byte cursor, or
None to close the dropdown.Source§fn tab(
&mut self,
text: &str,
cursor: usize,
selected: Option<&Suggestion>,
) -> TabAction
fn tab( &mut self, text: &str, cursor: usize, selected: Option<&Suggestion>, ) -> TabAction
Tab pressed.
selected is the highlighted row while this engine’s
dropdown is open. Defaults to pi’s behavior: accept the open row,
otherwise pass Tab through to the embedding app. The built-in
emoji dropdown always accepts without consulting the engine.Auto Trait Implementations§
impl Freeze for SlashCommands
impl RefUnwindSafe for SlashCommands
impl Send for SlashCommands
impl Sync for SlashCommands
impl Unpin for SlashCommands
impl UnsafeUnpin for SlashCommands
impl UnwindSafe for SlashCommands
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more