Tui fix focus

This commit is contained in:
2026-02-28 19:29:17 +08:00
parent 13beeb67d1
commit f7dcfa4e7d
6 changed files with 302 additions and 194 deletions

View File

@@ -20,24 +20,26 @@ type Config struct {
AgreementAccepted bool `json:"agreement_accepted"`
// 数据接收
Hostname string `json:"hostname"`
Country string `json:"country"`
Region string `json:"region"`
Timezone string `json:"timezone"`
HomePage string `json:"homepage"`
DBAddress string `json:"db_address"`
Software string `json:"software"`
ClusterName string `json:"cluster_name"`
Country string `json:"country"`
Region string `json:"region"`
Timezone string `json:"timezone"`
HomePage string `json:"homepage"`
DBAddress string `json:"db_address"`
Software string `json:"software"`
// 公网设置
PublicInterface string `json:"public_interface"`
PublicIPAddress string `json:"ip_address"`
PublicNetmask string `json:"netmask"`
PublicGateway string `json:"gateway"`
PublicMTU string `json:"public_mtu"`
// 内网配置
InternalInterface string `json:"internal_interface"`
InternalIPAddress string `json:"internal_ip"`
InternalNetmask string `json:"internal_mask"`
PrivateInterface string `json:"private_interface"`
PrivateIPAddress string `json:"private_ip"`
PrivateNetmask string `json:"private_mask"`
PrivateMTU string `json:"private_mtu"`
// DNS 配置
DNSPrimary string `json:"dns_primary"`
@@ -96,23 +98,24 @@ func defaultConfig() Config {
}
return Config{
License: "This test license is for testing purposes only. Do not use it in production.",
Hostname: "cluster.hpc.org",
Country: "China",
Region: "Beijing",
Timezone: "Asia/Shanghai",
HomePage: "www.sunhpc.com",
DBAddress: "/var/lib/sunhpc/sunhpc.db",
Software: "/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",
License: "This test license is for testing purposes only. Do not use it in production.",
ClusterName: "cluster.hpc.org",
Country: "China",
Region: "Beijing",
Timezone: "Asia/Shanghai",
HomePage: "www.sunhpc.com",
DBAddress: "/var/lib/sunhpc/sunhpc.db",
Software: "/export/sunhpc",
PublicInterface: defaultPublicInterface,
PublicIPAddress: "",
PublicNetmask: "",
PublicGateway: "",
PrivateInterface: defaultInternalInterface,
PrivateIPAddress: "172.16.9.254",
PrivateNetmask: "255.255.255.0",
PrivateMTU: "1500",
DNSPrimary: "8.8.8.8",
DNSSecondary: "8.8.4.4",
}
}
@@ -132,7 +135,7 @@ func initialModel() model {
// ------------------ 页面2基础信息页面 --------------------
page2Comps := make(map[string]Focusable)
page2Comps["Homepage_input"] = NewTextInput("Homepage", cfg.HomePage)
page2Comps["Hostname_input"] = NewTextInput("Hostname", cfg.Hostname)
page2Comps["ClusterName_input"] = NewTextInput("ClusterName", cfg.ClusterName)
page2Comps["Country_input"] = NewTextInput("Country", cfg.Country)
page2Comps["Region_input"] = NewTextInput("Region", cfg.Region)
page2Comps["Timezone_input"] = NewTextInput("Timezone", cfg.Timezone)
@@ -148,15 +151,17 @@ func initialModel() model {
page3Comps["PublicIPAddress_input"] = NewTextInput("PublicIPAddress", cfg.PublicIPAddress)
page3Comps["PublicNetmask_input"] = NewTextInput("PublicNetmask", cfg.PublicNetmask)
page3Comps["PublicGateway_input"] = NewTextInput("PublicGateway", cfg.PublicGateway)
page3Comps["PublicMTU_input"] = NewTextInput("PublicMTU", cfg.PublicMTU)
page3Comps["next_btn"] = NewButton("下一步")
page3Comps["prev_btn"] = NewButton("上一步")
pageComponents[PagePublicNetwork] = page3Comps
// ------------------ 页面4内网网络页面 --------------------
page4Comps := make(map[string]Focusable)
page4Comps["InternalInterface_input"] = NewTextInput("InternalInterface", cfg.InternalInterface)
page4Comps["InternalIPAddress_input"] = NewTextInput("InternalIPAddress", cfg.InternalIPAddress)
page4Comps["InternalNetmask_input"] = NewTextInput("InternalNetmask", cfg.InternalNetmask)
page4Comps["PrivateInterface_input"] = NewTextInput("PrivateInterface", cfg.PrivateInterface)
page4Comps["PrivateIPAddress_input"] = NewTextInput("PrivateIPAddress", cfg.PrivateIPAddress)
page4Comps["PrivateNetmask_input"] = NewTextInput("PrivateNetmask", cfg.PrivateNetmask)
page4Comps["PrivateMTU_input"] = NewTextInput("PrivateMTU", cfg.PrivateMTU)
page4Comps["next_btn"] = NewButton("下一步")
page4Comps["prev_btn"] = NewButton("上一步")
pageComponents[PageInternalNetwork] = page4Comps
@@ -199,11 +204,13 @@ func (m model) Init() tea.Cmd {
// Update 处理消息更新
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c":
m.quitting = true
m.saveConfig()
//m.quitting = true
return m, tea.Quit
// 1. 焦点切换Tab/Shift+Tab交给管理器处理
@@ -213,6 +220,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// 2. 回车键:处理当前焦点组件的点击/确认
case "enter":
currentCompID := m.focusManager.currentFocusID
switch currentCompID {
// 页1accept → 进入页2
@@ -232,7 +240,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// 页6确认配置 → 退出并保存
case "confirm_btn":
m.done = true
m.quitting = true
//m.quitting = true
return m, tea.Quit
case "cancel_btn":
@@ -258,8 +266,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// 页2基础信息
case "Homepage_input":
m.config.HomePage = comp.Value()
case "Hostname_input":
m.config.Hostname = comp.Value()
case "ClusterName_input":
m.config.ClusterName = comp.Value()
case "Country_input":
m.config.Country = comp.Value()
case "Region_input":
@@ -280,14 +288,18 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.config.PublicNetmask = comp.Value()
case "PublicGateway_input":
m.config.PublicGateway = comp.Value()
case "PublicMTU_input":
m.config.PublicMTU = comp.Value()
// 页4内网网络
case "InternalInterface_input":
m.config.InternalInterface = comp.Value()
case "InternalIPAddress_input":
m.config.InternalIPAddress = comp.Value()
case "InternalNetmask_input":
m.config.InternalNetmask = comp.Value()
case "PrivateInterface_input":
m.config.PrivateInterface = comp.Value()
case "PrivateIPAddress_input":
m.config.PrivateIPAddress = comp.Value()
case "PrivateNetmask_input":
m.config.PrivateNetmask = comp.Value()
case "PrivateMTU_input":
m.config.PrivateMTU = comp.Value()
// 页5DNS
case "Pri_DNS_input":