gui

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: MIT Imports: 54 Imported by: 1

Documentation

Index

Constants

View Source
const (
	REBASE_OPTION_CONTINUE = "continue"
	REBASE_OPTION_ABORT    = "abort"
	REBASE_OPTION_SKIP     = "skip"
)
View Source
const COMMIT_THRESHOLD = 200

after selecting the 200th commit, we'll load in all the rest

View Source
const HORIZONTAL_SCROLL_FACTOR = 3
View Source
const INFO_SECTION_PADDING = " "
View Source
const MAX_WATCHED_FILES = 50

macs for some bizarre reason cap the number of watchable files to 256. there's no obvious platform agnostic way to check the situation of the user's computer so we're just arbitrarily capping at 200. This isn't so bad because file watching is only really an added bonus for faster refreshing.

View Source
const SEARCH_PREFIX = "search: "
View Source
const StartupPopupVersion = 5
View Source
const UNKNOWN_VIEW_ERROR_MSG = "unknown view"

Variables

View Source
var OverlappingEdges = false

OverlappingEdges determines if panel edges overlap

View Source
var RuneReplacements = map[rune]string{

	graph.MergeSymbol:  "M",
	graph.CommitSymbol: "o",
}

Functions

func GetKeyDisplay added in v0.12.1

func GetKeyDisplay(key interface{}) string

func NewDummyUpdater added in v0.30.1

func NewDummyUpdater() *updates.Updater

NewDummyGui creates a new dummy GUI for testing

func NewFileWatcher added in v0.12.1

func NewFileWatcher(log *logrus.Entry) *fileWatcher

func NewRenderStringTask added in v0.27.1

func NewRenderStringTask(str string) *renderStringTask

func NewRenderStringWithoutScrollTask added in v0.27.1

func NewRenderStringWithoutScrollTask(str string) *renderStringWithoutScrollTask

func NewRunCommandTask added in v0.27.1

func NewRunCommandTask(cmd *exec.Cmd) *runCommandTask

func NewRunCommandTaskWithPrefix added in v0.27.1

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

func NewRunPtyTask added in v0.27.1

func NewRunPtyTask(cmd *exec.Cmd) *runPtyTask

Types

type BasicContext added in v0.22.0

type BasicContext struct {
	OnFocus         func() error
	OnFocusLost     func() error
	OnRender        func() error
	Kind            ContextKind
	Key             ContextKey
	ViewName        string
	WindowName      string
	OnGetOptionsMap func() map[string]string

	ParentContext Context
	// contains filtered or unexported fields
}

func (*BasicContext) GetKey added in v0.22.0

func (c *BasicContext) GetKey() ContextKey

func (*BasicContext) GetKind added in v0.22.0

func (c *BasicContext) GetKind() ContextKind

func (*BasicContext) GetOptionsMap added in v0.22.0

func (c *BasicContext) GetOptionsMap() map[string]string

func (*BasicContext) GetParentContext added in v0.22.0

func (c *BasicContext) GetParentContext() (Context, bool)

func (*BasicContext) GetViewName added in v0.22.0

func (c *BasicContext) GetViewName() string

func (*BasicContext) GetWindowName added in v0.22.0

func (c *BasicContext) GetWindowName() string

func (*BasicContext) HandleFocus added in v0.22.0

func (c *BasicContext) HandleFocus() error

func (*BasicContext) HandleFocusLost added in v0.22.0

func (c *BasicContext) HandleFocusLost() error

func (*BasicContext) HandleRender added in v0.22.0

func (c *BasicContext) HandleRender() error

func (*BasicContext) SetParentContext added in v0.22.0

func (c *BasicContext) SetParentContext(context Context)

func (*BasicContext) SetWindowName added in v0.22.0

func (c *BasicContext) SetWindowName(windowName string)

type Binding

type Binding struct {
	ViewName    string
	Contexts    []string
	Handler     func() error
	Key         interface{} // FIXME: find out how to get `gocui.Key | rune`
	Modifier    gocui.Modifier
	Description string
	Alternative string
	Tag         string // e.g. 'navigation'. Used for grouping things in the cheatsheet
	OpensMenu   bool
}

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 ""

func (*Binding) GetDisplayStrings added in v0.3.0

func (b *Binding) GetDisplayStrings(isFocused bool) []string

GetDisplayStrings returns the display string of a file

type Context added in v0.22.0

type Context interface {
	HandleFocus() error
	HandleFocusLost() error
	HandleRender() error
	GetKind() ContextKind
	GetViewName() string
	GetWindowName() string
	SetWindowName(string)
	GetKey() ContextKey
	SetParentContext(Context)

	// we return a bool here to tell us whether or not the returned value just wraps a nil
	GetParentContext() (Context, bool)
	GetOptionsMap() map[string]string
}

type ContextKey added in v0.27.1

type ContextKey string
const (
	STATUS_CONTEXT_KEY              ContextKey = "status"
	FILES_CONTEXT_KEY               ContextKey = "files"
	LOCAL_BRANCHES_CONTEXT_KEY      ContextKey = "localBranches"
	REMOTES_CONTEXT_KEY             ContextKey = "remotes"
	REMOTE_BRANCHES_CONTEXT_KEY     ContextKey = "remoteBranches"
	TAGS_CONTEXT_KEY                ContextKey = "tags"
	BRANCH_COMMITS_CONTEXT_KEY      ContextKey = "commits"
	REFLOG_COMMITS_CONTEXT_KEY      ContextKey = "reflogCommits"
	SUB_COMMITS_CONTEXT_KEY         ContextKey = "subCommits"
	COMMIT_FILES_CONTEXT_KEY        ContextKey = "commitFiles"
	STASH_CONTEXT_KEY               ContextKey = "stash"
	MAIN_NORMAL_CONTEXT_KEY         ContextKey = "normal"
	MAIN_MERGING_CONTEXT_KEY        ContextKey = "merging"
	MAIN_PATCH_BUILDING_CONTEXT_KEY ContextKey = "patchBuilding"
	MAIN_STAGING_CONTEXT_KEY        ContextKey = "staging"
	MENU_CONTEXT_KEY                ContextKey = "menu"
	CREDENTIALS_CONTEXT_KEY         ContextKey = "credentials"
	CONFIRMATION_CONTEXT_KEY        ContextKey = "confirmation"
	SEARCH_CONTEXT_KEY              ContextKey = "search"
	COMMIT_MESSAGE_CONTEXT_KEY      ContextKey = "commitMessage"
	SUBMODULES_CONTEXT_KEY          ContextKey = "submodules"
	SUGGESTIONS_CONTEXT_KEY         ContextKey = "suggestions"
	COMMAND_LOG_CONTEXT_KEY         ContextKey = "cmdLog"
)

type ContextKind added in v0.27.1

type ContextKind int
const (
	SIDE_CONTEXT ContextKind = iota
	MAIN_CONTEXT
	TEMPORARY_POPUP
	PERSISTENT_POPUP
	EXTRAS_CONTEXT
)

type ContextManager added in v0.27.1

type ContextManager struct {
	ContextStack []Context
	sync.RWMutex
}

func NewContextManager added in v0.27.1

func NewContextManager(initialContext Context) ContextManager

type ContextTree added in v0.22.0

type ContextTree struct {
	Status         Context
	Files          IListContext
	Submodules     IListContext
	Menu           IListContext
	Branches       IListContext
	Remotes        IListContext
	RemoteBranches IListContext
	Tags           IListContext
	BranchCommits  IListContext
	CommitFiles    IListContext
	ReflogCommits  IListContext
	SubCommits     IListContext
	Stash          IListContext
	Suggestions    IListContext
	Normal         Context
	Staging        Context
	PatchBuilding  Context
	Merging        Context
	Credentials    Context
	Confirmation   Context
	CommitMessage  Context
	Search         Context
	CommandLog     Context
}

type CustomCommandObjects added in v0.23.1

type CustomCommandObjects struct {
	SelectedLocalCommit    *models.Commit
	SelectedReflogCommit   *models.Commit
	SelectedSubCommit      *models.Commit
	SelectedFile           *models.File
	SelectedPath           string
	SelectedLocalBranch    *models.Branch
	SelectedRemoteBranch   *models.RemoteBranch
	SelectedRemote         *models.Remote
	SelectedTag            *models.Tag
	SelectedStashEntry     *models.StashEntry
	SelectedCommitFile     *models.CommitFile
	SelectedCommitFilePath string
	CheckedOutBranch       *models.Branch
	PromptResponses        []string
}

type Gui

type Gui struct {
	Log        *logrus.Entry
	GitCommand *commands.GitCommand
	OSCommand  *oscommands.OSCommand

	// this is the state of the GUI for the current repo
	State *guiState

	// this is a mapping of repos to gui states, so that we can restore the original
	// gui state when returning from a subrepo
	RepoStateMap map[Repo]*guiState
	Config       config.AppConfigurer
	Tr           *i18n.TranslationSet
	Updater      *updates.Updater

	Mutexes guiMutexes

	// when you enter into a submodule we'll append the superproject's path to this array
	// so that you can return to the superproject
	RepoPathStack []string

	// this tells us whether our views have been initially set up
	ViewsSetup bool

	Views Views

	// if we've suspended the gui (e.g. because we've switched to a subprocess)
	// we typically want to pause some things that are running like background
	// file refreshes
	PauseBackgroundThreads bool

	// Log of the commands that get run, to be displayed to the user.
	CmdLog       []string
	OnRunCommand func(entry oscommands.CmdLogEntry)

	// the extras window contains things like the command log
	ShowExtrasWindow bool
	// contains filtered or unexported fields
}

Gui wraps the gocui Gui object which handles rendering and events

func NewDummyGui added in v0.30.1

func NewDummyGui() *Gui

func NewGui

func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscommands.OSCommand, tr *i18n.TranslationSet, config config.AppConfigurer, updater *updates.Updater, filterPath string, showRecentRepos bool) (*Gui, error)

for now the split view will always be on NewGui builds a new gui handler

func (*Gui) GenerateMenuCandidates added in v0.30.1

func (gui *Gui) GenerateMenuCandidates(commandOutput, filter, valueFormat, labelFormat string) ([]commandMenuEntry, error)

func (*Gui) GetCustomCommandKeybindings added in v0.23.1

func (gui *Gui) GetCustomCommandKeybindings() []*Binding

func (*Gui) GetInitialKeybindings added in v0.7.1

func (gui *Gui) GetInitialKeybindings() []*Binding

GetInitialKeybindings is a function.

func (*Gui) GetOnRunCommand added in v0.28.1

func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry)

func (*Gui) HandlePasteCommits added in v0.7.1

func (gui *Gui) HandlePasteCommits() error

HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied

func (*Gui) RenderCommitLength added in v0.2.2

func (gui *Gui) RenderCommitLength()

RenderCommitLength is a function.

func (*Gui) Run

func (gui *Gui) Run() error

Run setup the gui with keybindings and start the mainloop

func (*Gui) RunAndHandleError added in v0.27.1

func (gui *Gui) RunAndHandleError() error

RunAndHandleError

func (*Gui) RunAndStream added in v0.31.1

func (gui *Gui) RunAndStream(cmdStr string, waitingStatus string, onSuccess func() error) error

func (*Gui) WithWaitingStatus added in v0.7.1

func (gui *Gui) WithWaitingStatus(message string, f func() error) error

WithWaitingStatus wraps a function and shows a waiting status while the function is still executing

type IListContext added in v0.31.1

type IListContext interface {
	GetSelectedItem() (ListItem, bool)
	GetSelectedItemId() string
	OnRender() error

	FocusLine()

	GetPanelState() IListPanelState

	Context
	// contains filtered or unexported methods
}

type IListPanelState added in v0.22.0

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

type LblPanelState added in v0.28.1

type LblPanelState struct {
	*lbl.State
	SecondaryFocused bool // this is for if we show the left or right panel
}

for now the staging panel state, unlike the other panel states, is going to be non-mutative, so that we don't accidentally end up with mismatches of data. We might change this in the future

type ListContext added in v0.22.0

type ListContext struct {
	GetItemsLength      func() int
	GetDisplayStrings   func(startIdx int, length int) [][]string
	OnFocus             func() error
	OnFocusLost         func() error
	OnClickSelectedItem func() error

	// the boolean here tells us whether the item is nil. This is needed because you can't work it out on the calling end once the pointer is wrapped in an interface (unless you want to use reflection)
	SelectedItem    func() (ListItem, bool)
	OnGetPanelState func() IListPanelState
	// if this is true, we'll call GetDisplayStrings for just the visible part of the
	// view and re-render that. This is useful when you need to render different
	// content based on the selection (e.g. for showing the selected commit)
	RenderSelection bool

	Gui *Gui

	*BasicContext
}

func (*ListContext) FocusLine added in v0.31.1

func (self *ListContext) FocusLine()

func (*ListContext) GetPanelState added in v0.22.0

func (self *ListContext) GetPanelState() IListPanelState

func (*ListContext) GetSelectedItem added in v0.22.0

func (self *ListContext) GetSelectedItem() (ListItem, bool)

func (*ListContext) GetSelectedItemId added in v0.22.0

func (self *ListContext) GetSelectedItemId() string

func (*ListContext) HandleFocus added in v0.22.0

func (self *ListContext) HandleFocus() error

func (*ListContext) HandleFocusLost added in v0.22.0

func (self *ListContext) HandleFocusLost() error

func (*ListContext) HandleRender added in v0.22.0

func (self *ListContext) HandleRender() error

func (*ListContext) OnRender added in v0.22.0

func (self *ListContext) OnRender() error

OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view

type ListItem added in v0.22.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 MergingPanelState added in v0.28.1

type MergingPanelState struct {
	*mergeconflicts.State

	// UserVerticalScrolling tells us if the user has started scrolling through the file themselves
	// in which case we won't auto-scroll to a conflict.
	UserVerticalScrolling bool
}

type Modes added in v0.22.0

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

type PullFilesOptions added in v0.22.0

type PullFilesOptions struct {
	RemoteName      string
	BranchName      string
	FastForwardOnly bool
	// contains filtered or unexported fields
}

type RebaseOption added in v0.31.1

type RebaseOption string

type ReflogActionKind added in v0.27.1

type ReflogActionKind int
const (
	CHECKOUT ReflogActionKind = iota
	COMMIT
	REBASE
	CURRENT_REBASE
)

type RefreshMode added in v0.27.1

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 RefreshableView added in v0.27.1

type RefreshableView int

models/views that we can refresh

const (
	COMMITS RefreshableView = iota
	BRANCHES
	FILES
	STASH
	REFLOG
	TAGS
	REMOTES
	STATUS
	SUBMODULES
)

type Repo added in v0.27.1

type Repo string

type StartupStage added in v0.27.1

type StartupStage int

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

const (
	INITIAL StartupStage = iota
	COMPLETE
)

type TaskKind added in v0.27.1

type TaskKind int

constants for updateTask's kind field

const (
	RENDER_STRING TaskKind = iota
	RENDER_STRING_WITHOUT_SCROLL
	RUN_COMMAND
	RUN_PTY
)

type Views added in v0.27.1

type Views struct {
	Status        *gocui.View
	Files         *gocui.View
	Branches      *gocui.View
	Commits       *gocui.View
	Stash         *gocui.View
	Main          *gocui.View
	Secondary     *gocui.View
	Options       *gocui.View
	Confirmation  *gocui.View
	Menu          *gocui.View
	Credentials   *gocui.View
	CommitMessage *gocui.View
	CommitFiles   *gocui.View
	Information   *gocui.View
	AppStatus     *gocui.View
	Search        *gocui.View
	SearchPrefix  *gocui.View
	Limit         *gocui.View
	Suggestions   *gocui.View
	Extras        *gocui.View
}

type WindowMaximisation added in v0.27.1

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
)

Directories

Path Synopsis
modes

Jump to

Keyboard shortcuts

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