keyboard

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

Package keyboard provides interactive user input capabilities for stochadex simulations. 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:

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