summaryrefslogtreecommitdiff
path: root/internal/repl/repl.go
AgeCommit message (Collapse)Author
2026-05-24fix(rpn): change variadic NewRPN/NewOperations to single optional ↵Paul Buetow
MetricReader (task ok)
2026-05-24refactor(repl): introduce RPNCalculator interface to fix DIP violation (task rj)Paul Buetow
Handlers accessed repl.rpnState.rpnCalc — three levels of concrete types violating DIP and Law of Demeter. Define an RPNCalculator interface capturing only the methods handlers actually need, and expose it via REPL.RpnCalculator() so handlers depend on the interface, not the concrete chain of *rpn.RPN.
2026-05-24docs(repl): fix inaccurate comments in repl.goPaul Buetow
- NewRPNState: correct 'config directory' to 'state directory' (XDG state, not config) - REPL struct: change 'percentage calculator' to 'calculator' (it's primarily RPN) - NewREPL: clarify that completer parameter is unused and logWriter is only stored - defaultExecutor: remove claim that 'handled commands are added to history' (code does the opposite) - defaultCompleter: remove claim about case-insensitivity and descriptions (not implemented) - RunREPLWithLog: remove claim about logging input/output (logWriter is stored but not used)
2026-05-23style: run gofmt on all Go source filesPaul Buetow
Fix formatting in 12 files to match gofmt standards. No logical changes.
2026-05-23refactor: remove Calculator/RPNCalculator passthrough adapter (KISS)Paul Buetow
Delete internal/repl/calculator.go which defined the Calculator interface and RPNCalculator adapter. Every method delegated directly to *rpn.RPN with zero transformation — unnecessary indirection. RPNState now holds *rpn.RPN directly instead of the Calculator interface. Updated NewRPNState, NewREPL, handleRatCommand, and RPNHandler.Handle() to access *rpn.RPN directly. Removes 71 net lines, zero behavioral changes.
2026-05-22fix(repl): remove unreachable return in ReadlinePrompt.RunPaul Buetow
Task fe: The infinite for loop in Run() can only exit via return (fmt.Errorf on readline error). The trailing 'return nil' was dead code flagged by go vet. Removed.
2026-04-11Multiple code-quality and feature improvementsPaul Buetow
- Task 31: Refactor repl tests to remove dependency on package-level singletons - Task 41: Introduce Calculator interface to decouple REPL from RPN engine - Task 61: Implement persistent variable store with Save/Load methods - Task 71: Add stack inspection (peek) command to REPL - Task 81: Expand constants library with additional mathematical constants - Task a1: Add session logging flag (--log) to gt CLI - Task 91: Integrate reverse history search (Ctrl+R) using readline This commit includes: - New: internal/repl/calculator.go - Calculator interface for RPN decoupling - New: internal/repl/completer.go - AutoCompleteAdapter for readline - Modified: internal/repl/repl.go - Uses readline instead of go-prompt - Modified: internal/rpn/variables.go - Added Save/Load for persistent state - Modified: internal/rpn/rpn_state.go - Added Stack() method - Modified: internal/rpn/constants.go - Added more mathematical constants - Modified: internal/repl/commands.go - Added 'stack' command - Modified: internal/repl/completer_test.go - Updated for readline API - Modified: internal/repl/repl_test.go - Updated for Calculator interface - Modified: internal/repl/concurrent_test.go - Updated for Calculator interface - Modified: internal/repl/handlers.go - Updated for Calculator interface - Modified: internal/rpn/variables_test.go - Added Save/Load tests - Modified: internal/rpn/constants_test.go - Added new constant tests - Modified: cmd/gt/main.go - Added --log flag support - Modified: Magefile.go - Symmetrized Install/Uninstall logic - Deleted: internal/repl/prompt.go - Replaced by readline integration - Added: STORY.md - Project history documentation
2026-04-11more on thisPaul Buetow
2026-03-26fix modulePaul Buetow
2026-03-25code-quality: Various improvements to code quality and thread safetyPaul Buetow
2026-03-25docs: Add SPDX license headers to all .go source filesPaul Buetow
- Added 'SPDX-License-Identifier: MIT' and 'Copyright (c) 2026 Paul Buetow' headers - Files updated: 24 .go files across cmd/gt/, internal/calculator/, internal/repl/, internal/rpn/ The MIT license from LICENSE file is reflected in all source files.
2026-03-25refactor: Consolidate REPL command descriptions to single sourcePaul Buetow
- Removed duplicate getCommandDescription function from completer.go - Added package-level getCommandDescription in repl.go as single source of truth - Updated defaultGetCommandDescription to delegate to getCommandDescription - Created minimal completer.go that uses getCommandDescription for test compatibility Command descriptions are now defined only once, eliminating duplication between the original completer.go and defaultGetCommandDescription in repl.go. The refactoring maintains: - Backward compatibility (tests still work) - Consistent descriptions across the codebase - Single source of truth for command descriptions
2026-03-25docs: Add comprehensive Go documentation for REPL functionsPaul Buetow
- Enhanced NewREPL documentation with detailed parameter descriptions - Enhanced RunREPL documentation clarifying it's a convenience wrapper - Improved executor documentation explaining backward compatibility and testing usage - Enhanced defaultExecutor documentation with input processing details and panic recovery - Enhanced defaultCompleter documentation with tab-completion behavior details - Enhanced defaultGetCommandDescription documentation with command description details - Improved TTYChecker methods (IsTTY, EnsureTTY) documentation - Improved SignalHandler.Start method documentation All exported and non-exported functions in the REPL package now have comprehensive documentation comments that describe their purpose, parameters, and return values.
2026-03-24refactor: Move RPNState and related declarations to top of repl.goPaul Buetow
- Move RPNState type definition before any functions - Move rpnState and rpnStateOnce variable declarations before any functions - Keep REPL struct and NewREPL constructor at the top (as per Go best practices) - Update getRPNState comment to be more descriptive This change follows Go best practices where constants, global variables, and type definitions should be at the top of the file before functions.
2026-03-24feat: Add RPN mode, rational number support, and improve REPLPaul Buetow
- Add RPN (Reverse Polish Notation) calculator with stack-based operations - Support precise rational number calculations using *big.Rat - Implement chain of responsibility pattern for command handling - Add auto-completion for built-in commands - Add history persistence with configurable max entries - Support standard operators: +, -, *, /, ^, %, lg, log, ln - Support hyper operators: [+], [-], [*], [/], [^], [%], [lg], [log], [ln] - Support stack manipulation: dup, swap, pop, show - Support variable assignments and management - Add rat mode for switching between float64 and rational calculations - Refactor calculator to return Calculation struct with formatting - Add proper version support (v0.3.0) All changes follow Go best practices with comprehensive test coverage.
2026-03-23Add panic recovery to REPL executor for better resiliencePaul Buetow
Added defer-recover mechanism to the executor function to catch unexpected panics. When a panic occurs, a user-friendly error message is displayed and the REPL can continue to function. This improves the robustness of the REPL when handling unexpected errors.
2026-03-23Code quality audit fixes from comprehensive auditPaul Buetow
- Error wrapping improvements across multiple files - Thread-safe singleton initialization using sync.Once - Proper error handling for file close operations - Removed speculative complexity in history management - Fixed operator interface design Audit report: COMPLETE_AUDIT_REPORT.md
2026-03-23Fix errcheck issues in cmd/perc, internal/repl, and internal/rpn packagesPaul Buetow
2026-03-23.golangci.ymlPaul Buetow
2026-03-23Replace global variable with function in internal/replPaul Buetow
2026-03-23Fix global variable in repl.go with mutex protectionPaul Buetow
2026-03-20internal/repl: Reorder functions per Go best practicesPaul Buetow
- Moved public RunREPL function before private functions - Constructor-like getRPNState immediately follows type definition - This aligns with project Go best practices for file organization
2026-03-20feat: Implement persistent RPN state for all RPN-related inputPaul Buetow
- Modified ParseAndEvaluate() to not reset stack at beginning, only initialize if nil - Changed runRPN() to use getRPNState() for persistent state across calls - Fixed Stack type definition ordering in variables.go to follow Go best practices - Updated tests to create fresh RPN instances where independence is needed This enables REPL-style incremental RPN calculations like '3 4 +' followed by '5 +'.
2026-03-20refactor: update Operations to use VariableStore interfacePaul Buetow
- Changed Operations.vars from *Variables to VariableStore interface - Changed NewOperations to accept VariableStore interface - Changed RPN.vars from *Variables to VariableStore interface - Changed NewRPN to accept VariableStore interface - Removed type assertions in main.go and repl.go - Added FormatVariables to VariableStore interface - All tests pass, build successful
2026-03-20internal/rpn/rpn.go: fix stack state persistence for ParseAndEvaluatePaul Buetow
- Reset currentStack at start of each ParseAndEvaluate call - This ensures test isolation while allowing incremental operations - Added tests for EvalOperator for incremental RPN evaluation - All tests pass, coverage 79.2% for rpn package
2026-03-20README.md: add REPL mode notes about independent command evaluationPaul Buetow
2026-03-20cmd/perc/main.go: try RPN parsing before percentage calculation in command modePaul Buetow
- Bare expressions like '1 2 +' now work without 'calc' prefix - Assignment format 'name value =' requires 'calc' subcommand prefix
2026-03-20internal/repl: add RPN support to REPLPaul Buetow
- Import rpn package in repl.go - Add 'rpn' and 'calc' as built-in commands - Update executor to handle 'rpn <expr>' and 'calc <expr>' commands - Add rpn/calc descriptions to help text - All tests pass, go vet passes
2026-03-16bump version to v0.2.0v0.2.0Paul Buetow
- Add REPL mode with vi keybindings - Add built-in commands (help, clear, quit/exit) - Add mage repl target Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>