Documentation
¶
Index ¶
- Constants
- type Content
- func (c *Content) Clear() string
- func (c *Content) DeleteToNextWord() string
- func (c *Content) DeleteToPrevWord() 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) MoveToNextWord() string
- func (c *Content) MoveToPrevWord() string
- func (c *Content) MoveToRowEnd() string
- func (c *Content) MoveToRowStart() string
- func (c *Content) PrevSymbol() rune
- func (c *Content) RemoveNextSymbol() string
- func (c *Content) RemovePrevSymbol() string
- func (c *Content) ReplaceText(text string) string
- func (c *Content) String() string
- func (c *Content) ToRequest() string
- type Dictionary
- type Editor
- type HistoryRepo
- type MockHistoryRepo
- type MockHistoryRepo_AddRequest_Call
- type MockHistoryRepo_Expecter
- func (_e *MockHistoryRepo_Expecter) AddRequest(req interface{}) *MockHistoryRepo_AddRequest_Call
- func (_e *MockHistoryRepo_Expecter) NextRequest() *MockHistoryRepo_NextRequest_Call
- func (_e *MockHistoryRepo_Expecter) PrevRequest() *MockHistoryRepo_PrevRequest_Call
- func (_e *MockHistoryRepo_Expecter) ResetPosition() *MockHistoryRepo_ResetPosition_Call
- type MockHistoryRepo_NextRequest_Call
- func (_c *MockHistoryRepo_NextRequest_Call) Return(_a0 string) *MockHistoryRepo_NextRequest_Call
- func (_c *MockHistoryRepo_NextRequest_Call) Run(run func()) *MockHistoryRepo_NextRequest_Call
- func (_c *MockHistoryRepo_NextRequest_Call) RunAndReturn(run func() string) *MockHistoryRepo_NextRequest_Call
- type MockHistoryRepo_PrevRequest_Call
- func (_c *MockHistoryRepo_PrevRequest_Call) Return(_a0 string) *MockHistoryRepo_PrevRequest_Call
- func (_c *MockHistoryRepo_PrevRequest_Call) Run(run func()) *MockHistoryRepo_PrevRequest_Call
- func (_c *MockHistoryRepo_PrevRequest_Call) RunAndReturn(run func() string) *MockHistoryRepo_PrevRequest_Call
- type MockHistoryRepo_ResetPosition_Call
- type MultiMode
Constants ¶
const ( LineUp = "\x1b[1A" LineClear = "\x1b[2K" NewLine = '\n' ReturnCarriage = "\r" Backspace = "\b" )
const ( PastingTimingThresholdInMicrosec = 250 MacOSDeleteKey = 127 Bell = "\a" )
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) DeleteToNextWord ¶
DeleteToNextWord deletes characters from the current position to the beginning of the next word in the content.
func (*Content) DeleteToPrevWord ¶
DeleteToPrevWord deletes characters from the current position to the beginning of current or previous word in the content.
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) MoveToNextWord ¶
MoveToNextWord moves the cursor to the beginning of the next word in the content and returns the word.
func (*Content) MoveToPrevWord ¶
MoveToPrevWord moves the cursor to the beginning of the previous word in the content and returns the word.
func (*Content) MoveToRowEnd ¶
MoveToRowEnd moves the position within the text to the end of the current row. It returns the substring from the initial position to the end of the row. If the current position is already at or beyond the end of the text, it returns an empty string.
func (*Content) MoveToRowStart ¶
MoveToRowStart moves the cursor position to the start of the current row. It updates the cursor position and returns a string of backspace characters needed to move the cursor to the start of the row. It takes no parameters and returns a string. If the cursor is already at the start of the row (position 0), 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) RemoveNextSymbol ¶
RemoveNextSymbol removes the symbol at the current position in the content's text and returns a string representing the updated text or necessary control characters for display. It takes no parameters. It returns a string which is the updated text or control characters for display. If the current position is out of bounds, it returns an empty string. If the symbol at the current position is a newline, it handles the line break and returns the appropriate control characters to update the display.
func (*Content) RemovePrevSymbol ¶
RemovePrevSymbol removes the previous symbol from the content's text at the current position. It adjusts the position and updates the text accordingly. It returns a string representing the changes to be displayed. If the current position is out of bounds, it returns an empty string. If the removed symbol is not a newline, it returns a string to clear and update the current line. If the removed symbol is a newline, it returns a string to clear and update the previous line(s).
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 {
Dictionary *Dictionary
// contains filtered or unexported fields
}
func NewEditor ¶
func NewEditor(output io.Writer, history HistoryRepo, isSingleLine bool) *Editor
NewEditor initializes a new instance of Editor for text editing tasks. It takes output of type io.Writer for writing, history of type HistoryRepo for request history, and isSingleLine of type bool to specify single-line mode. It returns a pointer to an initialized Editor structure.
func (*Editor) Edit ¶
Edit processes keyboard input to manipulate and return the edited content. It takes a context ctx of type context.Context for cancellation and an initial buffer initBuffer of type string. It returns the final edited string content or an error if input is unavailable, keyboard stream is closed, or an interrupt occurs.
type HistoryRepo ¶
type MockHistoryRepo ¶
MockHistoryRepo is an autogenerated mock type for the HistoryRepo type
func NewMockHistoryRepo ¶
func NewMockHistoryRepo(t interface {
mock.TestingT
Cleanup(func())
}) *MockHistoryRepo
NewMockHistoryRepo creates a new instance of MockHistoryRepo. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockHistoryRepo) AddRequest ¶
func (_m *MockHistoryRepo) AddRequest(req string)
AddRequest provides a mock function with given fields: req
func (*MockHistoryRepo) EXPECT ¶
func (_m *MockHistoryRepo) EXPECT() *MockHistoryRepo_Expecter
func (*MockHistoryRepo) NextRequest ¶
func (_m *MockHistoryRepo) NextRequest() string
NextRequest provides a mock function with given fields:
func (*MockHistoryRepo) PrevRequest ¶
func (_m *MockHistoryRepo) PrevRequest() string
PrevRequest provides a mock function with given fields:
func (*MockHistoryRepo) ResetPosition ¶
func (_m *MockHistoryRepo) ResetPosition()
ResetPosition provides a mock function with given fields:
type MockHistoryRepo_AddRequest_Call ¶
MockHistoryRepo_AddRequest_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddRequest'
func (*MockHistoryRepo_AddRequest_Call) Return ¶
func (_c *MockHistoryRepo_AddRequest_Call) Return() *MockHistoryRepo_AddRequest_Call
func (*MockHistoryRepo_AddRequest_Call) Run ¶
func (_c *MockHistoryRepo_AddRequest_Call) Run(run func(req string)) *MockHistoryRepo_AddRequest_Call
func (*MockHistoryRepo_AddRequest_Call) RunAndReturn ¶
func (_c *MockHistoryRepo_AddRequest_Call) RunAndReturn(run func(string)) *MockHistoryRepo_AddRequest_Call
type MockHistoryRepo_Expecter ¶
type MockHistoryRepo_Expecter struct {
// contains filtered or unexported fields
}
func (*MockHistoryRepo_Expecter) AddRequest ¶
func (_e *MockHistoryRepo_Expecter) AddRequest(req interface{}) *MockHistoryRepo_AddRequest_Call
AddRequest is a helper method to define mock.On call
- req string
func (*MockHistoryRepo_Expecter) NextRequest ¶
func (_e *MockHistoryRepo_Expecter) NextRequest() *MockHistoryRepo_NextRequest_Call
NextRequest is a helper method to define mock.On call
func (*MockHistoryRepo_Expecter) PrevRequest ¶
func (_e *MockHistoryRepo_Expecter) PrevRequest() *MockHistoryRepo_PrevRequest_Call
PrevRequest is a helper method to define mock.On call
func (*MockHistoryRepo_Expecter) ResetPosition ¶
func (_e *MockHistoryRepo_Expecter) ResetPosition() *MockHistoryRepo_ResetPosition_Call
ResetPosition is a helper method to define mock.On call
type MockHistoryRepo_NextRequest_Call ¶
MockHistoryRepo_NextRequest_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NextRequest'
func (*MockHistoryRepo_NextRequest_Call) Return ¶
func (_c *MockHistoryRepo_NextRequest_Call) Return(_a0 string) *MockHistoryRepo_NextRequest_Call
func (*MockHistoryRepo_NextRequest_Call) Run ¶
func (_c *MockHistoryRepo_NextRequest_Call) Run(run func()) *MockHistoryRepo_NextRequest_Call
func (*MockHistoryRepo_NextRequest_Call) RunAndReturn ¶
func (_c *MockHistoryRepo_NextRequest_Call) RunAndReturn(run func() string) *MockHistoryRepo_NextRequest_Call
type MockHistoryRepo_PrevRequest_Call ¶
MockHistoryRepo_PrevRequest_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PrevRequest'
func (*MockHistoryRepo_PrevRequest_Call) Return ¶
func (_c *MockHistoryRepo_PrevRequest_Call) Return(_a0 string) *MockHistoryRepo_PrevRequest_Call
func (*MockHistoryRepo_PrevRequest_Call) Run ¶
func (_c *MockHistoryRepo_PrevRequest_Call) Run(run func()) *MockHistoryRepo_PrevRequest_Call
func (*MockHistoryRepo_PrevRequest_Call) RunAndReturn ¶
func (_c *MockHistoryRepo_PrevRequest_Call) RunAndReturn(run func() string) *MockHistoryRepo_PrevRequest_Call
type MockHistoryRepo_ResetPosition_Call ¶
MockHistoryRepo_ResetPosition_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ResetPosition'
func (*MockHistoryRepo_ResetPosition_Call) Return ¶
func (_c *MockHistoryRepo_ResetPosition_Call) Return() *MockHistoryRepo_ResetPosition_Call
func (*MockHistoryRepo_ResetPosition_Call) Run ¶
func (_c *MockHistoryRepo_ResetPosition_Call) Run(run func()) *MockHistoryRepo_ResetPosition_Call
func (*MockHistoryRepo_ResetPosition_Call) RunAndReturn ¶
func (_c *MockHistoryRepo_ResetPosition_Call) RunAndReturn(run func()) *MockHistoryRepo_ResetPosition_Call
type MultiMode ¶
type MultiMode struct {
// contains filtered or unexported fields
}
func NewMultiMode ¶
func NewMultiMode(output io.Writer, reqHistory, cmdHistory HistoryRepo, cmdDict *Dictionary) *MultiMode
NewMultiMode initializes a new MultiMode structure with separate editors for command and standard input modes. It takes an io.Writer, two HistoryRepo instances for request and command histories, and an optional Dictionary. It returns a pointer to the created MultiMode, setting up command and edit modes appropriately.
func (*MultiMode) CommandMode ¶
CommandMode activates the command mode, reading user input from keyStream with an initial buffer initBuffer. It returns the resulting command string or an error if any issue occurs.