optimize tui interface and interaction
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package wizard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
@@ -17,19 +19,18 @@ type Config struct {
|
||||
Timezone string `json:"timezone"`
|
||||
HomePage string `json:"homepage"`
|
||||
DBAddress string `json:"db_address"`
|
||||
DBName string `json:"db_name"`
|
||||
DataAddress string `json:"data_address"`
|
||||
|
||||
// 公网设置
|
||||
PublicInterface string `json:"public_interface"`
|
||||
IPAddress string `json:"ip_address"`
|
||||
Netmask string `json:"netmask"`
|
||||
Gateway string `json:"gateway"`
|
||||
PublicIPAddress string `json:"ip_address"`
|
||||
PublicNetmask string `json:"netmask"`
|
||||
PublicGateway string `json:"gateway"`
|
||||
|
||||
// 内网配置
|
||||
InternalInterface string `json:"internal_interface"`
|
||||
InternalIP string `json:"internal_ip"`
|
||||
InternalMask string `json:"internal_mask"`
|
||||
InternalIPAddress string `json:"internal_ip"`
|
||||
InternalNetmask string `json:"internal_mask"`
|
||||
|
||||
// DNS 配置
|
||||
DNSPrimary string `json:"dns_primary"`
|
||||
@@ -56,40 +57,60 @@ const (
|
||||
|
||||
// model TUI 主模型
|
||||
type model struct {
|
||||
config Config
|
||||
currentPage PageType
|
||||
totalPages int
|
||||
textInputs []textinput.Model
|
||||
inputLabels []string // 存储标签
|
||||
focusIndex int
|
||||
focusType int // 0=输入框, 1=上一步按钮, 2=下一步按钮
|
||||
agreementIdx int // 0=拒绝,1=接受
|
||||
width int
|
||||
height int
|
||||
err error
|
||||
quitting bool
|
||||
done bool
|
||||
force bool
|
||||
config Config
|
||||
currentPage PageType
|
||||
totalPages int
|
||||
networkInterfaces []string // 所有系统网络接口
|
||||
textInputs []textinput.Model
|
||||
inputLabels []string // 存储标签
|
||||
focusIndex int
|
||||
focusType int // 0=输入框, 1=上一步按钮, 2=下一步按钮
|
||||
agreementIdx int // 0=拒绝,1=接受
|
||||
width int
|
||||
height int
|
||||
err error
|
||||
quitting bool
|
||||
done bool
|
||||
force bool
|
||||
}
|
||||
|
||||
// defaultConfig 返回默认配置
|
||||
func defaultConfig() Config {
|
||||
var (
|
||||
defaultPublicInterface string
|
||||
defaultInternalInterface string
|
||||
)
|
||||
interfaces := getNetworkInterfaces()
|
||||
switch len(interfaces) {
|
||||
case 0:
|
||||
defaultPublicInterface = ""
|
||||
defaultInternalInterface = ""
|
||||
case 1:
|
||||
defaultPublicInterface = interfaces[0]
|
||||
defaultInternalInterface = fmt.Sprintf("%s:0", interfaces[0])
|
||||
case 2:
|
||||
defaultPublicInterface = interfaces[0]
|
||||
defaultInternalInterface = interfaces[1]
|
||||
default:
|
||||
defaultPublicInterface = interfaces[0]
|
||||
defaultInternalInterface = interfaces[1]
|
||||
}
|
||||
|
||||
return Config{
|
||||
Hostname: "sunhpc01",
|
||||
Hostname: "cluster.hpc.org",
|
||||
Country: "China",
|
||||
Region: "Beijing",
|
||||
Timezone: "Asia/Shanghai",
|
||||
HomePage: "https://sunhpc.example.com",
|
||||
DBAddress: "127.0.0.1",
|
||||
DBName: "sunhpc_db",
|
||||
DataAddress: "/data/sunhpc",
|
||||
PublicInterface: "eth0",
|
||||
InternalInterface: "eth1",
|
||||
IPAddress: "192.168.1.100",
|
||||
Netmask: "255.255.255.0",
|
||||
Gateway: "192.168.1.1",
|
||||
InternalIP: "10.0.0.100",
|
||||
InternalMask: "255.255.255.0",
|
||||
HomePage: "www.sunhpc.com",
|
||||
DBAddress: "/var/lib/sunhpc/sunhpc.db",
|
||||
DataAddress: "/export/sunhpc",
|
||||
PublicInterface: defaultPublicInterface,
|
||||
PublicIPAddress: "",
|
||||
PublicNetmask: "",
|
||||
PublicGateway: "",
|
||||
InternalInterface: defaultInternalInterface,
|
||||
InternalIPAddress: "172.16.9.254",
|
||||
InternalNetmask: "255.255.255.0",
|
||||
DNSPrimary: "8.8.8.8",
|
||||
DNSSecondary: "8.8.4.4",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user