package main

import (
"fmt"
"github.com/c-bata/go-prompt"
"os"
"os/signal"
"syscall"
)

func base(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "1", Description: "网卡配置"},
{Text: "2", Description: "拨号管理"},
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}

func network1(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "1", Description: "网卡1"},
{Text: "2", Description: "网卡2"},
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}
func network2(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "1", Description: "自动获取"},
{Text: "2", Description: "手动配置"},
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}

func input(prompt string) string {
var text string
fmt.Print(prompt)
_, err := fmt.Scan(&text)
if err != nil {
return ""
}
return text
}

func exitHandle(exitChan chan os.Signal) {
for {
select {
case sig := <-exitChan:
_ = sig
//os.Exit(1) //如果ctrl+c 关不掉程序,使用os.Exit强行关掉
}
}

}

func main() {

exitChan := make(chan os.Signal)
signal.Notify(exitChan, os.Interrupt, os.Kill, syscall.SIGTERM)
go exitHandle(exitChan)

LOOP:
fmt.Println("请选择 \n" +
"1 网卡配置 \n2 拨号管理 \n0 返回")
t := prompt.Input("> ", base)

if t == "1" {

fmt.Println("可选择 1 网卡1 2 网卡2")
t1 := prompt.Input("> ", network1)
fmt.Println("You selected 网卡" + t1)
fmt.Println("可选择 1 自动获取 2 手动配置")
t2 := prompt.Input("> ", network2)
fmt.Println("You selected 网卡" + t2)
a := input("ip:")
b := input("network: ")
fmt.Println(a)
fmt.Println(b)
}

goto LOOP

}