shithub: hell

Download patch

ref: 613aaa101f1ca88bbfcd9d6fa168a69115c16109
parent: a21cb39658ab419bec6f5af6311e319f02551acd
author: penny <penny@limitedideas.org>
date: Sat Aug 2 16:20:57 EDT 2025

New, lazier evaluator

--- a/commands.go
+++ b/commands.go
@@ -4,7 +4,7 @@
 	"strings"
 )
 
-var commands = []string{"examine", "reply", "like", "thread", "open", "preview", "dm", "rt", "parent", "children", "thread", "rm", "download"}
+var commands = []string{"examine", "reply", "like", "thread", "open", "preview", "dm", "rt", "parent", "children", "rm", "download"}
 
 func processInput(input string) (command string, arguments string) {
 
@@ -19,28 +19,18 @@
 		arguments = input
 		return
 	}
-
-	input = input[1:]
-
-	command = "Command not found"
-	arguments = ""
-	commandInput := ""
-
-	firstSpaceIdx := strings.Index(input, " ")
-
-	if firstSpaceIdx == -1 {
-		commandInput = input
-		arguments = ""
-	} else {
-		commandInput = input[:firstSpaceIdx]
-		arguments = strings.TrimSpace(input[firstSpaceIdx+1:])
+	
+	inputcommand, _, hasargument := strings.Cut(input[1:], " ")
+	
+	if(!hasargument) {
+		inputcommand = input[1:]
 	}
 
-	for _, cmd := range commands {
-		if strings.HasPrefix(cmd, commandInput) {
-			if command == "" || len(cmd) < len(command) {
-				command = cmd
-			}
+	for _, choice := range commands {
+		if strings.HasPrefix(choice, inputcommand) {
+			command = choice
+			_, arguments, _ = strings.Cut(input, " ")
+			return
 		}
 	}
 	return
--