context

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPadding int = 2
)

Variables

Functions

func CloneContext

func CloneContext(ctx context.Context) context.Context

CloneContext creates a shallow copy of the existing context while preserving all keys and values

func CloneStateAndPushPage

func CloneStateAndPushPage[S CloneableState[S]](ctx context.Context, page tea.Model) context.Context

CloneStateAndPushPage clones the current state and pushes the current page-state pair onto the context (non-pointer version)

func GetCurrentModel

func GetCurrentModel(ctx context.Context) tea.Model

GetCurrentModel retrieves the current model from the context

func GetCurrentState

func GetCurrentState[S any](ctx context.Context) S

GetCurrentState retrieves the current state from the context and panics if not found (a non-pointer version)

func GetInitiaConfigDirectory

func GetInitiaConfigDirectory(ctx context.Context) (string, error)

func GetInitiaDataDirectory

func GetInitiaDataDirectory(ctx context.Context) (string, error)

func GetInitiaHome

func GetInitiaHome(ctx context.Context) (string, error)

func GetMinitiaArtifactsConfigJson

func GetMinitiaArtifactsConfigJson(ctx context.Context) (string, error)

func GetMinitiaArtifactsJson

func GetMinitiaArtifactsJson(ctx context.Context) (string, error)

func GetMinitiaHome

func GetMinitiaHome(ctx context.Context) (string, error)

func GetOPInitHome

func GetOPInitHome(ctx context.Context) (string, error)

func GetOPInitKeyFileJson added in v0.1.2

func GetOPInitKeyFileJson(ctx context.Context) (string, error)

func GetTooltip

func GetTooltip(ctx context.Context) bool

GetTooltip retrieves the boolean value for showing or hiding tooltip information from the context

func GetWindowWidth

func GetWindowWidth(ctx context.Context) int

func HandleCommonCommands

func HandleCommonCommands[S CloneableState[S]](model BaseModelInterface, msg tea.Msg) (tea.Model, tea.Cmd, bool)

func NewAppContext

func NewAppContext[S CloneableState[S]](initialState S) context.Context

NewAppContext initializes a new context with a generic state.

func PushPageAndGetState

func PushPageAndGetState[S CloneableState[S]](baseModel BaseModelInterface) S

func PushPageState

func PushPageState[S CloneableState[S]](ctx context.Context, page tea.Model, state S) context.Context

PushPageState pushes the current page and state onto the stack in the context

func SetCurrentModel

func SetCurrentModel(ctx context.Context, currentModel tea.Model) context.Context

SetCurrentModel updates the current model in the context

func SetCurrentState

func SetCurrentState[S any](ctx context.Context, state S) context.Context

SetCurrentState stores the current state in the context using StateKey (non-pointer version)

func SetInitiaHome

func SetInitiaHome(ctx context.Context, initiaHome string) context.Context

func SetMinitiaHome

func SetMinitiaHome(ctx context.Context, minitiaHome string) context.Context

func SetOPInitHome

func SetOPInitHome(ctx context.Context, opInitHome string) context.Context

func SetTooltip

func SetTooltip(ctx context.Context, showTooltip bool) context.Context

SetTooltip sets the boolean value for showing or hiding tooltip information in the context

func SetWindowWidth

func SetWindowWidth(ctx context.Context, windowWidth int) context.Context

func ToggleTooltip

func ToggleTooltip(ctx context.Context, msg tea.Msg) (context.Context, bool)

ToggleTooltip toggles the "tooltip" flag in the context for showing tooltips.

func ToggleTooltipInContext

func ToggleTooltipInContext(ctx context.Context) context.Context

func Undo

func Undo[S CloneableState[S]](ctx context.Context, msg tea.Msg) (context.Context, tea.Model, tea.Cmd, bool)

Undo handles the undo functionality

Types

type BaseModel

type BaseModel struct {
	Ctx        context.Context
	CannotBack bool
	PanicText  string
}

BaseModel provides common functionality for all context-aware models

func (*BaseModel) CanGoPreviousPage

func (b *BaseModel) CanGoPreviousPage() bool

func (*BaseModel) GetContext

func (b *BaseModel) GetContext() context.Context

GetContext retrieves the context from BaseModel

func (*BaseModel) HandlePanic

func (b *BaseModel) HandlePanic(err error) tea.Cmd

func (*BaseModel) SetContext

func (b *BaseModel) SetContext(ctx context.Context)

SetContext set the context from BaseModel

func (*BaseModel) WrapView

func (b *BaseModel) WrapView(content string) string

type BaseModelInterface

type BaseModelInterface interface {
	tea.Model
	SetContext(ctx context.Context)
	GetContext() context.Context
	CanGoPreviousPage() bool
	WrapView(content string) string
	HandlePanic(err error) tea.Cmd
}

BaseModelInterface is an interface for base models

func AdjustWindowSize

func AdjustWindowSize(model BaseModelInterface, msg tea.Msg) BaseModelInterface

type CloneableState

type CloneableState[S any] interface {
	Clone() S
}

CloneableState is an interface that requires the Clone method

type Key

type Key string

Key is a custom type to prevent key collisions in the context

const (
	PageKey          Key = "currentPage"
	StateKey         Key = "currentState"
	PageStackKey     Key = "pageStack"
	TooltipToggleKey Key = "tooltipToggle"
	WindowWidth      Key = "windowWidth"

	InitiaHomeKey  Key = "initiaHome"
	MinitiaHomeKey Key = "minitiaHome"
	OPInitHomeKey  Key = "opInitHomeKey"
)

type PageStatePair

type PageStatePair[S CloneableState[S]] struct {
	Page  tea.Model
	State S
}

PageStatePair is a generic struct that holds a pair of page (model) and its associated state.

func GetPageStack

func GetPageStack[S CloneableState[S]](ctx context.Context) []PageStatePair[S]

GetPageStack retrieves the page-state stack from the context

func PopPageState

func PopPageState[S CloneableState[S]](ctx context.Context) (context.Context, *PageStatePair[S])

PopPageState pops the last page-state pair from the stack

Jump to

Keyboard shortcuts

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