From ed32c7fea5ad0fefccab9c99a51ebdae13b3a2f2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 16 Mar 2026 23:01:59 +0200 Subject: bump version to v0.2.0 - 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 --- cmd/perc/main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cmd') diff --git a/cmd/perc/main.go b/cmd/perc/main.go index a5764b5..a9faf76 100644 --- a/cmd/perc/main.go +++ b/cmd/perc/main.go @@ -7,6 +7,8 @@ import ( "codeberg.org/snonux/perc/internal" "codeberg.org/snonux/perc/internal/calculator" + "codeberg.org/snonux/perc/internal/repl" + "github.com/mattn/go-isatty" ) func main() { @@ -20,6 +22,11 @@ func main() { func runCommand(args []string) (string, error) { if len(args) < 2 { + // No args provided - check if stdin is a TTY for REPL mode + if isatty.IsTerminal(os.Stdin.Fd()) { + repl.RunREPL() + return "", nil + } printUsage() return "", fmt.Errorf("no input provided") } @@ -28,6 +35,12 @@ func runCommand(args []string) (string, error) { return internal.Version, nil } + // Check for --repl flag + if args[1] == "--repl" || args[1] == "repl" { + repl.RunREPL() + return "", nil + } + input := strings.Join(args[1:], " ") result, err := calculator.Parse(input) if err != nil { @@ -40,9 +53,12 @@ func runCommand(args []string) (string, error) { func printUsage() { fmt.Println("Usage: perc ") fmt.Println(" perc version") + fmt.Println(" perc [--repl|repl]") fmt.Println("\nExamples:") fmt.Println(" perc 20% of 150") fmt.Println(" perc what is 20% of 150") fmt.Println(" perc 30 is what % of 150") fmt.Println(" perc 30 is 20% of what") + fmt.Println("\nStart REPL mode interactively by running without arguments:") + fmt.Println(" perc") } -- cgit v1.2.3