core

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandsLimit = 100

	HideCursor = "\x1b[?25l"
	ShowCursor = "\x1b[?25h"

	ClearTerminal = "\u001B[H\u001B[2J"
	WelcomMessage = "Use Enter to input request and send it, Ctrl+C to exit"
)

Variables

View Source
var (
	ErrInterrupted = fmt.Errorf("interrupted")
)

Functions

This section is empty.

Types

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

func NewCLI

func NewCLI(cmdFactory CommandFactory, wsConn ConnectionHandler, output io.Writer, editor Editor, formater Formater) *CLI

NewCLI creates a new CLI instance with the given wsConn, input, and output. It returns an error if it fails to get the current user, create the necessary directories, load the macro for the domain, or initialize the CLI instance.

func (*CLI) OnKeyEvent

func (c *CLI) OnKeyEvent(event KeyEvent)

func (*CLI) Run

func (c *CLI) Run(ctx context.Context, opts RunOptions) error

Run runs the CLI with the provided options. It listens for user input and executes commands accordingly.

type CommandFactory

type CommandFactory interface {
	Create(raw string) (Executer, error)
}

type ConnectionHandler

type ConnectionHandler interface {
	SetOnMessage(func(context.Context, []byte))
	Send(ctx context.Context, msg string) error
}

type Editor

type Editor interface {
	Edit(ctx context.Context, initBuffer string) (string, error)
	CommandMode(ctx context.Context, initBuffer string) (string, error)
	SetInput(input <-chan KeyEvent)
}

type Executer

type Executer interface {
	Execute(ExecutionContext) (Executer, error)
}

type ExecutionContext

type ExecutionContext interface {
	Print(data string, attr ...color.Attribute) error
	PrintToFile(data string) error
	FormatMessage(msg Message, noColor bool) (string, error)
	SendRequest(req string) error
	WaitForResponse(timeout time.Duration) (Message, error)
	EditorMode(initBuffer string) (string, error)
	CommandMode(initBuffer string) (string, error)
	CreateCommand(raw string) (Executer, error)
}

type Formater

type Formater interface {
	FormatMessage(msgType string, msgData string) (string, error)
	FormatForFile(msgType string, msgData string) (string, error)
}

type Key

type Key uint16
const (
	KeyEsc          Key = 27
	KeyCtrlC        Key = 3
	KeyCtrlD        Key = 4
	KeyEnter        Key = 13
	KeyCtrlS        Key = 19
	KeyCtrlU        Key = 21
	KeySpace        Key = 32
	KeyAltBackspace Key = 23
	KeyBackspace    Key = 8
	MacBackspace2   Key = 127
	KeyDelete       Key = 65522
	KeyArrowLeft    Key = 65515
	KeyArrowRight   Key = 65514
	KeyArrowUp      Key = 65517
	KeyArrowDown    Key = 65516
	KeyTab          Key = 9
	KeyHome         Key = 65505
	KeyEnd          Key = 65507
	KeyCtrlL        Key = 12
)

type KeyEvent

type KeyEvent struct {
	Key  Key
	Rune rune
}

type Message

type Message struct {
	Data string      `json:"data"`
	Type MessageType `json:"type"`
}

type MessageType

type MessageType uint8
const (
	Request MessageType = iota
	Response
)

func (MessageType) String

func (mt MessageType) String() string

type MockCommandFactory

type MockCommandFactory struct {
	mock.Mock
}

MockCommandFactory is an autogenerated mock type for the CommandFactory type

func NewMockCommandFactory

func NewMockCommandFactory(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockCommandFactory

NewMockCommandFactory creates a new instance of MockCommandFactory. 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 (*MockCommandFactory) Create

func (_m *MockCommandFactory) Create(raw string) (Executer, error)

Create provides a mock function with given fields: raw

func (*MockCommandFactory) EXPECT

type MockCommandFactory_Create_Call

type MockCommandFactory_Create_Call struct {
	*mock.Call
}

MockCommandFactory_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create'

func (*MockCommandFactory_Create_Call) Return

func (*MockCommandFactory_Create_Call) Run

func (*MockCommandFactory_Create_Call) RunAndReturn

type MockCommandFactory_Expecter

type MockCommandFactory_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockCommandFactory_Expecter) Create

func (_e *MockCommandFactory_Expecter) Create(raw interface{}) *MockCommandFactory_Create_Call

Create is a helper method to define mock.On call

  • raw string

type MockConnectionHandler

type MockConnectionHandler struct {
	mock.Mock
}

MockConnectionHandler is an autogenerated mock type for the ConnectionHandler type

func NewMockConnectionHandler

func NewMockConnectionHandler(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockConnectionHandler

NewMockConnectionHandler creates a new instance of MockConnectionHandler. 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 (*MockConnectionHandler) EXPECT

func (*MockConnectionHandler) Send

func (_m *MockConnectionHandler) Send(ctx context.Context, msg string) error

Send provides a mock function with given fields: ctx, msg

func (*MockConnectionHandler) SetOnMessage

func (_m *MockConnectionHandler) SetOnMessage(_a0 func(context.Context, []byte))

SetOnMessage provides a mock function with given fields: _a0

type MockConnectionHandler_Expecter

type MockConnectionHandler_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockConnectionHandler_Expecter) Send

func (_e *MockConnectionHandler_Expecter) Send(ctx interface{}, msg interface{}) *MockConnectionHandler_Send_Call

Send is a helper method to define mock.On call

  • ctx context.Context
  • msg string

func (*MockConnectionHandler_Expecter) SetOnMessage

SetOnMessage is a helper method to define mock.On call

  • _a0 func(context.Context , []byte)

type MockConnectionHandler_Send_Call

type MockConnectionHandler_Send_Call struct {
	*mock.Call
}

MockConnectionHandler_Send_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Send'

func (*MockConnectionHandler_Send_Call) Return

func (*MockConnectionHandler_Send_Call) Run

func (*MockConnectionHandler_Send_Call) RunAndReturn

type MockConnectionHandler_SetOnMessage_Call

type MockConnectionHandler_SetOnMessage_Call struct {
	*mock.Call
}

MockConnectionHandler_SetOnMessage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetOnMessage'

func (*MockConnectionHandler_SetOnMessage_Call) Return

func (*MockConnectionHandler_SetOnMessage_Call) Run

func (*MockConnectionHandler_SetOnMessage_Call) RunAndReturn

type MockEditor

type MockEditor struct {
	mock.Mock
}

MockEditor is an autogenerated mock type for the Editor type

func NewMockEditor

func NewMockEditor(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockEditor

NewMockEditor creates a new instance of MockEditor. 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 (*MockEditor) CommandMode

func (_m *MockEditor) CommandMode(ctx context.Context, initBuffer string) (string, error)

CommandMode provides a mock function with given fields: ctx, initBuffer

func (*MockEditor) EXPECT

func (_m *MockEditor) EXPECT() *MockEditor_Expecter

func (*MockEditor) Edit

func (_m *MockEditor) Edit(ctx context.Context, initBuffer string) (string, error)

Edit provides a mock function with given fields: ctx, initBuffer

func (*MockEditor) SetInput

func (_m *MockEditor) SetInput(input <-chan KeyEvent)

SetInput provides a mock function with given fields: input

type MockEditor_CommandMode_Call

type MockEditor_CommandMode_Call struct {
	*mock.Call
}

MockEditor_CommandMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CommandMode'

func (*MockEditor_CommandMode_Call) Return

func (*MockEditor_CommandMode_Call) Run

func (*MockEditor_CommandMode_Call) RunAndReturn

type MockEditor_Edit_Call

type MockEditor_Edit_Call struct {
	*mock.Call
}

MockEditor_Edit_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Edit'

func (*MockEditor_Edit_Call) Return

func (_c *MockEditor_Edit_Call) Return(_a0 string, _a1 error) *MockEditor_Edit_Call

func (*MockEditor_Edit_Call) Run

func (_c *MockEditor_Edit_Call) Run(run func(ctx context.Context, initBuffer string)) *MockEditor_Edit_Call

func (*MockEditor_Edit_Call) RunAndReturn

func (_c *MockEditor_Edit_Call) RunAndReturn(run func(context.Context, string) (string, error)) *MockEditor_Edit_Call

type MockEditor_Expecter

type MockEditor_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockEditor_Expecter) CommandMode

func (_e *MockEditor_Expecter) CommandMode(ctx interface{}, initBuffer interface{}) *MockEditor_CommandMode_Call

CommandMode is a helper method to define mock.On call

  • ctx context.Context
  • initBuffer string

func (*MockEditor_Expecter) Edit

func (_e *MockEditor_Expecter) Edit(ctx interface{}, initBuffer interface{}) *MockEditor_Edit_Call

Edit is a helper method to define mock.On call

  • ctx context.Context
  • initBuffer string

func (*MockEditor_Expecter) SetInput

func (_e *MockEditor_Expecter) SetInput(input interface{}) *MockEditor_SetInput_Call

SetInput is a helper method to define mock.On call

  • input <-chan KeyEvent

type MockEditor_SetInput_Call

type MockEditor_SetInput_Call struct {
	*mock.Call
}

MockEditor_SetInput_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetInput'

func (*MockEditor_SetInput_Call) Return

func (*MockEditor_SetInput_Call) Run

func (_c *MockEditor_SetInput_Call) Run(run func(input <-chan KeyEvent)) *MockEditor_SetInput_Call

func (*MockEditor_SetInput_Call) RunAndReturn

func (_c *MockEditor_SetInput_Call) RunAndReturn(run func(<-chan KeyEvent)) *MockEditor_SetInput_Call

type MockExecuter

type MockExecuter struct {
	mock.Mock
}

MockExecuter is an autogenerated mock type for the Executer type

func NewMockExecuter

func NewMockExecuter(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockExecuter

NewMockExecuter creates a new instance of MockExecuter. 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 (*MockExecuter) EXPECT

func (_m *MockExecuter) EXPECT() *MockExecuter_Expecter

func (*MockExecuter) Execute

func (_m *MockExecuter) Execute(_a0 ExecutionContext) (Executer, error)

Execute provides a mock function with given fields: _a0

type MockExecuter_Execute_Call

type MockExecuter_Execute_Call struct {
	*mock.Call
}

MockExecuter_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute'

func (*MockExecuter_Execute_Call) Return

func (*MockExecuter_Execute_Call) Run

func (*MockExecuter_Execute_Call) RunAndReturn

type MockExecuter_Expecter

type MockExecuter_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockExecuter_Expecter) Execute

func (_e *MockExecuter_Expecter) Execute(_a0 interface{}) *MockExecuter_Execute_Call

Execute is a helper method to define mock.On call

  • _a0 ExecutionContext

type MockExecutionContext

type MockExecutionContext struct {
	mock.Mock
}

MockExecutionContext is an autogenerated mock type for the ExecutionContext type

func NewMockExecutionContext

func NewMockExecutionContext(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockExecutionContext

NewMockExecutionContext creates a new instance of MockExecutionContext. 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 (*MockExecutionContext) CommandMode

func (_m *MockExecutionContext) CommandMode(initBuffer string) (string, error)

CommandMode provides a mock function with given fields: initBuffer

func (*MockExecutionContext) CreateCommand

func (_m *MockExecutionContext) CreateCommand(raw string) (Executer, error)

CreateCommand provides a mock function with given fields: raw

func (*MockExecutionContext) EXPECT

func (*MockExecutionContext) EditorMode

func (_m *MockExecutionContext) EditorMode(initBuffer string) (string, error)

EditorMode provides a mock function with given fields: initBuffer

func (*MockExecutionContext) FormatMessage

func (_m *MockExecutionContext) FormatMessage(msg Message, noColor bool) (string, error)

FormatMessage provides a mock function with given fields: msg, noColor

func (*MockExecutionContext) Print

func (_m *MockExecutionContext) Print(data string, attr ...color.Attribute) error

Print provides a mock function with given fields: data, attr

func (*MockExecutionContext) PrintToFile

func (_m *MockExecutionContext) PrintToFile(data string) error

PrintToFile provides a mock function with given fields: data

func (*MockExecutionContext) SendRequest

func (_m *MockExecutionContext) SendRequest(req string) error

SendRequest provides a mock function with given fields: req

func (*MockExecutionContext) WaitForResponse

func (_m *MockExecutionContext) WaitForResponse(timeout time.Duration) (Message, error)

WaitForResponse provides a mock function with given fields: timeout

type MockExecutionContext_CommandMode_Call

type MockExecutionContext_CommandMode_Call struct {
	*mock.Call
}

MockExecutionContext_CommandMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CommandMode'

func (*MockExecutionContext_CommandMode_Call) Return

func (*MockExecutionContext_CommandMode_Call) Run

func (*MockExecutionContext_CommandMode_Call) RunAndReturn

type MockExecutionContext_CreateCommand_Call

type MockExecutionContext_CreateCommand_Call struct {
	*mock.Call
}

MockExecutionContext_CreateCommand_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCommand'

func (*MockExecutionContext_CreateCommand_Call) Return

func (*MockExecutionContext_CreateCommand_Call) Run

func (*MockExecutionContext_CreateCommand_Call) RunAndReturn

type MockExecutionContext_EditorMode_Call

type MockExecutionContext_EditorMode_Call struct {
	*mock.Call
}

MockExecutionContext_EditorMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EditorMode'

func (*MockExecutionContext_EditorMode_Call) Return

func (*MockExecutionContext_EditorMode_Call) Run

func (*MockExecutionContext_EditorMode_Call) RunAndReturn

type MockExecutionContext_Expecter

type MockExecutionContext_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockExecutionContext_Expecter) CommandMode

func (_e *MockExecutionContext_Expecter) CommandMode(initBuffer interface{}) *MockExecutionContext_CommandMode_Call

CommandMode is a helper method to define mock.On call

  • initBuffer string

func (*MockExecutionContext_Expecter) CreateCommand

func (_e *MockExecutionContext_Expecter) CreateCommand(raw interface{}) *MockExecutionContext_CreateCommand_Call

CreateCommand is a helper method to define mock.On call

  • raw string

func (*MockExecutionContext_Expecter) EditorMode

func (_e *MockExecutionContext_Expecter) EditorMode(initBuffer interface{}) *MockExecutionContext_EditorMode_Call

EditorMode is a helper method to define mock.On call

  • initBuffer string

func (*MockExecutionContext_Expecter) FormatMessage

func (_e *MockExecutionContext_Expecter) FormatMessage(msg interface{}, noColor interface{}) *MockExecutionContext_FormatMessage_Call

FormatMessage is a helper method to define mock.On call

  • msg Message
  • noColor bool

func (*MockExecutionContext_Expecter) Print

func (_e *MockExecutionContext_Expecter) Print(data interface{}, attr ...interface{}) *MockExecutionContext_Print_Call

Print is a helper method to define mock.On call

  • data string
  • attr ...color.Attribute

func (*MockExecutionContext_Expecter) PrintToFile

func (_e *MockExecutionContext_Expecter) PrintToFile(data interface{}) *MockExecutionContext_PrintToFile_Call

PrintToFile is a helper method to define mock.On call

  • data string

func (*MockExecutionContext_Expecter) SendRequest

func (_e *MockExecutionContext_Expecter) SendRequest(req interface{}) *MockExecutionContext_SendRequest_Call

SendRequest is a helper method to define mock.On call

  • req string

func (*MockExecutionContext_Expecter) WaitForResponse

func (_e *MockExecutionContext_Expecter) WaitForResponse(timeout interface{}) *MockExecutionContext_WaitForResponse_Call

WaitForResponse is a helper method to define mock.On call

  • timeout time.Duration

type MockExecutionContext_FormatMessage_Call

type MockExecutionContext_FormatMessage_Call struct {
	*mock.Call
}

MockExecutionContext_FormatMessage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatMessage'

func (*MockExecutionContext_FormatMessage_Call) Return

func (*MockExecutionContext_FormatMessage_Call) Run

func (*MockExecutionContext_FormatMessage_Call) RunAndReturn

type MockExecutionContext_PrintToFile_Call

type MockExecutionContext_PrintToFile_Call struct {
	*mock.Call
}

MockExecutionContext_PrintToFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PrintToFile'

func (*MockExecutionContext_PrintToFile_Call) Return

func (*MockExecutionContext_PrintToFile_Call) Run

func (*MockExecutionContext_PrintToFile_Call) RunAndReturn

type MockExecutionContext_Print_Call

type MockExecutionContext_Print_Call struct {
	*mock.Call
}

MockExecutionContext_Print_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Print'

func (*MockExecutionContext_Print_Call) Return

func (*MockExecutionContext_Print_Call) Run

func (*MockExecutionContext_Print_Call) RunAndReturn

type MockExecutionContext_SendRequest_Call

type MockExecutionContext_SendRequest_Call struct {
	*mock.Call
}

MockExecutionContext_SendRequest_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendRequest'

func (*MockExecutionContext_SendRequest_Call) Return

func (*MockExecutionContext_SendRequest_Call) Run

func (*MockExecutionContext_SendRequest_Call) RunAndReturn

type MockExecutionContext_WaitForResponse_Call

type MockExecutionContext_WaitForResponse_Call struct {
	*mock.Call
}

MockExecutionContext_WaitForResponse_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WaitForResponse'

func (*MockExecutionContext_WaitForResponse_Call) Return

func (*MockExecutionContext_WaitForResponse_Call) Run

func (*MockExecutionContext_WaitForResponse_Call) RunAndReturn

type MockFormater

type MockFormater struct {
	mock.Mock
}

MockFormater is an autogenerated mock type for the Formater type

func NewMockFormater

func NewMockFormater(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockFormater

NewMockFormater creates a new instance of MockFormater. 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 (*MockFormater) EXPECT

func (_m *MockFormater) EXPECT() *MockFormater_Expecter

func (*MockFormater) FormatForFile

func (_m *MockFormater) FormatForFile(msgType string, msgData string) (string, error)

FormatForFile provides a mock function with given fields: msgType, msgData

func (*MockFormater) FormatMessage

func (_m *MockFormater) FormatMessage(msgType string, msgData string) (string, error)

FormatMessage provides a mock function with given fields: msgType, msgData

type MockFormater_Expecter

type MockFormater_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockFormater_Expecter) FormatForFile

func (_e *MockFormater_Expecter) FormatForFile(msgType interface{}, msgData interface{}) *MockFormater_FormatForFile_Call

FormatForFile is a helper method to define mock.On call

  • msgType string
  • msgData string

func (*MockFormater_Expecter) FormatMessage

func (_e *MockFormater_Expecter) FormatMessage(msgType interface{}, msgData interface{}) *MockFormater_FormatMessage_Call

FormatMessage is a helper method to define mock.On call

  • msgType string
  • msgData string

type MockFormater_FormatForFile_Call

type MockFormater_FormatForFile_Call struct {
	*mock.Call
}

MockFormater_FormatForFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatForFile'

func (*MockFormater_FormatForFile_Call) Return

func (*MockFormater_FormatForFile_Call) Run

func (*MockFormater_FormatForFile_Call) RunAndReturn

type MockFormater_FormatMessage_Call

type MockFormater_FormatMessage_Call struct {
	*mock.Call
}

MockFormater_FormatMessage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatMessage'

func (*MockFormater_FormatMessage_Call) Return

func (*MockFormater_FormatMessage_Call) Run

func (*MockFormater_FormatMessage_Call) RunAndReturn

type RunOptions

type RunOptions struct {
	OutputFile io.Writer
	Commands   []Executer
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL