mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Backup support
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TermMessage sends a message to the user in the terminal. This usually occurs before
|
||||
@@ -25,6 +26,38 @@ func TermMessage(msg ...interface{}) {
|
||||
TempStart(screenb)
|
||||
}
|
||||
|
||||
// TermPrompt prints a prompt and requests the user for a response
|
||||
// The result is matched against a list of options and the index of
|
||||
// the match is returned
|
||||
// If wait is true, the prompt re-prompts until a valid option is
|
||||
// chosen, otherwise if wait is false, -1 is returned for no match
|
||||
func TermPrompt(prompt string, options []string, wait bool) int {
|
||||
screenb := TempFini()
|
||||
|
||||
idx := -1
|
||||
// same behavior as do { ... } while (wait && idx == -1)
|
||||
for ok := true; ok; ok = wait && idx == -1 {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Print(prompt)
|
||||
resp, _ := reader.ReadString('\n')
|
||||
resp = strings.TrimSpace(resp)
|
||||
|
||||
for i, opt := range options {
|
||||
if resp == opt {
|
||||
idx = i
|
||||
}
|
||||
}
|
||||
|
||||
if wait && idx == -1 {
|
||||
fmt.Println("\nInvalid choice.")
|
||||
}
|
||||
}
|
||||
|
||||
TempStart(screenb)
|
||||
|
||||
return idx
|
||||
}
|
||||
|
||||
// TermError sends an error to the user in the terminal. Like TermMessage except formatted
|
||||
// as an error
|
||||
func TermError(filename string, lineNum int, err string) {
|
||||
|
||||
Reference in New Issue
Block a user