optimize tui interface and interaction
This commit is contained in:
@@ -45,43 +45,39 @@ func (m model) View() string {
|
||||
|
||||
// agreementView 协议页面
|
||||
func (m model) agreementView() string {
|
||||
title := titleStyle.Render("SunHPC 系统初始化向导")
|
||||
subtitle := subTitleStyle.Render("请先阅读并同意以下协议")
|
||||
title := titleStyle.Render("SunHPC Software License Agreement")
|
||||
|
||||
agreement := agreementBox.Render(`
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ SunHPC 软件许可协议 │
|
||||
│ SunHPC License Agreement │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
|
||||
1. 许可授予
|
||||
本软件授予您非独占、不可转让的使用许可。
|
||||
|
||||
2. 使用限制
|
||||
- 不得用于非法目的
|
||||
- 不得反向工程或反编译
|
||||
- 不得移除版权标识
|
||||
|
||||
3. 免责声明
|
||||
本软件按"原样"提供,不提供任何明示或暗示的保证。
|
||||
|
||||
4. 责任限制
|
||||
在任何情况下,作者不对因使用本软件造成的任何损失负责。
|
||||
|
||||
5. 协议终止
|
||||
如违反本协议条款,许可将自动终止。
|
||||
|
||||
1. License Grant
|
||||
This software grants you a non-exclusive, non-transferable
|
||||
license to use it.
|
||||
2. Disclaimer of Warranties
|
||||
This software is provided "as is" without any warranties,
|
||||
whether express or implied.
|
||||
3. Limitation of Liability
|
||||
This software is provided without warranty of any kind,
|
||||
either express or implied.
|
||||
In no event shall the author be liable for any damages
|
||||
arising out of the use of this software.
|
||||
4. Termination of Agreement
|
||||
If you violate any of the terms of this agreement,
|
||||
the license will automatically terminate.
|
||||
───────────────────────────────────────────────────────────────
|
||||
请仔细阅读以上条款,点击"接受"表示您同意并遵守本协议。
|
||||
PLEASE READ THE ABOVE TERMS CAREFULLY AND CLICK "ACCEPT"
|
||||
TO AGREE AND FOLLOW THIS AGREEMENT.
|
||||
───────────────────────────────────────────────────────────────
|
||||
`)
|
||||
|
||||
var acceptBtn, rejectBtn string
|
||||
if m.agreementIdx == 0 {
|
||||
rejectBtn = selectedButton.Render(">> 拒绝 <<")
|
||||
acceptBtn = selectedButton.Render(" 同意 ")
|
||||
rejectBtn = selectedButton.Render(">> Reject <<")
|
||||
acceptBtn = " Accept "
|
||||
} else {
|
||||
rejectBtn = selectedButton.Render(" 拒绝 ")
|
||||
acceptBtn = selectedButton.Render(">> 同意 <<")
|
||||
rejectBtn = " Reject "
|
||||
acceptBtn = selectedButton.Render(">> Accept <<")
|
||||
}
|
||||
|
||||
buttonGroup := lipgloss.JoinHorizontal(
|
||||
@@ -92,11 +88,9 @@ func (m model) agreementView() string {
|
||||
// debugInfo := lipgloss.NewStyle().Foreground(lipgloss.Color("#888888")).
|
||||
// Render(fmt.Sprintf("[DEBUG: idx=%d]", m.agreementIdx),)
|
||||
|
||||
hint := hintStyle.Render("使用 <- -> 或 Tab 选择,Enter 确认")
|
||||
|
||||
hint := hintStyle.Render("Use Up/Down OR Tab Change,Enter Confirm")
|
||||
return lipgloss.JoinVertical(lipgloss.Center,
|
||||
title, "",
|
||||
subtitle, "",
|
||||
agreement, "",
|
||||
buttonGroup, "",
|
||||
// debugInfo, "", // ✅ 显示调试信息
|
||||
@@ -106,8 +100,7 @@ func (m model) agreementView() string {
|
||||
|
||||
// dataView 数据接收页面
|
||||
func (m model) dataView() string {
|
||||
title := titleStyle.Render("集群基础配置")
|
||||
subtitle := subTitleStyle.Render("请填写系统基本信息")
|
||||
title := titleStyle.Render("Cluster Information")
|
||||
|
||||
var inputs strings.Builder
|
||||
for i, ti := range m.textInputs {
|
||||
@@ -117,11 +110,9 @@ func (m model) dataView() string {
|
||||
}
|
||||
|
||||
buttons := m.renderNavButtons()
|
||||
|
||||
hint := hintStyle.Render("使用 Up/Down 或 Tab 切换、Enter 确认")
|
||||
hint := hintStyle.Render("Use Up/Down OR Tab Change,Enter Confirm")
|
||||
return lipgloss.JoinVertical(lipgloss.Center,
|
||||
title, "",
|
||||
subtitle, "",
|
||||
inputs.String(), "",
|
||||
buttons, "",
|
||||
hint,
|
||||
@@ -130,25 +121,24 @@ func (m model) dataView() string {
|
||||
|
||||
// publicNetworkView 公网设置页面
|
||||
func (m model) publicNetworkView() string {
|
||||
title := titleStyle.Render("公网配置")
|
||||
subtitle := subTitleStyle.Render("请配置网络接口信息")
|
||||
title := titleStyle.Render("Public Network Configuration")
|
||||
|
||||
autoDetect := infoStyle.Render("[*] 自动检测网络接口: eth0, eth1, ens33")
|
||||
networkInterfaces := getNetworkInterfaces()
|
||||
autoDetect := infoStyle.Render(
|
||||
"[*] Auto Detect Network Interfaces: " + strings.Join(networkInterfaces, ", "))
|
||||
|
||||
var inputs strings.Builder
|
||||
for i, ti := range m.textInputs {
|
||||
info := fmt.Sprintf("%-10s|", m.inputLabels[i])
|
||||
info := fmt.Sprintf("%-20s|", m.inputLabels[i])
|
||||
input := inputBox.Render(info + ti.View())
|
||||
inputs.WriteString(input + "\n")
|
||||
}
|
||||
|
||||
buttons := m.renderNavButtons()
|
||||
|
||||
hint := hintStyle.Render("使用 Up/Down 或 Tab 切换、Enter 确认")
|
||||
hint := hintStyle.Render("Use Up/Down OR Tab Change,Enter Confirm")
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Center,
|
||||
title, "",
|
||||
subtitle, "",
|
||||
autoDetect, "",
|
||||
inputs.String(), "",
|
||||
buttons, "",
|
||||
@@ -158,22 +148,25 @@ func (m model) publicNetworkView() string {
|
||||
|
||||
// internalNetworkView 内网配置页面
|
||||
func (m model) internalNetworkView() string {
|
||||
title := titleStyle.Render("内网配置")
|
||||
subtitle := subTitleStyle.Render("请配置内网信息")
|
||||
title := titleStyle.Render("Internal Network Configuration")
|
||||
|
||||
networkInterfaces := getNetworkInterfaces()
|
||||
autoDetect := infoStyle.Render(
|
||||
"[*] Auto Detect Network Interfaces: " + strings.Join(networkInterfaces, ", "))
|
||||
|
||||
var inputs strings.Builder
|
||||
for i, ti := range m.textInputs {
|
||||
info := fmt.Sprintf("%-10s|", m.inputLabels[i])
|
||||
info := fmt.Sprintf("%-20s|", m.inputLabels[i])
|
||||
input := inputBox.Render(info + ti.View())
|
||||
inputs.WriteString(input + "\n")
|
||||
}
|
||||
|
||||
buttons := m.renderNavButtons()
|
||||
hint := hintStyle.Render("使用 Up/Down 或 Tab 切换、Enter 确认")
|
||||
hint := hintStyle.Render("Use Up/Down OR Tab Change,Enter Confirm")
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Center,
|
||||
title, "",
|
||||
subtitle, "",
|
||||
autoDetect, "",
|
||||
inputs.String(), "",
|
||||
buttons, "",
|
||||
hint,
|
||||
@@ -182,8 +175,7 @@ func (m model) internalNetworkView() string {
|
||||
|
||||
// dnsView DNS 配置页面
|
||||
func (m model) dnsView() string {
|
||||
title := titleStyle.Render("DNS 配置")
|
||||
subtitle := subTitleStyle.Render("请配置 DNS 服务器")
|
||||
title := titleStyle.Render("DNS Configuration")
|
||||
|
||||
var inputs strings.Builder
|
||||
for i, ti := range m.textInputs {
|
||||
@@ -193,12 +185,10 @@ func (m model) dnsView() string {
|
||||
}
|
||||
|
||||
buttons := m.renderNavButtons()
|
||||
|
||||
hint := hintStyle.Render("使用 Up/Down 或 Tab 切换、Enter 确认")
|
||||
hint := hintStyle.Render("Use Up/Down OR Tab Change,Enter Confirm")
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Center,
|
||||
title, "",
|
||||
subtitle, "",
|
||||
inputs.String(), "",
|
||||
buttons, "",
|
||||
hint,
|
||||
@@ -207,71 +197,71 @@ func (m model) dnsView() string {
|
||||
|
||||
// summaryView 总结页面
|
||||
func (m model) summaryView() string {
|
||||
title := titleStyle.Render("配置总结")
|
||||
subtitle := subTitleStyle.Render("请确认以下配置信息")
|
||||
title := titleStyle.Render("Summary")
|
||||
subtitle := subTitleStyle.Render("Please confirm the following configuration information")
|
||||
|
||||
summary := summaryBox.Render(fmt.Sprintf(`
|
||||
+---------------------------------------------+
|
||||
基本信息
|
||||
+---------------------------------------------+
|
||||
主机名:%-35s
|
||||
国 家: %-31s
|
||||
地 区:%-31s
|
||||
时 区:%-38s
|
||||
主 页:%-38s
|
||||
+---------------------------------------------+
|
||||
数据库
|
||||
+---------------------------------------------+
|
||||
地 址:%-38s
|
||||
名 称:%-38s
|
||||
软 件:%-33s
|
||||
+---------------------------------------------+
|
||||
公网配置
|
||||
+---------------------------------------------+
|
||||
接 口:%-38s
|
||||
地 址: %-41s
|
||||
掩 码:%-38s
|
||||
网 关:%-38s
|
||||
+---------------------------------------------+
|
||||
内网配置
|
||||
+---------------------------------------------+
|
||||
接 口:%-38s
|
||||
地 址: %-41s
|
||||
掩 码:%-38s
|
||||
+---------------------------------------------+
|
||||
DNS
|
||||
+---------------------------------------------+
|
||||
主 DNS: %-37s
|
||||
备 DNS: %-37s
|
||||
+---------------------------------------------+
|
||||
+----------------------------------------------------+
|
||||
Basic Information
|
||||
+----------------------------------------------------+
|
||||
Homepage : %-38s
|
||||
Hostname : %-35s
|
||||
Country : %-31s
|
||||
Region : %-31s
|
||||
Timezone : %-38s
|
||||
Homepage : %-38s
|
||||
+----------------------------------------------------+
|
||||
Database Configuration
|
||||
+----------------------------------------------------+
|
||||
Database Path : %-38s
|
||||
Software : %-33s
|
||||
+----------------------------------------------------+
|
||||
Public Network Configuration
|
||||
+----------------------------------------------------+
|
||||
Public Interface : %-38s
|
||||
Public IP : %-41s
|
||||
Public Netmask : %-38s
|
||||
Public Gateway : %-38s
|
||||
+----------------------------------------------------+
|
||||
Internal Network Configuration
|
||||
+----------------------------------------------------+
|
||||
Internal Interface: %-38s
|
||||
Internal IP : %-41s
|
||||
Internal Netmask : %-38s
|
||||
+----------------------------------------------------+
|
||||
DNS Configuration
|
||||
+----------------------------------------------------+
|
||||
Primary DNS : %-37s
|
||||
Secondary DNS : %-37s
|
||||
+----------------------------------------------------+
|
||||
`,
|
||||
m.config.HomePage,
|
||||
m.config.Hostname,
|
||||
m.config.Country,
|
||||
m.config.Region,
|
||||
m.config.Timezone,
|
||||
m.config.HomePage,
|
||||
m.config.DBAddress,
|
||||
m.config.DBName,
|
||||
m.config.DataAddress,
|
||||
m.config.PublicInterface,
|
||||
m.config.IPAddress,
|
||||
m.config.Netmask,
|
||||
m.config.Gateway,
|
||||
m.config.PublicIPAddress,
|
||||
m.config.PublicNetmask,
|
||||
m.config.PublicGateway,
|
||||
m.config.InternalInterface,
|
||||
m.config.InternalIP,
|
||||
m.config.InternalMask,
|
||||
m.config.InternalIPAddress,
|
||||
m.config.InternalNetmask,
|
||||
m.config.DNSPrimary,
|
||||
m.config.DNSSecondary,
|
||||
))
|
||||
|
||||
var buttons string
|
||||
if m.focusIndex == 0 {
|
||||
buttons = selectedButton.Render("[>] 执行初始化") + " " + normalButton.Render("[ ] 取消")
|
||||
buttons = selectedButton.Render("[>] Start Initialization") + " " + normalButton.Render("[ ] Cancel")
|
||||
} else {
|
||||
buttons = normalButton.Render("[>] 执行初始化") + " " + selectedButton.Render("[ ] 取消")
|
||||
buttons = normalButton.Render("[>] Start Initialization") + " " + selectedButton.Render("[ ] Cancel")
|
||||
}
|
||||
|
||||
hint := hintStyle.Render("使用 <- -> 或 Tab 选择,Enter 确认")
|
||||
hint := hintStyle.Render("Use Up/Down OR Tab Change,Enter Confirm")
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Center,
|
||||
title, "",
|
||||
@@ -297,7 +287,7 @@ func progressView(current PageType, total int) string {
|
||||
progress += " "
|
||||
}
|
||||
}
|
||||
labels := []string{"协议", "数据", "公网", "内网", "DNS", "总结"}
|
||||
labels := []string{"License", "Data", "Network", "Network", "DNS", "Summary"}
|
||||
label := labelStyle.Render(labels[current])
|
||||
return progressStyle.Render(progress) + " " + label
|
||||
}
|
||||
@@ -305,26 +295,26 @@ func progressView(current PageType, total int) string {
|
||||
// successView 成功视图
|
||||
func successView() string {
|
||||
return containerStyle.Render(lipgloss.JoinVertical(lipgloss.Center,
|
||||
successTitle.Render("初始化完成!"), "",
|
||||
successMsg.Render("系统配置已保存,正在初始化..."), "",
|
||||
hintStyle.Render("按任意键退出"),
|
||||
successTitle.Render("Initialization Completed!"), "",
|
||||
successMsg.Render("System configuration has been saved, and the system is initializing..."), "",
|
||||
hintStyle.Render("Press any key to exit"),
|
||||
))
|
||||
}
|
||||
|
||||
// quitView 退出视图
|
||||
func quitView() string {
|
||||
return containerStyle.Render(lipgloss.JoinVertical(lipgloss.Center,
|
||||
errorTitle.Render("已取消"), "",
|
||||
errorMsg.Render("初始化已取消,未保存任何配置"),
|
||||
errorTitle.Render("Canceled"), "",
|
||||
errorMsg.Render("Initialization canceled, no configuration saved"),
|
||||
))
|
||||
}
|
||||
|
||||
// errorView 错误视图
|
||||
func errorView(err error) string {
|
||||
return containerStyle.Render(lipgloss.JoinVertical(lipgloss.Center,
|
||||
errorTitle.Render("错误"), "",
|
||||
errorTitle.Render("Error"), "",
|
||||
errorMsg.Render(err.Error()), "",
|
||||
hintStyle.Render("按 Ctrl+C 退出"),
|
||||
hintStyle.Render("Press Ctrl+C to exit"),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -332,9 +322,9 @@ func errorView(err error) string {
|
||||
func navButtons(m model, prev, next string) string {
|
||||
var btns string
|
||||
if m.currentPage == 0 {
|
||||
btns = normalButton.Render(prev) + " " + selectedButton.Render(next)
|
||||
btns = normalButton.Render(next) + " " + selectedButton.Render(prev)
|
||||
} else {
|
||||
btns = selectedButton.Render(prev) + " " + normalButton.Render(next)
|
||||
btns = selectedButton.Render(next) + " " + normalButton.Render(prev)
|
||||
}
|
||||
return btns
|
||||
}
|
||||
@@ -345,22 +335,22 @@ func (m model) renderNavButtons() string {
|
||||
switch m.focusType {
|
||||
case FocusTypePrev:
|
||||
// 焦点在"上一步"
|
||||
prevBtn = selectedButton.Render("<< 上一步 >>")
|
||||
nextBtn = normalButton.Render("下一步 >>")
|
||||
nextBtn = normalButton.Render(" Next ")
|
||||
prevBtn = selectedButton.Render(" << Prev >>")
|
||||
case FocusTypeNext:
|
||||
// 焦点在"下一步"
|
||||
prevBtn = normalButton.Render("<< 上一步")
|
||||
nextBtn = selectedButton.Render("<< 下一步 >>")
|
||||
nextBtn = selectedButton.Render(" << Next >>")
|
||||
prevBtn = normalButton.Render(" Prev ")
|
||||
default:
|
||||
// 焦点在输入框
|
||||
prevBtn = normalButton.Render("<< 上一步")
|
||||
nextBtn = normalButton.Render("下一步 >>")
|
||||
nextBtn = normalButton.Render(" Next ")
|
||||
prevBtn = normalButton.Render(" Prev ")
|
||||
}
|
||||
|
||||
return lipgloss.JoinHorizontal(
|
||||
lipgloss.Center,
|
||||
prevBtn,
|
||||
" ",
|
||||
nextBtn,
|
||||
" ",
|
||||
prevBtn,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user