repotab

package
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package repotab provides a formatter which show repositories as a table in CLI

Index

Constants

This section is empty.

Variables

View Source
var AttributesCell = CellBuildFunc(func(r hosting.Repository) (content string, style aec.ANSI) {
	contents := []string{""}
	if r.Private {
		style = aec.YellowF
		contents[0] = "private"
	} else {
		style = aec.LightBlackF
		contents[0] = "public"
	}
	if r.Fork {
		contents = append(contents, "fork")
	}
	if r.Archived {
		contents = append(contents, "archived")
	}
	return strings.Join(contents, ","), style
})
View Source
var DefaultColumns = []Column{{
	Priority:    0,
	CellBuilder: RepoRefCell,
}, {
	Truncatable: true,
	MinWidth:    20,
	Elipsis:     "...",
	Priority:    3,
	CellBuilder: DescriptionCell,
}, {
	Priority:    1,
	CellBuilder: AttributesCell,
}, {
	Align:       AlignRight,
	Priority:    2,
	CellBuilder: UpdatedAtCell,
}}
View Source
var DescriptionCell = CellBuildFunc(func(r hosting.Repository) (content string, style aec.ANSI) {
	content = r.Description
	return content, aec.DefaultF.With(aec.DefaultB)
})
View Source
var EmojiAttributesCell = CellBuildFunc(func(r hosting.Repository) (content string, style aec.ANSI) {
	var parts []string

	if r.Private {
		parts = append(parts, "🔒")
	}
	if r.Fork {
		parts = append(parts, "🔀")
	}
	if r.Archived {
		parts = append(parts, "🗃️")
	}

	return strings.Join(parts, " "), aec.EmptyBuilder.ANSI
})
View Source
var RepoRefCell = CellBuildFunc(func(r hosting.Repository) (content string, style aec.ANSI) {
	content = r.Ref.String()
	return content, aec.Bold
})
View Source
var UpdatedAtCell = CellBuildFunc(func(r hosting.Repository) (content string, style aec.ANSI) {
	return FuzzyAgoAbbr(time.Now(), r.UpdatedAt), aec.LightBlackF
})

Functions

func FuzzyAgoAbbr

func FuzzyAgoAbbr(now time.Time, at time.Time) string

Types

type Align

type Align int
const (
	AlignLeft  Align = iota
	AlignRight Align = iota
)

type CellBuildFunc

type CellBuildFunc func(r hosting.Repository) (content string, style aec.ANSI)

func (CellBuildFunc) Build

func (f CellBuildFunc) Build(r hosting.Repository) (content string, style aec.ANSI)

type CellBuilder

type CellBuilder interface {
	Build(hosting.Repository) (content string, style aec.ANSI)
}

type Column

type Column struct {
	CellBuilder CellBuilder
	Elipsis     string
	MinWidth    int
	Priority    int
	Align       Align
	Truncatable bool
	// contains filtered or unexported fields
}

type Option

type Option func(*Printer)

func Columns

func Columns(columns ...Column) Option

func Styled

func Styled(force bool) Option

Styled sets the printer to use styled output if the terminal supports it.

func TermWidth

func TermWidth() Option

TermWidth sets the terminal width to the printer if it is available.

func Width

func Width(w int) Option

type Printer

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

func NewPrinter

func NewPrinter(w io.Writer, option ...Option) *Printer

func (*Printer) Close

func (p *Printer) Close() error

func (*Printer) Print

func (p *Printer) Print(r hosting.Repository) error

Jump to

Keyboard shortcuts

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