app

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ViewWorkspace  = "workspace"
	ViewMigrations = "migrations"
	ViewDetails    = "details"
	ViewOutputs    = "outputs"
	ViewStatusbar  = "statusbar"
)

View identifiers

Variables

This section is empty.

Functions

func AdjustOrigin

func AdjustOrigin(v *gocui.View, originY *int)

AdjustOrigin adjusts the origin to ensure it's within valid bounds Call this after content is rendered but before SetOrigin

func ColorToGocuiAttr added in v0.3.0

func ColorToGocuiAttr(c Color) int

ColorToGocuiAttr converts a Color to a gocui color attribute value. Exported so it can be used by any code that needs this conversion.

func CopyToClipboard

func CopyToClipboard(text string) error

CopyToClipboard copies text to the system clipboard

func WrapText added in v0.3.0

func WrapText(text string, maxWidth int, padding string) []string

WrapText wraps text to fit within the specified width. Each resulting line is prefixed with the given padding string. Handles multiple paragraphs separated by newlines.

Types

type App

type App struct {
	Common *common.Common
	Tr     *i18n.TranslationSet
	// contains filtered or unexported fields
}

func NewApp

func NewApp(config AppConfig) (*App, error)

func (*App) Alert added in v0.3.1

func (a *App) Alert(title string, message string)

Alert shows a simple notification popup (unstyled).

func (*App) CloseModal

func (a *App) CloseModal()

CloseModal closes the active modal and restores focus

func (*App) Confirm added in v0.3.1

func (a *App) Confirm(opts types.ConfirmOpts)

Confirm shows a yes/no confirmation popup. The ConfirmOpts callbacks return error; the underlying ConfirmModal expects func(). We wrap them with adapters that discard the error.

func (*App) ErrorHandler added in v0.3.1

func (a *App) ErrorHandler(err error) error

ErrorHandler shows an error modal with red styling.

func (*App) FinishCommand added in v0.3.1

func (a *App) FinishCommand()

FinishCommand marks command execution as complete.

func (*App) FocusNext

func (a *App) FocusNext()

func (*App) FocusPrevious

func (a *App) FocusPrevious()

func (*App) GetCurrentPanel

func (a *App) GetCurrentPanel() Panel

GetCurrentPanel returns the currently focused panel

func (*App) GetGui

func (a *App) GetGui() *gocui.Gui

func (*App) GetTranslationSet added in v0.3.1

func (a *App) GetTranslationSet() *i18n.TranslationSet

GetTranslationSet returns the current translation set.

func (*App) HandlePanelClick added in v0.3.0

func (a *App) HandlePanelClick(viewID string)

HandlePanelClick is the public wrapper for panel-click focus switching. It is used as a callback by contexts that manage their own mouse events.

func (*App) HasActiveModal

func (a *App) HasActiveModal() bool

HasActiveModal returns true if a modal is currently active

func (*App) LogAction added in v0.3.1

func (a *App) LogAction(action string, detail ...string)

LogAction logs a user-visible action to the output panel. Wrapped in g.Update() for thread safety — OutputContext.LogAction mutates o.content without mutex, so it must run on the UI thread.

func (*App) LogCommandBlocked added in v0.3.1

func (a *App) LogCommandBlocked(commandName string)

LogCommandBlocked logs a message when command execution is blocked.

func (*App) Menu added in v0.3.1

func (a *App) Menu(opts types.MenuOpts) error

Menu shows a list of selectable options. Maps types.MenuItem to ListModalItem.

func (*App) OnUIThread added in v0.3.1

func (a *App) OnUIThread(f func() error)

OnUIThread schedules a function to run on the UI thread.

func (*App) OpenModal

func (a *App) OpenModal(modal Modal)

OpenModal opens a modal and saves current focus state

func (*App) Prompt added in v0.3.1

func (a *App) Prompt(opts types.PromptOpts)

Prompt shows a text-input popup. The PromptOpts callback returns error; the underlying InputModal expects func(string). We wrap with an adapter that discards the error.

func (*App) Refresh added in v0.3.1

func (a *App) Refresh()

Refresh triggers a data refresh and re-render of all contexts. This is the controller-facing API; it ignores the return value of RefreshAll.

func (*App) RefreshAll

func (a *App) RefreshAll(onComplete ...func()) bool

RefreshAll refreshes all panels asynchronously

func (*App) RefreshPanels added in v0.3.1

func (a *App) RefreshPanels()

RefreshPanels refreshes all panels (blocking, internal).

func (*App) RegisterKeybindings

func (a *App) RegisterKeybindings() error

func (*App) RegisterMouseBindings

func (a *App) RegisterMouseBindings()

RegisterMouseBindings registers mouse click handlers for all panels

func (*App) RegisterPanel

func (a *App) RegisterPanel(panel Panel)

func (*App) Run

func (a *App) Run() error

func (*App) RunStreamingCommand added in v0.3.1

func (a *App) RunStreamingCommand(opts AsyncCommandOpts) bool

RunStreamingCommand handles the common boilerplate for streaming prisma commands. Returns false if the command could not be started (another command running or panel missing). The helper does NOT call FinishCommand() -- each callback is responsible for calling it.

func (*App) SetControllers added in v0.3.1

func (a *App) SetControllers(mc *MigrationsController, gc *GenerateController, sc *StudioController, cc *ClipboardController)

SetControllers wires the extracted controllers into the App.

func (*App) StatusBarState added in v0.3.0

func (a *App) StatusBarState() context.StatusBarState

StatusBarState returns callbacks for the StatusBarContext to access App state.

func (*App) Toast added in v0.3.1

func (a *App) Toast(message string)

Toast shows a brief message. Currently delegates to Alert as there is no auto-dismiss toast system yet.

func (*App) TryStartCommand added in v0.3.1

func (a *App) TryStartCommand(commandName string) bool

TryStartCommand attempts to start a command execution. Returns true if command can start, false if another command is already running.

type AppConfig

type AppConfig struct {
	DebugMode bool
	AppName   string
	Version   string
	Developer string
	Language  string
}

type AsyncCommandOpts added in v0.3.1

type AsyncCommandOpts struct {
	Name         string   // for tryStartCommand / logCommandBlocked
	Args         []string // full command args: ["npx", "prisma", "migrate", "deploy"]
	LogAction    string   // log action label (e.g., "Migrate Deploy")
	LogDetail    string   // log detail text (e.g., "Running prisma migrate deploy...")
	SkipTryStart bool     // true if tryStartCommand was already called by the caller

	// Callbacks — each callback is responsible for calling finishCommand() at the appropriate time.
	// The helper never calls finishCommand() itself.
	OnSuccess func(out *context.OutputContext, cwd string)
	OnFailure func(out *context.OutputContext, cwd string, exitCode int)
	OnError   func(out *context.OutputContext, cwd string, err error)

	// ErrorTitle and ErrorStartMsg are used for the default RunAsync failure modal.
	// If empty, generic error text is used.
	ErrorTitle    string
	ErrorStartMsg string
}

AsyncCommandOpts configures a streaming async command.

type BaseModal added in v0.3.0

type BaseModal struct {
	// contains filtered or unexported fields
}

BaseModal provides common infrastructure shared by all modal types

func NewBaseModal added in v0.3.0

func NewBaseModal(id string, g *gocui.Gui, tr *i18n.TranslationSet) *BaseModal

NewBaseModal creates a new BaseModal with default style

func (*BaseModal) AcceptsTextInput added in v0.3.1

func (b *BaseModal) AcceptsTextInput() bool

AcceptsTextInput returns false by default (most modals don't accept text input).

func (*BaseModal) CalculateDimensions added in v0.3.0

func (b *BaseModal) CalculateDimensions(widthRatio float64, minWidth int) (width int)

CalculateDimensions computes centered coordinates for a modal view. widthRatio is the fraction of screen width (e.g., 4.0/7.0). heightContent is the number of content lines (borders added by caller). minWidth is the minimum width for the modal.

func (*BaseModal) CenterBox added in v0.3.0

func (b *BaseModal) CenterBox(width, height int) (x0, y0, x1, y1 int)

CenterBox returns centered screen coordinates for a box of the given width and height.

func (*BaseModal) ClosesOnEnter added in v0.3.1

func (b *BaseModal) ClosesOnEnter() bool

ClosesOnEnter returns false by default (most modals handle Enter via HandleKey).

func (*BaseModal) ID added in v0.3.0

func (b *BaseModal) ID() string

ID returns the modal's view ID

func (*BaseModal) OnClose added in v0.3.0

func (b *BaseModal) OnClose()

OnClose deletes the modal's primary view

func (*BaseModal) SetStyle added in v0.3.0

func (b *BaseModal) SetStyle(style MessageModalStyle)

SetStyle sets the modal style (used by embedding structs' WithStyle methods)

func (*BaseModal) SetupView added in v0.3.0

func (b *BaseModal) SetupView(name string, x0, y0, x1, y1 int, zIndex byte, title, footer string) (*gocui.View, bool, error)

SetupView creates (or retrieves) a gocui view and applies common frame settings. It handles the "unknown view" error from SetView, applies frame runes, title, footer, and style colours. Returns the view and whether it was newly created.

func (*BaseModal) Style added in v0.3.0

func (b *BaseModal) Style() MessageModalStyle

Style returns the current modal style

type BasePanel

type BasePanel struct {
	// contains filtered or unexported fields
}

func NewBasePanel

func NewBasePanel(id string, g *gocui.Gui) BasePanel

func (*BasePanel) ID

func (bp *BasePanel) ID() string

func (*BasePanel) OnBlur

func (bp *BasePanel) OnBlur()

func (*BasePanel) OnFocus

func (bp *BasePanel) OnFocus()

func (*BasePanel) SetupView

func (bp *BasePanel) SetupView(v *gocui.View, title string)

SetupView handles common view setup

type ClipboardController added in v0.3.1

type ClipboardController struct {
	// contains filtered or unexported fields
}

ClipboardController handles clipboard-related operations.

func NewClipboardController added in v0.3.1

func NewClipboardController(
	c types.IControllerHost,
	g *gocui.Gui,
	migrationsCtx *context.MigrationsContext,
	openModal func(Modal),
	closeModal func(),
) *ClipboardController

NewClipboardController creates a new ClipboardController.

func (*ClipboardController) CopyMigrationInfo added in v0.3.1

func (cc *ClipboardController) CopyMigrationInfo()

CopyMigrationInfo copies migration info to clipboard

type Color

type Color int

Color represents terminal colors

const (
	ColorDefault Color = iota
	ColorBlack
	ColorRed
	ColorGreen
	ColorYellow
	ColorBlue
	ColorMagenta
	ColorCyan
	ColorWhite
)

type ConfirmModal

type ConfirmModal struct {
	*BaseModal
	// contains filtered or unexported fields
}

ConfirmModal displays a confirmation dialog with Yes/No options

func NewConfirmModal

func NewConfirmModal(g *gocui.Gui, tr *i18n.TranslationSet, title string, message string, onYes func(), onNo func()) *ConfirmModal

NewConfirmModal creates a new confirmation modal

func (*ConfirmModal) Draw

func (m *ConfirmModal) Draw(dim boxlayout.Dimensions) error

Draw renders the modal

func (*ConfirmModal) HandleKey

func (m *ConfirmModal) HandleKey(key any, mod gocui.Modifier) error

HandleKey handles keyboard input

func (*ConfirmModal) OnClose

func (m *ConfirmModal) OnClose()

OnClose is called when the modal is closed

func (*ConfirmModal) WithStyle

func (m *ConfirmModal) WithStyle(style MessageModalStyle) *ConfirmModal

WithStyle sets the modal style

type GenerateController added in v0.3.1

type GenerateController struct {
	// contains filtered or unexported fields
}

GenerateController handles prisma generate operations.

func NewGenerateController added in v0.3.1

func NewGenerateController(
	c types.IControllerHost,
	g *gocui.Gui,
	outputCtx *context.OutputContext,
	openModal func(Modal),
	runStreamCmd func(AsyncCommandOpts) bool,
) *GenerateController

NewGenerateController creates a new GenerateController.

func (*GenerateController) Generate added in v0.3.1

func (gc *GenerateController) Generate()

Generate runs prisma generate and shows result in modal

type InputModal

type InputModal struct {
	*BaseModal
	// contains filtered or unexported fields
}

InputModal displays an input field for user text entry

func NewInputModal

func NewInputModal(g *gocui.Gui, tr *i18n.TranslationSet, title string, onSubmit func(string), onCancel func()) *InputModal

NewInputModal creates a new input modal

func (*InputModal) AcceptsTextInput added in v0.3.1

func (m *InputModal) AcceptsTextInput() bool

AcceptsTextInput returns true because InputModal uses keyboard for text entry.

func (*InputModal) Draw

func (m *InputModal) Draw(dim boxlayout.Dimensions) error

Draw renders the input modal

func (*InputModal) HandleKey

func (m *InputModal) HandleKey(key any, mod gocui.Modifier) error

HandleKey handles keyboard input

func (*InputModal) OnClose

func (m *InputModal) OnClose()

OnClose is called when the modal is closed

func (*InputModal) OnValidationFail

func (m *InputModal) OnValidationFail(callback func(string)) *InputModal

OnValidationFail sets the callback for validation failures

func (*InputModal) WithRequired

func (m *InputModal) WithRequired(required bool) *InputModal

WithRequired sets whether the input is required (non-empty)

func (*InputModal) WithStyle

func (m *InputModal) WithStyle(style MessageModalStyle) *InputModal

WithStyle sets the modal style

func (*InputModal) WithSubtitle

func (m *InputModal) WithSubtitle(subtitle string) *InputModal

WithSubtitle sets the modal subtitle

type ListModal

type ListModal struct {
	*BaseModal
	// contains filtered or unexported fields
}

ListModal displays a list of items with descriptions

func NewListModal

func NewListModal(g *gocui.Gui, tr *i18n.TranslationSet, title string, items []ListModalItem, onCancel func()) *ListModal

NewListModal creates a new list modal

func (*ListModal) Draw

func (m *ListModal) Draw(dim boxlayout.Dimensions) error

Draw renders the list modal with two views (list on top, description on bottom)

func (*ListModal) HandleKey

func (m *ListModal) HandleKey(key any, mod gocui.Modifier) error

HandleKey handles keyboard input

func (*ListModal) OnClose

func (m *ListModal) OnClose()

OnClose is called when the modal is closed

func (*ListModal) WithStyle

func (m *ListModal) WithStyle(style MessageModalStyle) *ListModal

WithStyle sets the modal style

type ListModalItem

type ListModalItem struct {
	Label       string       // Display text in the list
	Description string       // Description shown in the bottom view
	OnSelect    func() error // Callback when item is selected with Enter
}

ListModalItem represents a selectable item in the list modal

type MessageModal

type MessageModal struct {
	*BaseModal
	// contains filtered or unexported fields
}

MessageModal displays a message with title and content

func NewMessageModal

func NewMessageModal(g *gocui.Gui, tr *i18n.TranslationSet, title string, lines ...string) *MessageModal

NewMessageModal creates a new message modal

func (*MessageModal) ClosesOnEnter added in v0.3.1

func (m *MessageModal) ClosesOnEnter() bool

ClosesOnEnter returns true because MessageModal is dismissed with Enter.

func (*MessageModal) Draw

func (m *MessageModal) Draw(dim boxlayout.Dimensions) error

Draw renders the modal

func (*MessageModal) HandleKey

func (m *MessageModal) HandleKey(key any, mod gocui.Modifier) error

HandleKey handles keyboard input

func (*MessageModal) OnClose

func (m *MessageModal) OnClose()

OnClose is called when the modal is closed

func (*MessageModal) WithStyle

func (m *MessageModal) WithStyle(style MessageModalStyle) *MessageModal

WithStyle sets the modal style

type MessageModalStyle

type MessageModalStyle struct {
	TitleColor  Color // Color for title (default: ColorDefault)
	BorderColor Color // Color for border (default: ColorDefault)
}

MessageModalStyle holds styling options for the modal

type MigrationsController added in v0.3.1

type MigrationsController struct {
	// contains filtered or unexported fields
}

MigrationsController handles migration-related operations.

func NewMigrationsController added in v0.3.1

func NewMigrationsController(
	c types.IControllerHost,
	g *gocui.Gui,
	migrationsCtx *context.MigrationsContext,
	outputCtx *context.OutputContext,
	openModal func(Modal),
	closeModal func(),
	runStreamCmd func(AsyncCommandOpts) bool,
) *MigrationsController

NewMigrationsController creates a new MigrationsController.

func (*MigrationsController) DeleteMigration added in v0.3.1

func (mc *MigrationsController) DeleteMigration()

DeleteMigration deletes a pending migration

func (*MigrationsController) MigrateDeploy added in v0.3.1

func (mc *MigrationsController) MigrateDeploy()

MigrateDeploy runs npx prisma migrate deploy

func (*MigrationsController) MigrateDev added in v0.3.1

func (mc *MigrationsController) MigrateDev()

MigrateDev opens a list modal to choose migration type

func (*MigrationsController) MigrateResolve added in v0.3.1

func (mc *MigrationsController) MigrateResolve()

MigrateResolve resolves a failed migration

func (*MigrationsController) SchemaDiffMigration added in v0.3.1

func (mc *MigrationsController) SchemaDiffMigration()

SchemaDiffMigration performs schema diff-based migration with validation checks

type Modal interface {
	ID() string
	Draw(dim boxlayout.Dimensions) error
	HandleKey(key any, mod gocui.Modifier) error
	OnClose()
	// AcceptsTextInput reports whether the modal uses keyboard input for text entry
	// (e.g. InputModal). When true, single-character keys like 'q' are not treated
	// as close commands.
	AcceptsTextInput() bool
	// ClosesOnEnter reports whether pressing Enter should close the modal
	// (e.g. MessageModal). When false, Enter is forwarded to HandleKey instead.
	ClosesOnEnter() bool
}

Modal represents a modal dialog

type Panel

type Panel interface {
	ID() string
	Draw(dim boxlayout.Dimensions) error
	OnFocus()
	OnBlur()
}

type StudioController added in v0.3.1

type StudioController struct {
	// contains filtered or unexported fields
}

StudioController handles Prisma Studio toggle operations.

func NewStudioController added in v0.3.1

func NewStudioController(
	c types.IControllerHost,
	g *gocui.Gui,
	outputCtx *context.OutputContext,
	openModal func(Modal),
) *StudioController

NewStudioController creates a new StudioController.

func (*StudioController) GetStudioCmd added in v0.3.1

func (sc *StudioController) GetStudioCmd() *commands.Command

GetStudioCmd returns the running studio command (for cleanup on app exit).

func (*StudioController) IsStudioRunning added in v0.3.1

func (sc *StudioController) IsStudioRunning() bool

IsStudioRunning returns whether Prisma Studio is currently running.

func (*StudioController) Studio added in v0.3.1

func (sc *StudioController) Studio()

Studio toggles Prisma Studio

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL