comcord/lib/prompt.go

34 lines
721 B
Go
Raw Normal View History

2023-07-11 03:41:51 +00:00
package lib
import (
"strings"
"github.com/Cynosphere/comcord/state"
"github.com/bwmarrin/discordgo"
"github.com/ergochat/readline"
)
func MakePrompt(session *discordgo.Session, prompt string, uniqueLine bool, callback func(session *discordgo.Session, input string, interrupt bool)) {
state.SetInPrompt(true)
state.SetPromptText(prompt)
rl, _ := readline.NewFromConfig(&readline.Config{
Prompt: prompt,
UniqueEditLine: uniqueLine,
})
defer rl.Close()
input, err := rl.Readline()
input = strings.TrimSpace(input)
rl.Close()
interrupt := err == readline.ErrInterrupt
callback(session, input, interrupt)
state.SetInPrompt(false)
state.SetPromptText("")
ProcessQueue(session)
}