Documentation
¶
Index ¶
- Constants
- type Content
- func (c *Content) Clear() string
- func (c *Content) DeleteToNextWord() string
- func (c *Content) DeleteToPrevWord() string
- func (c *Content) GetCurrentWord() string
- func (c *Content) GetLinesAfterPosition(pos int) (startOfLine int, lines []string)
- func (c *Content) GetPosition() int
- 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) MoveToPosition(pos int) 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 Editor
- type FuzzyPicker
- type HistoryRepo
- type MockHistoryRepo
- func (_m *MockHistoryRepo) AddRequest(req string)
- func (_m *MockHistoryRepo) EXPECT() *MockHistoryRepo_Expecter
- func (_m *MockHistoryRepo) FuzzySearch(query string) []history.FuzzyMatch
- func (_m *MockHistoryRepo) NextRequest() string
- func (_m *MockHistoryRepo) PrevRequest() string
- func (_m *MockHistoryRepo) ResetPosition()
- func (_m *MockHistoryRepo) Search(prefix string) string
- type MockHistoryRepo_AddRequest_Call
- type MockHistoryRepo_Expecter
- func (_e *MockHistoryRepo_Expecter) AddRequest(req interface{}) *MockHistoryRepo_AddRequest_Call
- func (_e *MockHistoryRepo_Expecter) FuzzySearch(query interface{}) *MockHistoryRepo_FuzzySearch_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
- func (_e *MockHistoryRepo_Expecter) Search(prefix interface{}) *MockHistoryRepo_Search_Call
- type MockHistoryRepo_FuzzySearch_Call
- func (_c *MockHistoryRepo_FuzzySearch_Call) Return(_a0 []history.FuzzyMatch) *MockHistoryRepo_FuzzySearch_Call
- func (_c *MockHistoryRepo_FuzzySearch_Call) Run(run func(query string)) *MockHistoryRepo_FuzzySearch_Call
- func (_c *MockHistoryRepo_FuzzySearch_Call) RunAndReturn(run func(string) []history.FuzzyMatch) *MockHistoryRepo_FuzzySearch_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 MockHistoryRepo_Search_Call
- type MultiMode
- func (m *MultiMode) BinaryEdit(ctx context.Context, initBuffer string) (string, error)
- func (m *MultiMode) CommandMode(ctx context.Context, initBuffer string) (string, error)
- func (m *MultiMode) Edit(ctx context.Context, initBuffer string) (string, error)
- func (m *MultiMode) SetInput(input <-chan core.KeyEvent)
- type Option
Constants ¶
const ( LineUp = "\x1b[1A" LineClear = "\x1b[2K" NewLine = '\n' ReturnCarriage = "\r" Backspace = "\b" )
const ( PastingTimingThresholdInMicrosec = 250 MacOSDeleteKey = 127 Bell = "\a" )
const ( HideCursor = "\x1b[?25l" ShowCursor = "\x1b[?25h" )
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) GetCurrentWord ¶ added in v0.7.0
GetCurrentWord retrieves the word currently under the cursor position. It returns a string representing the word or an empty string if the position is at the start.
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) GetPosition ¶ added in v0.7.0
GetPosition retrieves the current position value of the Content. It takes no parameters. It returns an int representing the current position.
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) MoveToPosition ¶ added in v0.7.0
MoveToPosition moves the current position to the specified index and returns the resultant output string. It takes pos of type int, which is the target position relative to the content length. It returns a string detailing the changes made while adjusting the position. If pos is less than 0, it defaults to 0. If pos exceeds the content length, it defaults to the content's length.
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 Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
func NewEditor ¶
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 FuzzyPicker ¶ added in v0.8.0
type FuzzyPicker struct {
// contains filtered or unexported fields
}
FuzzyPicker provides an interactive fuzzy search interface for history.
func NewFuzzyPicker ¶ added in v0.8.0
func NewFuzzyPicker(output io.Writer, hist HistoryRepo) *FuzzyPicker
NewFuzzyPicker creates a new FuzzyPicker instance.
func (*FuzzyPicker) Pick ¶ added in v0.8.0
func (fp *FuzzyPicker) Pick(ctx context.Context) (string, error)
Pick displays an interactive fuzzy search interface and returns the selected request. Returns the selected request string or an error if interrupted or input unavailable.
func (*FuzzyPicker) SetInput ¶ added in v0.8.0
func (fp *FuzzyPicker) SetInput(input <-chan core.KeyEvent)
SetInput sets the input channel for the picker.
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) FuzzySearch ¶ added in v0.8.0
func (_m *MockHistoryRepo) FuzzySearch(query string) []history.FuzzyMatch
FuzzySearch provides a mock function with given fields: query
func (*MockHistoryRepo) NextRequest ¶
func (_m *MockHistoryRepo) NextRequest() string
NextRequest provides a mock function with no fields
func (*MockHistoryRepo) PrevRequest ¶
func (_m *MockHistoryRepo) PrevRequest() string
PrevRequest provides a mock function with no fields
func (*MockHistoryRepo) ResetPosition ¶
func (_m *MockHistoryRepo) ResetPosition()
ResetPosition provides a mock function with no fields
func (*MockHistoryRepo) Search ¶ added in v0.7.0
func (_m *MockHistoryRepo) Search(prefix string) string
Search provides a mock function with given fields: prefix
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) FuzzySearch ¶ added in v0.8.0
func (_e *MockHistoryRepo_Expecter) FuzzySearch(query interface{}) *MockHistoryRepo_FuzzySearch_Call
FuzzySearch is a helper method to define mock.On call
- query 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
func (*MockHistoryRepo_Expecter) Search ¶ added in v0.7.0
func (_e *MockHistoryRepo_Expecter) Search(prefix interface{}) *MockHistoryRepo_Search_Call
Search is a helper method to define mock.On call
- prefix string
type MockHistoryRepo_FuzzySearch_Call ¶ added in v0.8.0
MockHistoryRepo_FuzzySearch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FuzzySearch'
func (*MockHistoryRepo_FuzzySearch_Call) Return ¶ added in v0.8.0
func (_c *MockHistoryRepo_FuzzySearch_Call) Return(_a0 []history.FuzzyMatch) *MockHistoryRepo_FuzzySearch_Call
func (*MockHistoryRepo_FuzzySearch_Call) Run ¶ added in v0.8.0
func (_c *MockHistoryRepo_FuzzySearch_Call) Run(run func(query string)) *MockHistoryRepo_FuzzySearch_Call
func (*MockHistoryRepo_FuzzySearch_Call) RunAndReturn ¶ added in v0.8.0
func (_c *MockHistoryRepo_FuzzySearch_Call) RunAndReturn(run func(string) []history.FuzzyMatch) *MockHistoryRepo_FuzzySearch_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 MockHistoryRepo_Search_Call ¶ added in v0.7.0
MockHistoryRepo_Search_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Search'
func (*MockHistoryRepo_Search_Call) Return ¶ added in v0.7.0
func (_c *MockHistoryRepo_Search_Call) Return(_a0 string) *MockHistoryRepo_Search_Call
func (*MockHistoryRepo_Search_Call) Run ¶ added in v0.7.0
func (_c *MockHistoryRepo_Search_Call) Run(run func(prefix string)) *MockHistoryRepo_Search_Call
func (*MockHistoryRepo_Search_Call) RunAndReturn ¶ added in v0.7.0
func (_c *MockHistoryRepo_Search_Call) RunAndReturn(run func(string) string) *MockHistoryRepo_Search_Call
type MultiMode ¶
type MultiMode struct {
// contains filtered or unexported fields
}
func NewMultiMode ¶
func NewMultiMode(output io.Writer, reqHistory, cmdHistory, binHistory HistoryRepo) *MultiMode
NewMultiMode initializes a new MultiMode structure with separate editors for command, standard input, and binary modes. It takes an io.Writer and three HistoryRepo instances for request, command, and binary histories. It returns a pointer to the created MultiMode, setting up command, edit, and binary modes appropriately.
func (*MultiMode) BinaryEdit ¶ added in v0.10.0
BinaryEdit activates the binary edit mode, allowing users to edit binary data with an initial buffer. it returns the edited binary string or an error if any issue occurs during the editing process.
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.
type Option ¶ added in v0.7.0
type Option func(*Editor)
func WithCloseHook ¶ added in v0.7.0
WithCloseHook sets the onClose function for the Editor instance. It takes a function hook of type func(io.Writer) error. It returns an Option function to set the onClose function.