ui

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorReset  = "\033[0m"
	ColorRed    = "\033[31m"
	ColorGreen  = "\033[32m"
	ColorYellow = "\033[33m"
	ColorCyan   = "\033[36m"
	ColorGray   = "\033[90m"
)

Variables

View Source
var ErrNoSelection = errors.New("no selection made")

Functions

func CodeFenceLanguageFromPath added in v1.1.0

func CodeFenceLanguageFromPath(path string) string

CodeFenceLanguageFromPath returns a glamour-friendly language identifier derived from a file path extension. An empty string means "no preference".

func Colorize

func Colorize(color, text string) string

Colorize applies ANSI color codes to text

func ColorizeCode

func ColorizeCode(code string) string

ColorizeCode applies syntax highlighting to suggested code

func ColorizeDiff

func ColorizeDiff(diff string) string

ColorizeDiff applies syntax highlighting to diff hunks

func ColorsEnabled added in v1.1.0

func ColorsEnabled() bool

ColorsEnabled reports whether ANSI colors are enabled.

func CreateHyperlink(url, text string) string

CreateHyperlink creates an OSC8 hyperlink

func EmojiText added in v1.1.0

func EmojiText(emojiText, plainText string) string

EmojiText returns emojiText when colors/emoji are enabled, otherwise the plain fallback.

func RenderMarkdown

func RenderMarkdown(text string) (string, error)

RenderMarkdown renders markdown text with glamour

func SelectFromList

func SelectFromList[T any](items []T, renderer ItemRenderer[T]) (T, error)

SelectFromList creates an interactive selector for a list of items Returns selected items in order they were selected

func SelectFromListWithAction

func SelectFromListWithAction[T any](items []T, renderer ItemRenderer[T], customAction CustomAction[T], actionKey string, onOpen CustomAction[T], filterFunc func(T, bool) bool, onSelect CustomAction[T], customActionSecond CustomAction[T], actionKeySecond string) (T, error)

SelectFromListWithAction creates an interactive selector with a custom action The customAction is triggered by r, and actionKey describes the action in the help text

func SelectPR added in v1.2.0

func SelectPR(prs []*github.PullRequest) (*github.PullRequest, error)

SelectPR displays an interactive selector for choosing a pull request

func SetColorEnabled added in v1.1.0

func SetColorEnabled(enabled bool)

SetColorEnabled toggles ANSI color output across the UI helpers.

func StripSuggestionBlock

func StripSuggestionBlock(body string) string

StripSuggestionBlock removes the suggestion code block and images from comment body

func WrapText

func WrapText(text string, width int) string

WrapText wraps text to a maximum line width

Types

type AuthorStyle

type AuthorStyle struct {
	Name  string // Author name (without @ symbol)
	IsBot bool   // True if author name ends with [bot]
	Color string // ANSI color code (cyan for users, yellow for bots)
}

AuthorStyle represents styling information for a GitHub author.

func NewAuthorStyle

func NewAuthorStyle(author string) *AuthorStyle

NewAuthorStyle creates a new author style based on the author name. Bots (ending with [bot]) are colored yellow, regular users in cyan.

func (*AuthorStyle) Format

func (as *AuthorStyle) Format(includeIcon bool) string

Format returns the formatted author string with color (colored "@authorname").

type CommentListStyle

type CommentListStyle = ReviewListStyle

CommentListStyle is an alias for backward compatibility with resolve.go.

func NewCommentListStyle

func NewCommentListStyle(authorName string, isResolved bool) *CommentListStyle

NewCommentListStyle creates a new comment list style from comment data. Deprecated: Use NewReviewListStyle instead.

type CustomAction

type CustomAction[T any] func(item T) (string, error)

CustomAction is a function that handles custom actions on items

type ItemRenderer

type ItemRenderer[T any] interface {
	// Title returns the primary display text for an item
	Title(item T) string
	// Description returns secondary text for an item
	Description(item T) string
	// Preview returns detailed preview text for an item
	Preview(item T) string
	// EditPath returns the file path to open in editor (optional)
	EditPath(item T) string
	// EditLine returns the line number to go to in editor (1-based, optional)
	EditLine(item T) int
	// FilterValue returns the string to match against when filtering
	FilterValue(item T) string
	// IsSkippable returns true if the item should be skipped during navigation
	IsSkippable(item T) bool
}

ItemRenderer defines how to render an item in the selector

type ReviewListStyle

type ReviewListStyle struct {
	Author *AuthorStyle // Author styling (with bot detection)
	Status *StatusStyle // Resolution status styling
}

ReviewListStyle provides formatting for list items showing review comments or suggestions.

func NewReviewListStyle

func NewReviewListStyle(authorName string, isResolved bool) *ReviewListStyle

NewReviewListStyle creates a new review list style from comment data.

func (*ReviewListStyle) FormatCommentDescription

func (rls *ReviewListStyle) FormatCommentDescription(filePath string, lineNumber int) string

FormatCommentDescription returns a formatted description for comment list: "file:line [emoji status]".

func (*ReviewListStyle) FormatCommentTitle

func (rls *ReviewListStyle) FormatCommentTitle(commentID int64) string

FormatCommentTitle returns a formatted title for comment list display: "@author".

func (*ReviewListStyle) FormatSuggestionDescription

func (rls *ReviewListStyle) FormatSuggestionDescription(hasSuggestion bool, isOutdated bool) string

FormatSuggestionDescription returns a formatted description with status and tags for suggestion list.

func (*ReviewListStyle) FormatSuggestionTitle

func (rls *ReviewListStyle) FormatSuggestionTitle(filePath string, lineNumber int) string

FormatSuggestionTitle returns a formatted title for suggestion list: "@author • file:line".

type SelectionModel

type SelectionModel[T any] struct {
	// contains filtered or unexported fields
}

SelectionModel is the tea.Model for interactive selection

func (*SelectionModel[T]) Init

func (m *SelectionModel[T]) Init() tea.Cmd

Init initializes the model

func (*SelectionModel[T]) Update

func (m *SelectionModel[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles user input

func (*SelectionModel[T]) View

func (m *SelectionModel[T]) View() string

View renders the model

type StatusStyle

type StatusStyle struct {
	IsResolved bool   // True if resolved, false if unresolved
	Label      string // "resolved" or "unresolved"
	Color      string // ANSI color code (green for resolved, yellow for unresolved)
	Emoji      string // Visual indicator (✅ or ⚠️)
}

StatusStyle represents styling information for resolved/unresolved status.

func NewStatusStyle

func NewStatusStyle(isResolved bool) *StatusStyle

NewStatusStyle creates a new status style for the given resolved state.

func (*StatusStyle) Format

func (ss *StatusStyle) Format(includeEmoji bool) string

Format returns the formatted status string with color and emoji. When includeEmoji is true, the emoji indicator is prepended to the status.

type SuggestionListStyle

type SuggestionListStyle = ReviewListStyle

SuggestionListStyle is an alias for backward compatibility with applier.go.

func NewSuggestionListStyle

func NewSuggestionListStyle(authorName string, isResolved bool) *SuggestionListStyle

NewSuggestionListStyle creates a new suggestion list style from comment data. Deprecated: Use NewReviewListStyle instead.

Jump to

Keyboard shortcuts

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