2023-07-11 03:41:51 +00:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/Cynosphere/comcord/state"
|
|
|
|
"github.com/ergochat/readline"
|
|
|
|
)
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
func MakePrompt(prompt string, uniqueLine bool, callback func(input string, interrupt bool)) {
|
2023-07-11 03:41:51 +00:00
|
|
|
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
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
callback(input, interrupt)
|
2023-07-11 03:41:51 +00:00
|
|
|
|
|
|
|
state.SetInPrompt(false)
|
|
|
|
state.SetPromptText("")
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
ProcessQueue()
|
2023-07-11 03:41:51 +00:00
|
|
|
}
|