Documentation
¶
Index ¶
- Constants
- type Content
- func (c *Content) Clear() string
- func (c *Content) GetLinesAfterPosition(pos int) (startOfLine int, lines []string)
- func (c *Content) InsertSymbol(symbol rune) string
- func (c *Content) MovePositionLeft() string
- func (c *Content) MovePositionRight() string
- func (c *Content) MoveToEnd() string
- func (c *Content) PrevSymbol() rune
- func (c *Content) RemoveSymbol() string
- func (c *Content) ReplaceText(text string) string
- func (c *Content) String() string
- func (c *Content) ToRequest() string
- type Dictionary
- type Editor
- type History
Constants ¶
const ( LineUp = "\x1b[1A" LineClear = "\x1b[2K" NewLine = '\n' ReturnCarriege = "\r" Backspace = "\b" )
const ( PastingTimingThresholdInMicrosec = 250 MacOSDeleteKey = 127 Bell = "\a" )
const (
HistoryFileRigths = 0o644
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content struct {
// contains filtered or unexported fields
}
func NewContent ¶
func NewContent() *Content
NewContent returns a new instance of Content with empty text and position set to 0.
func (*Content) Clear ¶
Clear clears the content and returns the string representation of the cleared content. If the content is already empty, it returns an empty string.
func (*Content) GetLinesAfterPosition ¶
GetLinesAfterPosition returns the start index of the line containing the given position and a slice of strings representing the lines after the given position. If the position is before the first line, the start index is 0.
func (*Content) InsertSymbol ¶
InsertSymbol inserts a rune at the current position of the Content object. If the position is invalid, it returns an empty string. If the inserted symbol is not a newline and the next character is a newline, it returns the inserted symbol. If the inserted symbol is a newline, it returns the content of the lines affected by the insertion, with the cursor moved to the beginning of the next line.
func (*Content) MovePositionLeft ¶
MovePositionLeft moves the cursor position one character to the left and returns the ANSI escape sequence required to move the cursor to the new position. If the cursor is already at the beginning of the line, it moves the cursor to the end of the previous line. If the cursor is already at the beginning of the content, it returns an empty string.
func (*Content) MovePositionRight ¶
MovePositionRight moves the position of the cursor to the right by one character in the content. If the position is already at the end of the content, it returns an empty string.
func (*Content) MoveToEnd ¶
MoveToEnd moves the cursor to the end of the content and returns the remaining text. If the cursor is already at the end, it returns an empty string.
func (*Content) PrevSymbol ¶
PrevSymbol returns the symbol before the current position in the content text. If the current position is at the beginning of the text, it returns 0.
func (*Content) RemoveSymbol ¶
RemoveSymbol removes the symbol at the current position of the Content object and returns the string representation of the changes made. If the current position is out of bounds, an empty string is returned. If the removed symbol is not a newline character, the function returns the string representation of the changes made, including clearing the current line and moving the cursor to the beginning of the line. If the removed symbol is a newline character, the function returns the string representation of the changes made, including moving the cursor up one line and clearing the current line.
func (*Content) ReplaceText ¶
ReplaceText replaces the current text with the given text and returns the resulting string.
type Dictionary ¶
type Dictionary struct {
// contains filtered or unexported fields
}
func NewDictionary ¶
func NewDictionary(words []string) *Dictionary
NewDictionary creates a new instance of Dictionary with the given list of words. The words are sorted in ascending order before being stored in the dictionary. It returns a pointer to the created Dictionary.
func (*Dictionary) Search ¶
func (d *Dictionary) Search(prefix string) string
Search searches for words in the dictionary that have the given prefix. It performs a search to find all matching words. The function returns the longest common prefix among the matching words.
type Editor ¶
type Editor struct {
History *History
Dictionary *Dictionary
// contains filtered or unexported fields
}
func NewEditor ¶
NewEditor creates a new instance of Editor struct. It takes an io.Writer to output the editor content, a *History to store the command history, a boolean value to indicate whether the editor should be single line or not. It returns a pointer to the created Editor struct.
type History ¶
type History struct {
// contains filtered or unexported fields
}
func NewHistory ¶
NewHistory creates a new History instance with the given file name and limit. The History instance stores a list of requests made by the user and loads them from the file if it exists. The limit parameter specifies the maximum number of requests to store in the history.
func (*History) AddRequest ¶
AddRequest adds a request to the history. If the request is empty or the same as the last request, it will not be added.
func (*History) NextRequst ¶
NextRequest returns the next request in the history. If there are no more requests, it returns an empty string.
func (*History) PrevRequst ¶
PrevRequst returns the previous request in the history. If there are no more previous requests, it returns an empty string.
func (*History) ResetPosition ¶
func (h *History) ResetPosition()
ResetPosition resets the position of the history to the end. If the history is empty, it does nothing.
func (*History) SaveToFile ¶
SaveToFile saves the history to a file. It opens the file with the given filename and writes the history requests to it. If the file does not exist, it creates it. If the number of requests is greater than the limit, it writes only the last limit requests. It replaces newlines with the escape sequence "\\n". It returns an error if it fails to open the file or write to it.