inputhandlers

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtrlA       = 0x01
	CtrlB       = 0x02
	CtrlC       = 0x03
	CtrlD       = 0x04
	CtrlE       = 0x05
	CtrlF       = 0x06
	CtrlN       = 0x0E
	CtrlP       = 0x10 // paste whatever is in the clipboard - This is kinda special and the clipboard should usually be empty unless you're
	CtrlQ       = 0x11 // shortcut for /quit
	CtrlR       = 0x12
	CtrlS       = 0x13
	CtrlT       = 0x14
	CtrlU       = 0x15
	CtrlV       = 0x16
	CtrlW       = 0x17
	CtrlX       = 0x18
	CtrlY       = 0x19
	CtrlZ       = 0x1A
	CtrlBkSlash = 0x1C
)
View Source
const SystemCommandPrefix = "/"

Variables

View Source
var (
	ErrInputRequired        = errors.New(`input required`)
	ErrInvalidResponse      = errors.New(`invalid response`)
	ErrPasswordsDidNotMatch = errors.New(`your passwords did not match`)
)

Functions

func AddIACHandler

func AddIACHandler(h IACHandler)

func AlwaysRun

func AlwaysRun(_ map[string]string) bool

AlwaysRun is a default ConditionFunc that always returns true.

func AnsiHandler

func AnsiHandler(clientInput *connections.ClientInput, sharedState map[string]any) (nextHandler bool)

func CleanserInputHandler

func CleanserInputHandler(clientInput *connections.ClientInput, sharedState map[string]any) (nextHandler bool)

CleanserInputHandler's job is to remove any bad characters from the input stream before passing it down the chain. For this reason, it's important it happen before other text processing handlers

func CreatePromptHandler

func CreatePromptHandler(steps []*PromptStep, onComplete CompletionFunc) connections.InputHandler

CreatePromptHandler creates a generic input handler for multi-step prompts.

func DefaultValidator

func DefaultValidator(input string, _ map[string]string) (string, error)

DefaultValidator is a basic validator that accepts any non-empty input.

func EchoInputHandler

func EchoInputHandler(clientInput *connections.ClientInput, sharedState map[string]any) (nextHandler bool)

func FinalizeLoginOrCreate

func FinalizeLoginOrCreate(results map[string]string, sharedState map[string]any, clientInput *connections.ClientInput) bool

FinalizeLoginOrCreate is called after all prompts are successfully answered.

func GetLoginPromptHandler

func GetLoginPromptHandler() connections.InputHandler

func HistoryInputHandler

func HistoryInputHandler(clientInput *connections.ClientInput, sharedState map[string]any) (nextHandler bool)

All this does is manage the input history stack

func SignalHandler

func SignalHandler(clientInput *connections.ClientInput, sharedState map[string]any) (nextHandler bool)

This should be the first handler in the chain It will convert any special signals like CTRL-C into a /quit command

func SystemCommandInputHandler

func SystemCommandInputHandler(clientInput *connections.ClientInput, sharedState map[string]any) (nextHandler bool)

func TelnetIACHandler

func TelnetIACHandler(clientInput *connections.ClientInput, sharedState map[string]any) (nextHandler bool)

func ValidateEmail

func ValidateEmail(input string, results map[string]string) (string, error)

func ValidateNewEntry

func ValidateNewEntry(input string, _ map[string]string) (string, error)

func ValidatePassword

func ValidatePassword(input string, _ map[string]string) (string, error)

func ValidatePassword2

func ValidatePassword2(input string, results map[string]string) (string, error)

func ValidateUsername

func ValidateUsername(input string, _ map[string]string) (string, error)

Specific Validators

func ValidateYesNo

func ValidateYesNo(input string, _ map[string]string) (string, error)

Types

type CompletionFunc

type CompletionFunc func(results map[string]string, sharedState map[string]any, clientInput *connections.ClientInput) bool

CompletionFunc is called when all steps are successfully completed. It receives the accumulated results and the shared state. It should return true if the overall process succeeded and the handler can be removed, false otherwise (e.g., login failed, disconnect).

type ConditionFunc

type ConditionFunc func(results map[string]string) bool

ConditionFunc defines a function type to determine if a step should be executed. It takes the accumulated results so far.

type DataFunc

type DataFunc func(results map[string]string) map[string]any

DataFunc generates dynamic data for a prompt step based on prior results.

type IACHandler

type IACHandler interface {
	HandleIAC(uint64, []byte) bool
}

type PromptHandlerState

type PromptHandlerState struct {
	Steps            []*PromptStep
	CurrentStepIndex int
	Results          map[string]string
	OnComplete       CompletionFunc
	// contains filtered or unexported fields
}

PromptHandlerState holds the current state of the multi-step prompt process for a connection.

type PromptStep

type PromptStep struct {
	ID             string         // Unique identifier for this step's result
	PromptTemplate string         // Template name for the prompt message
	GetDataFunc    DataFunc       // Function to generate template data dynamically (optional)
	MaskInput      bool           // Should the input be masked?
	MaskTemplate   string         // Template for the mask character (optional)
	Validator      ValidationFunc // Function to validate the input, if returns false, repeat prompt
	Condition      ConditionFunc  // Do this step unless Condition Function returns false
	FailureCount   int            // Can be added if needed, managed within PromptHandlerState
}

PromptStep defines a single step in a multi-step prompt process.

type SystemCommandHelp

type SystemCommandHelp struct {
	Description  string
	Details      string
	ExampleInput string
}

type ValidationFunc

type ValidationFunc func(input string, results map[string]string) (string, error)

ValidationFunc defines a function type for validating user input for a step. It takes the raw input and the accumulated results so far. It returns the cleaned/validated value (or an empty string) and an error if validation fails.

Jump to

Keyboard shortcuts

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