Replies: 1 comment
|
What pyvim is doing is better modeled as a temporary one-line BufferControl, not as editable content inside the toolbar itself. prompt_toolkit already has this pattern in SystemToolbar: it owns a Buffer, wraps it in a one-line BufferControl/Window, puts that window in a ConditionalContainer, and makes the container visible when that buffer has focus. A global key binding focuses the window; Enter/Escape handle accept/cancel and then layout.focus_last() returns focus to the previous control. For a custom command field, create a Buffer, a one-line Window(BufferControl(...)), and a ConditionalContainer filtered by has_focus(command_buffer). Put that container below the toolbar in the surrounding HSplit. In the key binding that opens command mode, call event.app.layout.focus(command_window). On Enter, read/reset command_buffer.text and restore the old focus; Escape can simply reset and restore focus. That has two advantages over trying to mutate a toolbar: the input field gets normal Buffer editing/history/completion behavior, and visibility follows focus rather than requiring you to manually redraw/remove a row. If your desired field is specifically a shell-command prompt, SystemToolbar itself may already be close enough to reuse. If it is a custom colon-style command language, copying its composition/focus pattern while supplying your own accept handler is the cleaner approach. |
Uh oh!
There was an error while loading. Please reload this page.
This may seem obvious, but in pyvim, you can input commands below the toolbar.
How do I make it so that I allow the user to input text below the toolbar when they hit a keybind
All reactions