split

package
v0.17.15 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package split provides a unified TUI component for split operations.

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	Up: key.NewBinding(
		key.WithKeys(core.KeyUp, "k"),
		key.WithHelp("↑/k", "up"),
	),
	Down: key.NewBinding(
		key.WithKeys(core.KeyDown, "j"),
		key.WithHelp("↓/j", "down"),
	),
	Select: key.NewBinding(
		key.WithKeys(core.KeyEnter),
		key.WithHelp("enter", "select"),
	),
	Submit: key.NewBinding(
		key.WithKeys(core.KeyEnter),
		key.WithHelp("enter", "submit"),
	),
	Yes: key.NewBinding(
		key.WithKeys("y", core.KeyEnter),
		key.WithHelp("y", "yes"),
	),
	No: key.NewBinding(
		key.WithKeys("n"),
		key.WithHelp("n", "no"),
	),
	Cancel: key.NewBinding(
		key.WithKeys(core.KeyCtrlC, core.KeyEsc),
		key.WithHelp("esc", "cancel"),
	),
}

DefaultKeyMap contains the default key bindings for the split wizard

Functions

func GenerateDefaultCommitMessage

func GenerateDefaultCommitMessage(files []string, originalCommitMessage string) string

GenerateDefaultCommitMessage generates a sensible default commit message based on the original commit message and files being extracted.

Format:

<original title> (split)

<original body>

 * file1
 * file2

Types

type BranchCreatedMsg

type BranchCreatedMsg struct {
	Name string
}

BranchCreatedMsg indicates a branch was created

type BranchNameEnteredMsg

type BranchNameEnteredMsg struct {
	Name string
}

BranchNameEnteredMsg indicates user entered a branch name

type CancelMsg

type CancelMsg struct{}

CancelMsg indicates user canceled the operation

type CommitEditorConfig

type CommitEditorConfig struct {
	// DefaultMessage is the initial commit message
	DefaultMessage string
	// Files being extracted (for context display)
	Files []string
	// Direction of the split (above/below)
	Direction Direction
	// CurrentBranch name for context
	CurrentBranch string
}

CommitEditorConfig configures the commit message editor

type CommitEditorModel

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

CommitEditorModel is a bubbletea model for editing commit messages It shows context and launches external EDITOR for editing

func NewCommitEditorModel

func NewCommitEditorModel(cfg CommitEditorConfig) *CommitEditorModel

NewCommitEditorModel creates a new commit message editor model

func (*CommitEditorModel) Canceled

func (m *CommitEditorModel) Canceled() bool

Canceled returns true if the user canceled the editor

func (*CommitEditorModel) Init

func (m *CommitEditorModel) Init() tea.Cmd

Init implements tea.Model

func (*CommitEditorModel) Message

func (m *CommitEditorModel) Message() string

Message returns the commit message entered by the user

func (*CommitEditorModel) Update

func (m *CommitEditorModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model

func (*CommitEditorModel) View

func (m *CommitEditorModel) View() tea.View

View implements tea.Model

type CompleteMsg

type CompleteMsg struct {
	Branches []string
}

CompleteMsg indicates split is complete

type Config

type Config struct {
	Engine engine.Engine
	Branch engine.Branch

	// PreselectedStyle skips type selection if set
	PreselectedStyle Style
	// PreselectedDirection skips direction selection if set
	PreselectedDirection Direction

	// UseGitAddP uses git add -p instead of TUI hunk selector
	UseGitAddP bool

	// AvailableTypes provides the type choices when style not preselected
	AvailableTypes []TypeChoice
}

Config provides configuration for the split model

type Direction

type Direction string

Direction specifies where the new branch should be placed Note: This mirrors split.Direction from actions/split to avoid import cycles.

const (
	DirectionBelow Direction = "below"
	DirectionAbove Direction = "above"
)

Direction constants

type DirectionContext

type DirectionContext struct {
	Engine        engine.BranchReader
	CurrentBranch string
	ParentBranch  string
	Children      []string
}

DirectionContext provides context for the direction selection

type DirectionSelectedMsg

type DirectionSelectedMsg struct {
	Direction Direction
}

DirectionSelectedMsg indicates user selected a direction

type EditMessageConfirmedMsg

type EditMessageConfirmedMsg struct {
	WantsEdit bool
}

EditMessageConfirmedMsg indicates user responded to edit message prompt

type EditorCompleteMsg

type EditorCompleteMsg struct {
	Message string
	Error   error
}

EditorCompleteMsg indicates external editor completed

type EditorRequestMsg

type EditorRequestMsg struct {
	DefaultMessage string
}

EditorRequestMsg indicates the model needs an external editor

type ErrorMsg

type ErrorMsg struct {
	Error error
}

ErrorMsg indicates an error occurred

type HunksLoadedMsg

type HunksLoadedMsg struct {
	Hunks []git.Hunk
	Diff  string
}

HunksLoadedMsg indicates hunks have been loaded for selection

type HunksSelectedMsg

type HunksSelectedMsg struct {
	Hunks []git.Hunk
}

HunksSelectedMsg indicates user finished selecting hunks

type KeyMap

type KeyMap struct {
	Up     key.Binding
	Down   key.Binding
	Select key.Binding
	Submit key.Binding
	Yes    key.Binding
	No     key.Binding
	Cancel key.Binding
}

KeyMap defines unified key bindings for the split wizard

func (KeyMap) ConfirmHelp

func (k KeyMap) ConfirmHelp() []key.Binding

ConfirmHelp returns key bindings for confirmation prompts

func (KeyMap) FullHelp

func (k KeyMap) FullHelp() [][]key.Binding

FullHelp returns all key bindings for full help display

func (KeyMap) ShortHelp

func (k KeyMap) ShortHelp() []key.Binding

ShortHelp returns key bindings for navigation help

func (KeyMap) SubmitHelp

func (k KeyMap) SubmitHelp() []key.Binding

SubmitHelp returns key bindings for submit prompts

type LoopContinueMsg

type LoopContinueMsg struct{}

LoopContinueMsg indicates the hunk loop should continue

type Model

type Model struct {
	core.BaseModel
	// contains filtered or unexported fields
}

Model is the unified TUI model for the split wizard. It implements a state machine that guides the user through: 1. Selecting split type (if not preselected) 2. Selecting direction (if not preselected) 3. The hunk selection loop (select hunks → branch name → commit message → create)

func NewModel

func NewModel(cfg Config) *Model

NewModel creates a new split wizard model

func (*Model) GetBranchName

func (m *Model) GetBranchName() string

GetBranchName returns the current branch name input value

func (*Model) GetCurrentState

func (m *Model) GetCurrentState() State

GetCurrentState returns the current state

func (*Model) GetCurrentSubState

func (m *Model) GetCurrentSubState() SubState

GetCurrentSubState returns the current sub-state

func (*Model) GetResult

func (m *Model) GetResult() Result

GetResult returns the result of the split wizard

func (*Model) GetSelectedDirection

func (m *Model) GetSelectedDirection() Direction

GetSelectedDirection returns the selected direction

func (*Model) GetSelectedStyle

func (m *Model) GetSelectedStyle() Style

GetSelectedStyle returns the selected style

func (*Model) GetWantsEditMessage

func (m *Model) GetWantsEditMessage() bool

GetWantsEditMessage returns whether user wants to edit the message

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init implements tea.Model

func (*Model) IsCreatingBranch

func (m *Model) IsCreatingBranch() bool

IsCreatingBranch returns true if the model is creating a branch

func (*Model) IsSelectingHunks

func (m *Model) IsSelectingHunks() bool

IsSelectingHunks returns true if the model is in hunk selection state

func (*Model) IsWaitingForEditor

func (m *Model) IsWaitingForEditor() bool

IsWaitingForEditor returns true if the model is waiting for external editor

func (*Model) SetCommitMessage

func (m *Model) SetCommitMessage(msg string)

SetCommitMessage sets the default commit message

func (*Model) SetDefaultBranchName

func (m *Model) SetDefaultBranchName(name string)

SetDefaultBranchName sets the default branch name for the next branch

func (*Model) SetExistingBranchNames

func (m *Model) SetExistingBranchNames(names map[string]bool)

SetExistingBranchNames sets the map of existing branch names for validation

func (*Model) SetOriginalBranchName

func (m *Model) SetOriginalBranchName(name string)

SetOriginalBranchName sets the original branch name (allowed to reuse)

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model

func (*Model) View

func (m *Model) View() tea.View

View implements tea.Model

type NoChangesMsg

type NoChangesMsg struct{}

NoChangesMsg indicates no changes were staged

type Result

type Result struct {
	Branches  []string
	Canceled  bool
	Error     error
	Style     Style
	Direction Direction
}

Result contains the result of a split operation

type RetryMsg

type RetryMsg struct{}

RetryMsg indicates user wants to retry hunk selection

type State

type State int

State represents the main state of the split wizard

const (
	StateSelectingType State = iota
	StateSelectingDirection
	StateHunkLoop
	StateComplete
	StateCanceled
	StateError
)

State constants

type Style

type Style string

Style specifies the split mode Note: This mirrors split.Style from actions/split to avoid import cycles. Callers convert between the two types.

const (
	StyleCommit Style = "commit"
	StyleHunk   Style = "hunk"
	StyleFile   Style = "file"
)

Style constants

type Styles

type Styles struct {
	Header    style.HeaderStyles
	Selection style.SelectionStyles
	Status    style.StatusStyles
	Common    style.CommonStyles
	Layout    style.LayoutStyles
	Icons     style.StatusIcons
}

Styles contains styling for the split component using shared style types

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles returns the default styles for the split component

type SubState

type SubState int

SubState represents the sub-state within the hunk loop

const (
	SubStateNone SubState = iota
	SubStateSelectingHunks
	SubStateEnteringBranchName
	SubStatePromptEditMessage
	SubStateEditingMessage
	SubStateCreatingBranch
	SubStateWaitingForRetry
)

SubState constants

type TypeChoice

type TypeChoice struct {
	Style       Style
	Label       string
	Description string
	Available   bool
}

TypeChoice represents an available split type option

type TypeSelectedMsg

type TypeSelectedMsg struct {
	Style Style
}

TypeSelectedMsg indicates user selected a split type

Jump to

Keyboard shortcuts

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