class TermBuf::History

Overview

Lines entered earlier, and a walk back through them.

Off by default and bounded when on. What separates this from an array is the line being typed when the walk starts: it is put aside and restored on the way back down, which is what people expect and what most implementations forget.

Defined in:

termbuf/widgets/history.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(capacity : Int32 = 100, search : Search = Search::Chronological) #

[View source]

Instance Method Detail

def add(entry : String) : Nil #

Records entry and ends any walk in progress.

A blank line is not worth recalling, and neither is a line identical to the one before it: a history full of the same command is a history of one command.


[View source]
def capacity : Int32 #

How many entries to keep. The oldest go first.


[View source]
def clear : Nil #

Forgets everything.


[View source]
def empty? : Bool #

Whether nothing has been recorded.


[View source]
def entries : Array(String) #

Newest last, which is the order a history file is written in.


[View source]
def load(io : IO) : Nil #

Reads entries written by #save, appending to whatever is already here.


[View source]
def next : String | Nil #

Steps forward one entry. Returns what to put in its place, which at the end of the walk is the line that was being typed when it started.


[View source]
def previous(current : String) : String | Nil #

Steps back one entry, given the line currently being typed. Returns what to put in its place, or nil when there is nowhere further back.


[View source]
def reset : Nil #

Abandons the walk, so the next #previous starts from the live line again. Anything that edits the line should do this.


[View source]
def save(io : IO) : Nil #

Writes one entry per line. Where that goes, and whether it goes anywhere, is the application's business: the shard does not decide where a history file lives or what it is called.


[View source]
def search : Search #

Which entries #previous visits.


[View source]
def search=(search : Search) #

Which entries #previous visits.


[View source]
def size : Int32 #

How many entries are held.


[View source]
def walking? : Bool #

Whether a walk is under way.


[View source]