types

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 16 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
	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

	// If true, the keybinding will appear at the bottom of the screen. If
	// the given view has no bindings with Display: true, the default keybindings
	// will be displayed instead.
	// TODO: implement this
	Display 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
	HasLoader           bool
	FindSuggestionsFunc func(string) []*Suggestion
	Editable            bool
	Mask                bool
}

type Context added in v0.35.0

type Context interface {
	IBaseContext

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

type ContextCommon added in v0.39.0

type ContextCommon struct {
	*common.Common
	IGuiCommon
}

type ContextKey added in v0.35.0

type ContextKey string

type ContextKind added in v0.35.0

type ContextKind int
const (
	// this is your files, branches, commits, contexts etc. They're all on the left hand side
	// and you can cycle through them.
	SIDE_CONTEXT ContextKind = iota
	// This is either the left or right 'main' contexts that appear to the right of the side contexts
	MAIN_CONTEXT
	// A persistent popup is one that has its own identity e.g. the commit message context.
	// When you open a popup over it, we'll let you return to it upon pressing escape
	PERSISTENT_POPUP
	// A temporary popup is one that could be used for various things (e.g. a generic menu or confirmation popup).
	// Because we re-use these contexts, they're temporary in that you can't return to them after you've switched from them
	// to some other context, because the context you switched to might actually be the same context but rendering different content.
	// We should really be able to spawn new contexts for menus/prompts so that we can actually return to old ones.
	TEMPORARY_POPUP
	// This contains the command log, underneath the main contexts.
	EXTRAS_CONTEXT
	// only used by the one global context, purely for the sake of defining keybindings globally
	GLOBAL_CONTEXT
	// a display context only renders a view. It has no keybindings associated and
	// it cannot receive focus.
	DISPLAY_CONTEXT
)

type CreateMenuOptions added in v0.35.0

type CreateMenuOptions struct {
	Title           string
	Items           []*MenuItem
	HideCancel      bool
	ColumnAlignment []utils.Alignment
}

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

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

type DiffableContext added in v0.39.0

type DiffableContext interface {
	Context

	// Returns the current diff terminals of the currently selected item.
	// in the case of a branch it returns both the branch and it's upstream name,
	// which becomes an option when you bring up the diff menu, but when you're just
	// flicking through branches it will be using the local branch name.
	GetDiffTerminals() []string
}

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
	GetOnRenderToMain() func() error
	GetOnFocus() func(OnFocusOpts) error
	GetOnFocusLost() func(OnFocusLostOpts) error
}

type HelperCommon added in v0.35.0

type HelperCommon struct {
	*ContextCommon
}

type IBaseContext added in v0.35.0

type IBaseContext interface {
	HasKeybindings
	ParentContexter

	GetKind() ContextKind
	GetViewName() string
	GetView() *gocui.View
	GetViewTrait() IViewTrait
	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
	// this tells us if the view's bounds are determined by its window or if they're
	// determined independently.
	HasControlledBounds() 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)

	AddOnRenderToMainFn(func() error)
	AddOnFocusFn(func(OnFocusOpts) error)
	AddOnFocusLostFn(func(OnFocusLostOpts) error)
}

type IContextMgr added in v0.39.0

type IContextMgr interface {
	Push(context Context, opts ...OnFocusOpts) error
	Pop() error
	Replace(context Context) error
	Current() Context
	CurrentStatic() Context
	CurrentSide() Context
	IsCurrent(c Context) bool
	ForEach(func(Context))
	AllList() []IListContext
	AllFilterable() []IFilterableContext
	AllSearchable() []ISearchableContext
	AllPatchExplorer() []IPatchExplorerContext
}

type IController added in v0.35.0

type IController interface {
	HasKeybindings
	Context() Context
}

type IFileWatcher added in v0.39.0

type IFileWatcher interface {
	AddFilesToFileWatcher(files []*models.File) error
}

type IFilterableContext added in v0.39.0

type IFilterableContext interface {
	Context
	IListPanelState

	SetFilter(string)
	GetFilter() string
	ClearFilter()
	IsFiltering() bool
	IsFilterableContext()
}

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

	// renders string to a view without resetting its origin
	SetViewContent(view *gocui.View, content string)
	// resets cursor and origin of view. Often used before calling SetViewContent
	ResetViewOrigin(view *gocui.View)

	// this just re-renders the screen
	Render()
	// allows rendering to main views (i.e. the ones to the right of the side panel)
	// in such a way that avoids concurrency issues when there are slow commands
	// to display the output of
	RenderToMainViews(opts RefreshMainOpts) error
	// used purely for the sake of RenderToMainViews to provide the pair of main views we want to render to
	MainViewPairs() MainViewPairs

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

	PushContext(context Context, opts ...OnFocusOpts) error
	PopContext() error
	ReplaceContext(context Context) error
	// Removes all given contexts from the stack. If a given context is not in the stack, it is ignored.
	// This is for when you have a group of contexts that are bundled together e.g. with the commit message panel.
	// If you want to remove a single context, you should probably use PopContext instead.
	RemoveContexts([]Context) error
	CurrentContext() Context
	CurrentStaticContext() Context
	CurrentSideContext() Context
	IsCurrentContext(Context) bool
	// TODO: replace the above context-based methods with just using Context() e.g. replace PushContext() with Context().Push()
	Context() IContextMgr

	ActivateContext(context Context) error

	GetConfig() config.AppConfigurer
	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)
	// Runs a function in a goroutine. Use this whenever you want to run a goroutine and keep track of the fact
	// that lazygit is still busy. See docs/dev/Busy.md
	OnWorker(f func(gocui.Task))
	// Function to call at the end of our 'layout' function which renders views
	// For example, you may want a view's line to be focused only after that view is
	// resized, if in accordion mode.
	AfterLayout(f func() error)

	// returns the gocui Gui struct. There is a good chance you don't actually want to use
	// this struct and instead want to use another method above
	GocuiGui() *gocui.Gui

	Views() Views

	Git() *commands.GitCommand
	OS() *oscommands.OSCommand
	Model() *Model

	Modes() *Modes

	Mutexes() Mutexes

	State() IStateAccessor

	KeybindingsOpts() KeybindingsOpts

	// hopefully we can remove this once we've moved all our keybinding stuff out of the gui god struct.
	GetInitialKeybindingsWithCustomCommands() ([]*Binding, []*gocui.ViewMouseBinding)
}

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

	FocusLine()
	IsListContext() // used for type switch
}

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 IModeMgr added in v0.39.0

type IModeMgr interface {
	IsAnyModeActive() bool
}

type IPatchExplorerContext added in v0.36.0

type IPatchExplorerContext interface {
	Context

	GetState() *patch_exploring.State
	SetState(*patch_exploring.State)
	GetIncludedLineIndices() []int
	RenderAndFocus(isFocused bool) error
	Render(isFocused bool) error
	Focus() error
	GetContentToRender(isFocused bool) string
	NavigateTo(isFocused bool, selectedLineIdx int) error
	GetMutex() *deadlock.Mutex
	IsPatchExplorerContext() // used for type switch
}

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(gocui.Task) error) error
	WithWaitingStatus(message string, f func(gocui.Task) error) error
	Menu(opts CreateMenuOptions) error
	Toast(message string)
	GetPromptInput() string
}

type IRepoStateAccessor added in v0.39.0

type IRepoStateAccessor interface {
	GetViewsSetup() bool
	GetWindowViewNameMap() *utils.ThreadSafeMap[string, string]
	GetStartupStage() StartupStage
	SetStartupStage(stage StartupStage)
	GetCurrentPopupOpts() *CreatePopupPanelOpts
	SetCurrentPopupOpts(*CreatePopupPanelOpts)
	GetScreenMode() WindowMaximisation
	SetScreenMode(WindowMaximisation)
	InSearchPrompt() bool
	GetSearchState() *SearchState
	SetSplitMainPanel(bool)
	GetSplitMainPanel() bool
}

type ISearchableContext added in v0.39.0

type ISearchableContext interface {
	Context

	SetSearchString(string)
	GetSearchString() string
	ClearSearchString()
	IsSearching() bool
	IsSearchableContext()
}

type IStateAccessor added in v0.39.0

type IStateAccessor interface {
	GetIgnoreWhitespaceInDiffView() bool
	SetIgnoreWhitespaceInDiffView(value bool)
	GetRepoPathStack() *utils.StringStack
	GetRepoState() IRepoStateAccessor
	// tells us whether we're currently updating lazygit
	GetUpdating() bool
	SetUpdating(bool)
	SetIsRefreshingFiles(bool)
	GetIsRefreshingFiles() bool
	GetShowExtrasWindow() bool
	SetShowExtrasWindow(bool)
	GetRetainOriginalDir() bool
	SetRetainOriginalDir(bool)
}

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(value int)
	ScrollDown(value int)
	PageDelta() int
	SelectedLineIdx() int
	SetHighlight(bool)
}

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 MainContextPair added in v0.36.0

type MainContextPair struct {
	Main      Context
	Secondary Context
}

func NewMainContextPair added in v0.36.0

func NewMainContextPair(main Context, secondary Context) MainContextPair

type MainViewPairs added in v0.36.0

type MainViewPairs struct {
	Normal         MainContextPair
	MergeConflicts MainContextPair
	Staging        MainContextPair
	PatchBuilding  MainContextPair
}
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
	WorkingTreeStateAtLastCommitRefresh enums.RebaseMode
	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 Mutexes added in v0.36.0

type Mutexes struct {
	RefreshingFilesMutex    *deadlock.Mutex
	RefreshingBranchesMutex *deadlock.Mutex
	RefreshingStatusMutex   *deadlock.Mutex
	SyncMutex               *deadlock.Mutex
	LocalCommitsMutex       *deadlock.Mutex
	SubCommitsMutex         *deadlock.Mutex
	SubprocessMutex         *deadlock.Mutex
	PopupMutex              *deadlock.Mutex
	PtyMutex                *deadlock.Mutex
}

if you add a new mutex here be sure to instantiate it. We're using pointers to mutexes so that we can pass the mutexes to controllers.

type OnFocusLostOpts added in v0.36.0

type OnFocusLostOpts struct {
	NewContextKey ContextKey
}

type OnFocusOpts added in v0.35.0

type OnFocusOpts struct {
	ClickedWindowName  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 RefreshMainOpts added in v0.36.0

type RefreshMainOpts struct {
	Pair      MainContextPair
	Main      *ViewUpdateOpts
	Secondary *ViewUpdateOpts
}

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. []RefreshableView{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
	SUB_COMMITS
	BRANCHES
	FILES
	STASH
	REFLOG
	TAGS
	REMOTES
	STATUS
	SUBMODULES
	STAGING
	PATCH_BUILDING
	MERGE_CONFLICTS
	COMMIT_FILES
	// not actually a view. Will refactor this later
	BISECT_INFO
)

type RenderStringTask added in v0.36.0

type RenderStringTask struct {
	Str string
}

func NewRenderStringTask added in v0.36.0

func NewRenderStringTask(str string) *RenderStringTask

func (*RenderStringTask) IsUpdateTask added in v0.36.0

func (t *RenderStringTask) IsUpdateTask()

type RenderStringWithScrollTask added in v0.36.0

type RenderStringWithScrollTask struct {
	Str     string
	OriginX int
	OriginY int
}

func NewRenderStringWithScrollTask added in v0.36.0

func NewRenderStringWithScrollTask(str string, originX int, originY int) *RenderStringWithScrollTask

func (*RenderStringWithScrollTask) IsUpdateTask added in v0.36.0

func (t *RenderStringWithScrollTask) IsUpdateTask()

type RenderStringWithoutScrollTask added in v0.36.0

type RenderStringWithoutScrollTask struct {
	Str string
}

func NewRenderStringWithoutScrollTask added in v0.36.0

func NewRenderStringWithoutScrollTask(str string) *RenderStringWithoutScrollTask

func (*RenderStringWithoutScrollTask) IsUpdateTask added in v0.36.0

func (t *RenderStringWithoutScrollTask) IsUpdateTask()

type RunCommandTask added in v0.36.0

type RunCommandTask struct {
	Cmd    *exec.Cmd
	Prefix string
}

func NewRunCommandTask added in v0.36.0

func NewRunCommandTask(cmd *exec.Cmd) *RunCommandTask

func NewRunCommandTaskWithPrefix added in v0.36.0

func NewRunCommandTaskWithPrefix(cmd *exec.Cmd, prefix string) *RunCommandTask

func (*RunCommandTask) IsUpdateTask added in v0.36.0

func (t *RunCommandTask) IsUpdateTask()

type RunPtyTask added in v0.36.0

type RunPtyTask struct {
	Cmd    *exec.Cmd
	Prefix string
}

func NewRunPtyTask added in v0.36.0

func NewRunPtyTask(cmd *exec.Cmd) *RunPtyTask

func (*RunPtyTask) IsUpdateTask added in v0.36.0

func (t *RunPtyTask) IsUpdateTask()

type SearchState added in v0.39.0

type SearchState struct {
	Context Context
}

TODO: could we remove this entirely?

func NewSearchState added in v0.39.0

func NewSearchState() *SearchState

func (*SearchState) SearchType added in v0.39.0

func (self *SearchState) SearchType() SearchType

type SearchType added in v0.39.0

type SearchType int
const (
	SearchTypeNone SearchType = iota
	// searching is where matches are highlighted but the content is not filtered down
	SearchTypeSearch
	// filter is where the list is filtered down to only matches
	SearchTypeFilter
)

type StartupStage added in v0.39.0

type StartupStage int

startup stages so we don't need to load everything at once

const (
	INITIAL StartupStage = iota
	COMPLETE
)

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
}

type UpdateTask added in v0.36.0

type UpdateTask interface {
	IsUpdateTask()
}

type ViewUpdateOpts added in v0.36.0

type ViewUpdateOpts struct {
	Title    string
	SubTitle string

	Task UpdateTask
}

type Views added in v0.39.0

type Views struct {
	Status         *gocui.View
	Submodules     *gocui.View
	Files          *gocui.View
	Branches       *gocui.View
	Remotes        *gocui.View
	Tags           *gocui.View
	RemoteBranches *gocui.View
	ReflogCommits  *gocui.View
	Commits        *gocui.View
	Stash          *gocui.View

	Main                   *gocui.View
	Secondary              *gocui.View
	Staging                *gocui.View
	StagingSecondary       *gocui.View
	PatchBuilding          *gocui.View
	PatchBuildingSecondary *gocui.View
	MergeConflicts         *gocui.View

	Options           *gocui.View
	Confirmation      *gocui.View
	Menu              *gocui.View
	CommitMessage     *gocui.View
	CommitDescription *gocui.View
	CommitFiles       *gocui.View
	SubCommits        *gocui.View
	Information       *gocui.View
	AppStatus         *gocui.View
	Search            *gocui.View
	SearchPrefix      *gocui.View
	Limit             *gocui.View
	Suggestions       *gocui.View
	Tooltip           *gocui.View
	Extras            *gocui.View

	// for playing the easter egg snake game
	Snake *gocui.View
}

type WindowMaximisation added in v0.39.0

type WindowMaximisation int

screen sizing determines how much space your selected window takes up (window as in panel, not your terminal's window). Sometimes you want a bit more space to see the contents of a panel, and this keeps track of how much maximisation you've set

const (
	SCREEN_NORMAL WindowMaximisation = iota
	SCREEN_HALF
	SCREEN_FULL
)

Jump to

Keyboard shortcuts

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