Drawer
Position
Section titled “Position”| Constant | Edge |
|---|---|
DrawerRight | Right edge (default) |
DrawerLeft | Left edge |
The drawer spans the full height of the terminal.
SetFocusOnShow(p) sets which primitive receives focus when the drawer opens. Useful when the drawer contains a form or list that should be immediately interactive.
Usage
drawer := components.NewDrawer(components.DrawerConfig{ Title: "Details", Width: 50, Position: components.DrawerRight, Backdrop: true,}). SetContent(tview.NewBox()). SetDismissOnEsc(true). SetHints([]components.KeyHint{ {Key: "Esc", Description: "Close"}, })
fmt.Println(drawer != nil)Methods
| Method | Signature | Description |
|---|---|---|
Close | func (d *Drawer) Close() | Close triggers the close callback. |
GetBehavior | func (d *Drawer) GetBehavior() ModalBehavior | GetBehavior returns the drawer's behavior configuration. |
GetHintBar | func (d *Drawer) GetHintBar() *KeyHintBar | GetHintBar returns the hint bar for direct manipulation. |
GetPanel | func (d *Drawer) GetPanel() *Panel | GetPanel returns the drawer's panel for customization. |
Hints | func (d *Drawer) Hints() []KeyHint | Hints returns key binding hints for this drawer. |
ModalBehavior | func (d *Drawer) ModalBehavior() ModalBehavior | ModalBehavior implements nav.Modal. |
OnDismiss | func (d *Drawer) OnDismiss() bool | OnDismiss implements nav.Modal. |
SetBehavior | func (d *Drawer) SetBehavior(b ModalBehavior) *Drawer | SetBehavior configures the drawer's behavior. |
SetContent | func (d *Drawer) SetContent(content tview.Primitive) *Drawer | SetContent sets the drawer's main content. |
SetDismissOnEsc | func (d *Drawer) SetDismissOnEsc(dismiss bool) *Drawer | SetDismissOnEsc sets whether Escape key dismisses the drawer. |
SetFocusOnShow | func (d *Drawer) SetFocusOnShow(p tview.Primitive) *Drawer | SetFocusOnShow sets a specific primitive to focus when the drawer is shown. |
SetHints | func (d *Drawer) SetHints(hints []KeyHint) *Drawer | SetHints sets the key hints displayed at bottom. |
SetOnClose | func (d *Drawer) SetOnClose(fn func()) *Drawer | SetOnClose sets callback when drawer closes. |
SetOnDismiss | func (d *Drawer) SetOnDismiss(fn func() bool) *Drawer | SetOnDismiss sets a handler called before the drawer is dismissed. Return false from the handler to cancel the dismiss. |
Start | func (d *Drawer) Start() | Start is called when the drawer becomes active. |
Stop | func (d *Drawer) Stop() | Stop is called when the drawer becomes inactive. |
Types
type DrawerConfig struct DrawerConfig configures drawer dimensions and behavior. | Field | Type | Description |
|---|---|---|
Title | string | |
Width | int | Fixed width |
Position | DrawerPosition | Which edge to attach to |
Backdrop | bool | Draw semi-transparent background |
type KeyHint struct KeyHint represents a single key binding hint. | Field | Type | Description |
|---|---|---|
Key | string | e.g., "Enter", "Esc", "Space", "j/k" |
Description | string | e.g., "Select", "Close", "Toggle" |
type KeyHintBar struct KeyHintBar displays key hints in a pill style at the bottom of views/modals. | Field | Type | Description |
|---|---|---|
Hints | []KeyHint |
type ModalBehavior struct ModalBehavior configures how a modal handles input and lifecycle.
This is a copy of nav.ModalBehavior to avoid import cycles.
The values are copied when implementing nav.ModalComponent. | Field | Type | Description |
|---|---|---|
CapturesAllInput | bool | CapturesAllInput prevents input from reaching underlying views. |
DismissOnEsc | bool | DismissOnEsc automatically dismisses the modal when Escape is pressed. |
RestoreFocusOnDismiss | bool | RestoreFocusOnDismiss returns focus to the previous component when dismissed. |
Backdrop | bool | Backdrop draws a semi-transparent overlay behind the modal. |
BlockUntilDismissed | bool | BlockUntilDismissed prevents other stack operations until this modal is dismissed. |
type Panel Panel is a container with rounded borders and optional title.
It delegates focus and input handling to its content. type DrawerPosition DrawerPosition specifies which edge the drawer appears from. | Constant | Description |
|---|---|
DrawerRight | |
DrawerLeft |