types

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding added in v0.35.0

type Binding struct {
	ViewName    string
	Contexts    []string
	Handler     func() error
	Key         Key
	Modifier    gocui.Modifier
	Description string
	Alternative string
	Tag         string // e.g. 'navigation'. Used for grouping things in the cheatsheet
	OpensMenu   bool

	// to be displayed if the keybinding is highlighted from within a menu
	Tooltip string
}

Binding - a keybinding mapping a key and modifier to a handler. The keypress is only handled if the given view has focus, or handled globally if the view is ""

type CheckoutRefOptions added in v0.35.0

type CheckoutRefOptions struct {
	WaitingStatus string
	EnvVars       []string
	OnRefNotFound func(ref string) error
}

type ConfirmOpts added in v0.35.0

type ConfirmOpts struct {
	Title               string
	Prompt              string
	HandleConfirm       func() error
	HandleClose         func() error
	HandlersManageFocus bool
}

type Context added in v0.35.0

type Context interface {
	IBaseContext

	HandleFocus(opts ...OnFocusOpts) error
	HandleFocusLost() error
	HandleRender() error
	HandleRenderToMain() error
}

type ContextKey added in v0.35.0

type ContextKey string

type ContextKind added in v0.35.0

type ContextKind int
const (
	SIDE_CONTEXT ContextKind = iota
	MAIN_CONTEXT
	TEMPORARY_POPUP
	PERSISTENT_POPUP
	EXTRAS_CONTEXT
	// only used by the one global context
	GLOBAL_CONTEXT
)

type CreateMenuOptions added in v0.35.0

type CreateMenuOptions struct {
	Title      string
	Items      []*MenuItem
	HideCancel bool
}

type CreatePopupPanelOpts added in v0.35.0

type CreatePopupPanelOpts struct {
	HasLoader           bool
	Editable            bool
	Title               string
	Prompt              string
	HandleConfirm       func() error
	HandleConfirmPrompt func(string) error
	HandleClose         func() error

	// when HandlersManageFocus is true, do not return from the confirmation context automatically. It's expected that the handlers will manage focus, whether that means switching to another context, or manually returning the context.
	HandlersManageFocus bool

	FindSuggestionsFunc func(string) []*Suggestion
	Mask                bool
}

type GitArg added in v0.35.0

type GitArg string
const (
	GitArgNone   GitArg = ""
	GitArgStatus GitArg = "status"
	GitArgBranch GitArg = "branch"
	GitArgLog    GitArg = "log"
	GitArgStash  GitArg = "stash"
)

type Guard added in v0.35.0

type Guard func(func() error) func() error

A guard is a decorator which checks something before executing a handler and potentially early-exits if some precondition hasn't been met.

type HasKeybindings added in v0.35.0

type HasKeybindings interface {
	GetKeybindings(opts KeybindingsOpts) []*Binding
	GetMouseKeybindings(opts KeybindingsOpts) []*gocui.ViewMouseBinding
	GetOnClick() func() error
}

type HelperCommon added in v0.35.0

type HelperCommon struct {
	*common.Common
	IGuiCommon
}

type IBaseContext added in v0.35.0

type IBaseContext interface {
	HasKeybindings
	ParentContexter

	GetKind() ContextKind
	GetViewName() string
	GetWindowName() string
	SetWindowName(string)
	GetKey() ContextKey
	IsFocusable() bool
	// if a context is transient, then it only appears via some keybinding on another
	// context. Until we add support for having multiple of the same context, no two
	// of the same transient context can appear at once meaning one might be 'stolen'
	// from another window.
	IsTransient() bool

	// returns the desired title for the view upon activation. If there is no desired title (returns empty string), then
	// no title will be set
	Title() string

	GetOptionsMap() map[string]string

	AddKeybindingsFn(KeybindingsFn)
	AddMouseKeybindingsFn(MouseKeybindingsFn)

	// This is a bit of a hack at the moment: we currently only set an onclick function so that
	// our list controller can come along and wrap it in a list-specific click handler.
	// We'll need to think of a better way to do this.
	AddOnClickFn(func() error)
}

type IController added in v0.35.0

type IController interface {
	HasKeybindings
	Context() Context
}

type IGuiCommon added in v0.35.0

type IGuiCommon interface {
	IPopupHandler

	LogAction(action string)
	LogCommand(cmdStr string, isCommandLine bool)
	// we call this when we want to refetch some models and render the result. Internally calls PostRefreshUpdate
	Refresh(RefreshOptions) error
	// we call this when we've changed something in the view model but not the actual model,
	// e.g. expanding or collapsing a folder in a file view. Calling 'Refresh' in this
	// case would be overkill, although refresh will internally call 'PostRefreshUpdate'
	PostRefreshUpdate(Context) error
	// this just re-renders the screen
	Render()

	// returns true if command completed successfully
	RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error)
	RunSubprocessAndRefresh(oscommands.ICmdObj) error

	PushContext(context Context, opts ...OnFocusOpts) error
	PopContext() error
	CurrentContext() Context
	// enters search mode for the current view
	OpenSearch()

	GetAppState() *config.AppState
	SaveAppState() error

	// Runs the given function on the UI thread (this is for things like showing a popup asking a user for input).
	// Only necessary to call if you're not already on the UI thread i.e. you're inside a goroutine.
	// All controller handlers are executed on the UI thread.
	OnUIThread(f func() error)
}

type IList added in v0.35.0

type IList interface {
	IListCursor
	Len() int
}

type IListContext added in v0.35.0

type IListContext interface {
	Context

	GetSelectedItemId() string

	GetList() IList

	OnSearchSelect(selectedLineIdx int) error
	FocusLine()

	GetViewTrait() IViewTrait
}

type IListCursor added in v0.35.0

type IListCursor interface {
	GetSelectedLineIdx() int
	SetSelectedLineIdx(value int)
	MoveSelectedLine(delta int)
	RefreshSelectedIdx()
}

type IListPanelState added in v0.35.0

type IListPanelState interface {
	SetSelectedLineIdx(int)
	GetSelectedLineIdx() int
}

type IPopupHandler added in v0.35.0

type IPopupHandler interface {
	// Shows a popup with a (localized) "Error" caption and the given error message (in red).
	//
	// This is a convenience wrapper around Alert().
	ErrorMsg(message string) error
	Error(err error) error
	// Shows a notification popup with the given title and message to the user.
	//
	// This is a convenience wrapper around Confirm(), thus the popup can be closed using both 'Enter' and 'ESC'.
	Alert(title string, message string) error
	// Shows a popup asking the user for confirmation.
	Confirm(opts ConfirmOpts) error
	// Shows a popup prompting the user for input.
	Prompt(opts PromptOpts) error
	WithLoaderPanel(message string, f func() error) error
	WithWaitingStatus(message string, f func() error) error
	Menu(opts CreateMenuOptions) error
	Toast(message string)
	GetPromptInput() string
}

type IViewTrait added in v0.35.0

type IViewTrait interface {
	FocusPoint(yIdx int)
	SetViewPortContent(content string)
	SetContent(content string)
	SetFooter(value string)
	SetOriginX(value int)
	ViewPortYBounds() (int, int)
	ScrollLeft()
	ScrollRight()
	ScrollUp()
	ScrollDown()
	PageDelta() int
	SelectedLineIdx() int
}

type Key added in v0.35.0

type Key interface{} // FIXME: find out how to get `gocui.Key | rune`

type KeybindingGuards added in v0.35.0

type KeybindingGuards struct {
	OutsideFilterMode Guard
	NoPopupPanel      Guard
}

type KeybindingsFn added in v0.35.0

type KeybindingsFn func(opts KeybindingsOpts) []*Binding

type KeybindingsOpts added in v0.35.0

type KeybindingsOpts struct {
	GetKey func(key string) Key
	Config config.KeybindingConfig
	Guards KeybindingGuards
}

type ListItem added in v0.35.0

type ListItem interface {
	// ID is a SHA when the item is a commit, a filename when the item is a file, 'stash@{4}' when it's a stash entry, 'my_branch' when it's a branch
	ID() string

	// Description is something we would show in a message e.g. '123as14: push blah' for a commit
	Description() string
}
type MenuItem struct {
	Label string

	// alternative to Label. Allows specifying columns which will be auto-aligned
	LabelColumns []string

	OnPress func() error

	// Only applies when Label is used
	OpensMenu bool

	// If Key is defined it allows the user to press the key to invoke the menu
	// item, as opposed to having to navigate to it
	Key Key

	// The tooltip will be displayed upon highlighting the menu item
	Tooltip string
}

type Model added in v0.35.0

type Model struct {
	CommitFiles  []*models.CommitFile
	Files        []*models.File
	Submodules   []*models.SubmoduleConfig
	Branches     []*models.Branch
	Commits      []*models.Commit
	StashEntries []*models.StashEntry
	SubCommits   []*models.Commit
	Remotes      []*models.Remote

	// FilteredReflogCommits are the ones that appear in the reflog panel.
	// when in filtering mode we only include the ones that match the given path
	FilteredReflogCommits []*models.Commit
	// ReflogCommits are the ones used by the branches panel to obtain recency values
	// if we're not in filtering mode, CommitFiles and FilteredReflogCommits will be
	// one and the same
	ReflogCommits []*models.Commit

	BisectInfo     *git_commands.BisectInfo
	RemoteBranches []*models.RemoteBranch
	Tags           []*models.Tag

	// for displaying suggestions while typing in a file name
	FilesTrie *patricia.Trie
}

type Modes added in v0.35.0

type Modes struct {
	Filtering     filtering.Filtering
	CherryPicking *cherrypicking.CherryPicking
	Diffing       diffing.Diffing
}

type MouseKeybindingsFn added in v0.35.0

type MouseKeybindingsFn func(opts KeybindingsOpts) []*gocui.ViewMouseBinding

type OnFocusOpts added in v0.35.0

type OnFocusOpts struct {
	ClickedViewName    string
	ClickedViewLineIdx int
}

type ParentContexter added in v0.35.0

type ParentContexter interface {
	SetParentContext(Context)
	// we return a bool here to tell us whether or not the returned value just wraps a nil
	GetParentContext() (Context, bool)
}

type PromptOpts added in v0.35.0

type PromptOpts struct {
	Title               string
	InitialContent      string
	FindSuggestionsFunc func(string) []*Suggestion
	HandleConfirm       func(string) error
	// CAPTURE THIS
	HandleClose func() error
	Mask        bool
}

type Ref added in v0.35.0

type Ref interface {
	FullRefName() string
	RefName() string
	ParentRefName() string
	Description() string
}

type RefreshMode added in v0.35.0

type RefreshMode int
const (
	SYNC     RefreshMode = iota // wait until everything is done before returning
	ASYNC                       // return immediately, allowing each independent thing to update itself
	BLOCK_UI                    // wrap code in an update call to ensure UI updates all at once and keybindings aren't executed till complete
)

type RefreshOptions added in v0.35.0

type RefreshOptions struct {
	Then  func()
	Scope []RefreshableView // e.g. []int{COMMITS, BRANCHES}. Leave empty to refresh everything
	Mode  RefreshMode       // one of SYNC (default), ASYNC, and BLOCK_UI
}

type RefreshableView added in v0.35.0

type RefreshableView int

models/views that we can refresh

const (
	COMMITS RefreshableView = iota
	REBASE_COMMITS
	BRANCHES
	FILES
	STASH
	REFLOG
	TAGS
	REMOTES
	STATUS
	SUBMODULES
	// not actually a view. Will refactor this later
	BISECT_INFO
)

type StartArgs added in v0.35.0

type StartArgs struct {
	// FilterPath determines which path we're going to filter on so that we only see commits from that file.
	FilterPath string
	// GitArg determines what context we open in
	GitArg GitArg
}

StartArgs is the struct that represents some things we want to do on program start

func NewStartArgs added in v0.35.0

func NewStartArgs(filterPath string, gitArg GitArg) StartArgs

type Suggestion

type Suggestion struct {
	// value is the thing that we're matching on and the thing that will be submitted if you select the suggestion
	Value string
	// label is what is actually displayed so it can e.g. contain color
	Label string
}

Jump to

Keyboard shortcuts

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