keyboard

import "github.com/umbralcalc/stochadex/pkg/keyboard"

Package keyboard provides interactive user input capabilities for stochadex simulations.

Importing it registers the keyboard as a stream transport, so a config steers a run from the keyboard with a stream input, stream: {keyboard: {partition, keys}}, feeding params_from_input (see stream.go). That is the way to use it; UserInputIteration, which reads keys from inside an iteration, is kept for Go code that builds it directly. It enables real-time user interaction during simulation runs through keyboard events, allowing for dynamic control and parameter adjustment during execution.

Key Features:

Usage Patterns:

Index

type KeystrokeChannel

KeystrokeChannel abstracts a source of keyboard events.

Usage hints:

type KeystrokeChannel interface {
    Get(
        partitionIndex int,
        settings *simulator.Settings,
    ) (<-chan keyboard.KeyEvent, error)
}

type StandardKeystrokeChannel

StandardKeystrokeChannel retrieves keystrokes from the terminal.

type StandardKeystrokeChannel struct{}

func (*StandardKeystrokeChannel) Get

func (s *StandardKeystrokeChannel) Get(partitionIndex int, settings *simulator.Settings) (<-chan keyboard.KeyEvent, error)

type UserInputIteration

UserInputIteration provides real-time user interaction during simulation runs through keyboard input handling and action mapping.

This iteration type enables interactive control of simulations by mapping keyboard events to simulation actions. It supports configurable key mappings, timeout handling, and graceful exit functionality.

Interactive Features:

Configuration Parameters:

Key Mapping: Key mappings are configured using parameters named “user_input_keystroke_action_<key>” where <key> is the character that triggers the action. For example:

Example Configuration:

iteration := &UserInputIteration{
    Channel: &StandardKeystrokeChannel{},
}

// Configure key mappings
params.Set("user_input_keystroke_action_p", []float64{1}) // pause
params.Set("user_input_keystroke_action_r", []float64{2}) // resume
params.Set("user_input_keystroke_action_s", []float64{3}) // stop
params.Set("wait_milliseconds", []float64{100})           // 100ms timeout
params.Set("default_value", []float64{0})                 // no action

Usage Patterns:

Thread Safety:

Performance:

Error Handling:

Deprecated: steer a run from the keyboard with a stream input instead, stream: {keyboard: {partition, keys}}, feeding a param_values partition through params_from_input (see stream.go). That works from a YAML config, records what was pressed for replay, and holds a value until the next key. This iteration is kept for Go code that builds it directly.

type UserInputIteration struct {
    Channel KeystrokeChannel
    // contains filtered or unexported fields
}

func (*UserInputIteration) Configure

func (u *UserInputIteration) Configure(partitionIndex int, settings *simulator.Settings)

func (*UserInputIteration) Iterate

func (u *UserInputIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64

Generated by gomarkdoc