Skip to content

Drawer

ConstantEdge
DrawerRightRight edge (default)
DrawerLeftLeft 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.

Drawer preview

Drawer is a slide-out panel that appears from an edge of the screen. Unlike Modal which is centered, Drawer attaches to a screen edge. Drawer implements the nav.ModalComponent interface for automatic lifecycle management.

Constructor func NewDrawer(config DrawerConfig) *Drawer

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.
FieldTypeDescription
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.
FieldTypeDescription
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.
FieldTypeDescription
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.
FieldTypeDescription
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.
ConstantDescription
DrawerRight
DrawerLeft