shithub: hell

ref: 6cc3988782312323f3d6453c8bc64f33f3c4d5ba
dir: /commands.go/

View raw version
package main

import (
	"strings"
)

var commands = []string{"examine", "reply", "like", "thread", "open", "preview", "download", "dm", "rt", "parent", "children", "rm", "mark", "unmark", "account", "vim", "import", "pause", "resume"}

func processInput(input string) (command string, arguments string) {

	if input == "" {
		command = ""
		arguments = ""
		return
	}

	if input[0] != '/' {
		command = ""
		arguments = input
		return
	}

	inputcommand, _, hasargument := strings.Cut(input[1:], " ")

	if !hasargument {
		inputcommand = input[1:]
	}

	for _, choice := range commands {
		if strings.HasPrefix(choice, inputcommand) {
			command = choice
			_, arguments, _ = strings.Cut(input, " ")
			return
		}
	}
	return
}