You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.7 KiB
79 lines
1.7 KiB
package ui
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/inancgumus/screen"
|
|
)
|
|
|
|
func ClearScreen() {
|
|
screen.Clear()
|
|
screen.MoveTopLeft()
|
|
}
|
|
|
|
func DisplayStartScreen() {
|
|
ClearScreen()
|
|
fmt.Println("========================================")
|
|
fmt.Println(" Welcome to ServiceTrade CLI")
|
|
fmt.Println("========================================")
|
|
fmt.Println("Please log in with your ServiceTrade credentials to continue.")
|
|
fmt.Println()
|
|
}
|
|
|
|
func PromptCredentials() (string, string, error) {
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
fmt.Print("Enter your email: ")
|
|
email, _ := reader.ReadString('\n')
|
|
email = strings.TrimSpace(email)
|
|
|
|
fmt.Print("Enter your password: ")
|
|
password, _ := reader.ReadString('\n')
|
|
password = strings.TrimSpace(password)
|
|
|
|
return email, password, nil
|
|
}
|
|
|
|
func DisplayMessage(message string) {
|
|
fmt.Println(message)
|
|
}
|
|
|
|
func DisplayError(prefix string, err error) {
|
|
fmt.Printf("%s %v\n", prefix, err)
|
|
}
|
|
|
|
func PressEnterToContinue() {
|
|
fmt.Println("Press Enter to continue...")
|
|
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
|
}
|
|
|
|
func DisplayMenu(items []string, title string) {
|
|
ClearScreen()
|
|
fmt.Printf("\n%s:\n", title)
|
|
for i, item := range items {
|
|
fmt.Printf("%d. %s\n", i+1, item)
|
|
}
|
|
}
|
|
|
|
func GetUserChoice(max int) (int, error) {
|
|
reader := bufio.NewReader(os.Stdin)
|
|
fmt.Printf("\nEnter your choice (1-%d): ", max)
|
|
input, _ := reader.ReadString('\n')
|
|
input = strings.TrimSpace(input)
|
|
choice, err := strconv.Atoi(input)
|
|
if err != nil || choice < 1 || choice > max {
|
|
return 0, fmt.Errorf("invalid input")
|
|
}
|
|
return choice, nil
|
|
}
|
|
|
|
func PromptForInput(prompt string) string {
|
|
reader := bufio.NewReader(os.Stdin)
|
|
fmt.Print(prompt)
|
|
input, _ := reader.ReadString('\n')
|
|
return strings.TrimSpace(input)
|
|
}
|
|
|