shell

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WFreq    = 0.7 // frequency weight
	WRecency = 0.4 // recency weight
	WLen     = 0.3 // length bonus
	WSepPen  = 0.5 // separator-ratio penalty
	WClass   = 0.2 // class weight

	WComplex = 1.4 // influence of low-complexity detector

	WInfo = 0.8 // information content (entropy + RLE)
)

Scoring knobs

View Source
var (
	// FilePathCompletionSeparator holds separate characters.
	FilePathCompletionSeparator = string([]byte{' ', os.PathSeparator})
)

https://github.com/c-bata/go-prompt/blob/master/completer/file.go

Functions

func Chdir

func Chdir(dir string) error

Chdir changes the current working directory to the specified path. This is required to update the PWD environment variable

func Completer

func Completer(d prompt.Document) []prompt.Suggest

func Explore

func Explore(ctx context.Context, args []string) error

func IsCdCmd

func IsCdCmd(pd prompt.Document) bool

func Pager

func Pager(content string) error

func RemovePageSuffix

func RemovePageSuffix(command string) (string, bool)

RemovePageSuffix removes a "| page" command suffix. Returns the new command and true if a suffix was removed, otherwise returns the original command and false.

func RunAndCapture

func RunAndCapture(ctx context.Context, shellBin, command string, page, save bool, capture func(which int, line string) error) error

RunAndCapture runs a command and captures its output line by line.

func RunNoCapture

func RunNoCapture(shellBin, command string) error

func RunPtyCapture

func RunPtyCapture(ctx context.Context, shellBin, command string, capture func(int, string) error) error

func Shell

func Shell(ctx context.Context, cfg *api.AppConfig) error

Types

type FilePathCompleter

type FilePathCompleter struct {
	IgnoreCase bool
}

FilePathCompleter is a completer for your local file system. Please caution that you need to set OptionCompletionWordSeparator(completer.FilePathCompletionSeparator) when you use this completer.

func (*FilePathCompleter) Complete

func (c *FilePathCompleter) Complete(d prompt.Document, filter func(os.DirEntry) bool) []prompt.Suggest

Complete returns suggestions from your local file system.

type Sub

type Sub struct {
	Page pager.Options `cmd:"" help:"Scroll through a file"`
}

https://github.com/alecthomas/kong

type VisitedRegistry

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

func NewVisitedRegistry

func NewVisitedRegistry() (*VisitedRegistry, error)

func (*VisitedRegistry) List

func (r *VisitedRegistry) List() []string

func (*VisitedRegistry) Visit

func (r *VisitedRegistry) Visit(abs string)

type WordCompleter

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

func NewWordCompleter

func NewWordCompleter(headN, tailM int) *WordCompleter

func (*WordCompleter) Capture

func (wc *WordCompleter) Capture(which int, line string) error

Capture captures lines; processes first N synchronously, buffers last M, and processes buffer when which == 99

func (*WordCompleter) Complete

func (wc *WordCompleter) Complete(d prompt.Document) []prompt.Suggest

func (*WordCompleter) Show

func (wc *WordCompleter) Show(word string, top int)

type WordCounter

type WordCounter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func DefaultWordCounter

func DefaultWordCounter() *WordCounter

DefaultWordCounter returns a WordCounter with reasonable defaults so callers don’t have to worry about the parameters in the common case.

Defaults:

  • maxSize – 100 000 distinct words
  • classWeights – nil (all classes weighted equally)

func NewWordCounter

func NewWordCounter(maxSize int, classWeights map[int]float64) *WordCounter

func (*WordCounter) AddWords

func (c *WordCounter) AddWords(words []string)

func (*WordCounter) AddWordsWithClass

func (c *WordCounter) AddWordsWithClass(class int, words []string)

func (*WordCounter) ScoreWord

func (c *WordCounter) ScoreWord(w string, st *WordStat) float64

ScoreWord returns a positive value (≈0‥4). −1 means “discard”.

func (*WordCounter) Suggest

func (c *WordCounter) Suggest(query string, n int) []WordFreq

Suggest / Top-N

type WordFreq

type WordFreq struct {
	Word   string
	Count  int
	Recent int
	Score  float64
}

type WordStat

type WordStat struct {
	Count       int         // total occurrences
	Recent      int         // last-seen “tick”
	ClassCounts map[int]int // histogram by class
}

Directories

Path Synopsis
Package pager provides a pager (similar to less) for the terminal.
Package pager provides a pager (similar to less) for the terminal.

Jump to

Keyboard shortcuts

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