feat: 实现模块4 - TUI状态栏和主题配色
This commit is contained in:
@@ -13,12 +13,15 @@ type model struct {
|
||||
translator *translator.Translator
|
||||
textInput textinput.Model
|
||||
result string
|
||||
targetLang string
|
||||
}
|
||||
|
||||
var (
|
||||
headerStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#00D9FF")).
|
||||
Bold(true)
|
||||
dividerStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#00D9FF"))
|
||||
inputStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#FAFAFA")).
|
||||
Background(lipgloss.Color("#1A1A2E"))
|
||||
@@ -27,9 +30,21 @@ var (
|
||||
Background(lipgloss.Color("#0D1B2A"))
|
||||
helpStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#888888"))
|
||||
statusBarStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#FFFFFF")).
|
||||
Background(lipgloss.Color("#1F2937")).
|
||||
Width(60)
|
||||
langStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#FBBF24")).
|
||||
Bold(true)
|
||||
)
|
||||
|
||||
func NewApp(cfg *config.Config, t *translator.Translator) *tea.Program {
|
||||
targetLang := "zh-CN"
|
||||
if cfg != nil && cfg.DefaultTargetLang != "" {
|
||||
targetLang = cfg.DefaultTargetLang
|
||||
}
|
||||
|
||||
ti := textinput.New()
|
||||
ti.Placeholder = "输入要翻译的文本..."
|
||||
ti.Focus()
|
||||
@@ -40,6 +55,7 @@ func NewApp(cfg *config.Config, t *translator.Translator) *tea.Program {
|
||||
config: cfg,
|
||||
translator: t,
|
||||
textInput: ti,
|
||||
targetLang: targetLang,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -66,14 +82,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
func (m model) View() string {
|
||||
resultBox := m.renderResult()
|
||||
helpText := helpStyle.Render("\n 按 Ctrl+C 退出 | Enter 翻译")
|
||||
helpText := helpStyle.Render("\n Ctrl+C 退出 · Enter 翻译")
|
||||
|
||||
return "\n" +
|
||||
" " + headerStyle.Render("YOYO翻译") + "\n" +
|
||||
" " + lipgloss.NewStyle().Foreground(lipgloss.Color("#00D9FF")).Render("─────────────────────") + "\n\n" +
|
||||
" " + dividerStyle.Render("─────────────────────") + "\n\n" +
|
||||
" " + m.textInput.View() + "\n\n" +
|
||||
resultBox +
|
||||
helpText
|
||||
helpText +
|
||||
"\n" +
|
||||
m.renderStatusBar()
|
||||
}
|
||||
|
||||
func (m model) renderResult() string {
|
||||
@@ -82,3 +100,11 @@ func (m model) renderResult() string {
|
||||
}
|
||||
return " " + resultStyle.Render(m.result) + "\n"
|
||||
}
|
||||
|
||||
func (m model) renderStatusBar() string {
|
||||
divider := dividerStyle.Render("─")
|
||||
langInfo := langStyle.Render("目标: " + m.targetLang)
|
||||
|
||||
return "\n " + divider + "\n" +
|
||||
" " + statusBarStyle.Render(" "+langInfo+" ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user