Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidMetaCommand = errors.New("invalid meta-command") ErrInvalidMetaValue = errors.New("invalid value") )
View Source
var ( ErrAmbiguousPrefix = fmt.Errorf("ambiguous prefix") ErrPrefixNotFound = fmt.Errorf("prefix not found") )
View Source
var ErrEnvironmentMissing = errors.New("environment missing")
Functions ¶
func Evaluate ¶
Evaluate parses expr and evaluates it in the given environment. The caller is responsible for trimming whitespace from expr.
func NewCommand ¶
NewCommand creates a new calculator command.
Expressions can be passed as one or more arguments. If no arguments are provided and STDIN is a TTY, it will start a REPL. Otherwise, the command will return ErrNotTTY.
Types ¶
type Calculator ¶
type Calculator struct {
DecimalPlaces int
KeepTrailingZeros bool
UnderscoreZeros bool
Verbose bool
Trace bool
// contains filtered or unexported fields
}
func (*Calculator) DisplayError ¶
func (c *Calculator) DisplayError(err error)
func (*Calculator) DisplayResult ¶
func (c *Calculator) DisplayResult(res *unified.Real)
func (*Calculator) Execute ¶
func (c *Calculator) Execute(expr string)
func (*Calculator) ProcessSTDIN ¶
func (c *Calculator) ProcessSTDIN() error
ProcessSTDIN reads expressions from STDIN and evaluates them line by line. This is used for non-interactive mode (e.g., piped input).
func (*Calculator) REPL ¶
func (c *Calculator) REPL() error
type ExecutionMode ¶
type ExecutionMode int
ExecutionMode represents the context in which an expression is being evaluated
const ( // ModeREPL represents interactive REPL mode. Results are displayed and errors reported normally. ModeREPL ExecutionMode = iota // ModeSTDIN represents non-interactive mode reading from STDIN. Results are displayed and errors reported normally. ModeSTDIN // ModeLoad represents loading a saved session. Results are not displayed; errors are reported as warnings. ModeLoad )
type SettingDescriptor ¶
type SettingDescriptor struct {
Type SettingType // bool or int
Description string // Help text
// Type-safe accessors using closures
GetBool func(*Calculator) bool
SetBool func(*Calculator, bool)
GetInt func(*Calculator) int
SetInt func(*Calculator, int)
// Optional validation for int types
ValidateInt func(int) error
}
SettingDescriptor contains all metadata for a setting
type SettingType ¶
type SettingType int
SettingType represents the data type of a setting
const ( SettingTypeBool SettingType = iota SettingTypeInt )
Click to show internal directories.
Click to hide internal directories.