Documentation ¶
Index ¶
- Constants
- type Item
- type ItemType
- type Model
- func (m Model) AppendItem(item Item) tea.Cmd
- func (m Model) Init() tea.Cmd
- func (m Model) Lookback(lookback int) Item
- func (m Model) ReadHistory() tea.Cmd
- func (m Model) SaveHistory(items []Item) tea.Cmd
- func (m Model) Search(search string, startIdx int, delta int) (foundIdx int, found bool)
- func (m Model) StreamOutputFor(cmd Item) func(bytes []byte) tea.Msg
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) UpdateItem(item Item) tea.Cmd
- func (m Model) View() string
- type Status
Constants ¶
const (
// Limit is the maximum number of history items to store
Limit = 1000
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct { // This group of fields are serialized and stored ID xid.ID `json:"id"` // The unique ID of the command Prompt string `json:"prompt"` // The prompt that was displayed when the command was executed Line string `json:"line"` // The command executed Started time.Time `json:"started"` // The time the command was executed Finished time.Time `json:"finished"` // The time the command finished executing Status Status `json:"status"` // The status of the command Output string `json:"output"` // The output of the command // This group of fields are not serialized and are only used // for rendering the UI during the current shell session StreamedOutput []byte `json:"-"` // The output of the command as it is streamed ItemType ItemType `json:"-"` // If true then this item is an internal error item and not a user command Error error `json:"-"` // The error returned from the command LoadedHistory bool `json:"-"` // If true then this item is a history restored item and not a user command }
Item represents a single entry in the command history list
It is both a tea.Model as well as a serializable struct to be stored within the history file.
type Model ¶
type Model struct { Scrollback int // The number of lines to scroll back Items []Item // The history items we're currently displaying // contains filtered or unexported fields }
Model represents the main history model
func (Model) AppendItem ¶
AppendItem adds a new item to the history
func (Model) Lookback ¶
Lookback returns the item that is lookback items back in the history
Valid range for lookback is 1 to len(history.Items)
func (Model) ReadHistory ¶
ReadHistory reads the history file and then returns a message to update the history model
func (Model) SaveHistory ¶
SaveHistory saves the history file to disk
We pass in the items to save as a parameter so that we can asynchronously save the history file without worrying about commands which might be added to the queue after this one
func (Model) Search ¶
Search searches through the history for the given string starting from startIdx moving by delta, it returns the next index that matches the search string, or the startIdx if no more matches are found.
Expected call patterns are: - `Search("foo", 0, 1)` - search from the start of the history going backwards in time - `Search("foo", len(history.Items), -1)` - search from the end of the history going forwards in time
func (Model) StreamOutputFor ¶
StreamOutputFor returns a function that appends the given bytes to the given item by returning an append message
func (Model) UpdateItem ¶
UpdateItem updates an item in the history
If the item doesn't exist in the history it will be added
DO NOT rely on this to add items to the history. Use [AppendItem] instead as that will be far more efficient on large histories