优化: 资源消耗优化,发布 v0.2.1
This commit is contained in:
@@ -28,7 +28,7 @@ func (m *Model) render() string {
|
||||
|
||||
b.WriteString(m.renderTabBar())
|
||||
b.WriteString("\n")
|
||||
b.WriteString(lipgloss.NewStyle().Foreground(style.BgPanel).Render(strings.Repeat("─", m.width)))
|
||||
b.WriteString(style.SepFg.Render(sepRunes(m.width)))
|
||||
b.WriteString("\n")
|
||||
|
||||
if m.IsHistoryTab() {
|
||||
@@ -46,27 +46,27 @@ func (m *Model) render() string {
|
||||
b.WriteString(style.InputStyle.Render(fmt.Sprintf(" ⎇ fork:%s [Enter]confirm [Esc]cancel", m.forkBuf)))
|
||||
}
|
||||
if m.launched != "" {
|
||||
b.WriteString(lipgloss.NewStyle().Foreground(style.Accent).Render(fmt.Sprintf(" ✓ %s", m.launched)))
|
||||
b.WriteString(style.AccentFg.Render(fmt.Sprintf(" ✓ %s", m.launched)))
|
||||
m.launched = ""
|
||||
}
|
||||
if m.update.Done {
|
||||
b.WriteString(lipgloss.NewStyle().Foreground(style.Success).Bold(true).
|
||||
b.WriteString(style.SuccessBoldFg.
|
||||
Render(fmt.Sprintf(" updated to v%s, restart to apply", m.update.NewVersion)))
|
||||
} else if m.update.Error != nil {
|
||||
b.WriteString(lipgloss.NewStyle().Foreground(style.Red).
|
||||
b.WriteString(style.RedFg.
|
||||
Render(fmt.Sprintf(" update failed: %v", m.update.Error)))
|
||||
} else if m.update.Updating {
|
||||
b.WriteString(lipgloss.NewStyle().Foreground(style.Warning).
|
||||
b.WriteString(style.WarningFg.
|
||||
Render(" updating..."))
|
||||
} else if m.update.Available {
|
||||
b.WriteString(lipgloss.NewStyle().Foreground(style.Warning).Bold(true).
|
||||
b.WriteString(style.WarningBoldFg.
|
||||
Render(fmt.Sprintf(" v%s available [u]update", m.update.NewVersion)))
|
||||
}
|
||||
b.WriteString("\n")
|
||||
|
||||
helpParts := m.renderHelp()
|
||||
helpStr := " " + strings.Join(helpParts, " ")
|
||||
verStr := lipgloss.NewStyle().Foreground(style.Dim).Render("绝尘 v" + Version)
|
||||
verStr := style.DimFg.Render("绝尘 v" + Version)
|
||||
padW := m.width - lipgloss.Width(helpStr) - lipgloss.Width(verStr)
|
||||
if padW > 0 {
|
||||
b.WriteString(helpStr + strings.Repeat(" ", padW) + verStr)
|
||||
@@ -88,9 +88,7 @@ func (m *Model) renderTabBar() string {
|
||||
|
||||
wsLabel := " 1 工作空间 "
|
||||
if !m.IsHistoryTab() {
|
||||
b.WriteString(lipgloss.NewStyle().
|
||||
Bold(true).Background(style.BgPanel).Foreground(style.Accent).
|
||||
Render(wsLabel))
|
||||
b.WriteString(style.TabActiveAccent.Render(wsLabel))
|
||||
} else {
|
||||
b.WriteString(style.TabInactiveStyle.Render(wsLabel))
|
||||
}
|
||||
@@ -98,9 +96,7 @@ func (m *Model) renderTabBar() string {
|
||||
b.WriteString(sep)
|
||||
histLabel := " 2 历史对话 "
|
||||
if m.IsHistoryTab() {
|
||||
b.WriteString(lipgloss.NewStyle().
|
||||
Bold(true).Background(style.BgPanel).Foreground(style.Cyan).
|
||||
Render(histLabel))
|
||||
b.WriteString(style.TabActiveCyan.Render(histLabel))
|
||||
} else {
|
||||
b.WriteString(style.TabInactiveStyle.Render(histLabel))
|
||||
}
|
||||
@@ -132,12 +128,12 @@ func (m *Model) renderHelp() []string {
|
||||
}
|
||||
|
||||
func (m *Model) fmtHelp(key, desc string) string {
|
||||
return lipgloss.NewStyle().Foreground(style.Accent).Render(key) +
|
||||
lipgloss.NewStyle().Foreground(style.Dim).Render(":" + desc)
|
||||
return style.AccentFg.Render(key) +
|
||||
style.DimFg.Render(":" + desc)
|
||||
}
|
||||
|
||||
func renderNavEntry(lines *[]string, w int, label string, activeFg string, isCur, focused bool) {
|
||||
sep := lipgloss.NewStyle().Foreground(style.BgPanel).Render(fitWidth(" ─────────", w))
|
||||
sep := style.SepFg.Render(fitWidth(" ─────────", w))
|
||||
*lines = append(*lines, sep)
|
||||
if isCur {
|
||||
curLabel := " → " + label
|
||||
@@ -150,6 +146,6 @@ func renderNavEntry(lines *[]string, w int, label string, activeFg string, isCur
|
||||
} else {
|
||||
inactiveLabel := " " + label
|
||||
line := padRightByWidth(truncateByWidth(inactiveLabel, w), w)
|
||||
*lines = append(*lines, lipgloss.NewStyle().Foreground(style.Dim).Render(line))
|
||||
*lines = append(*lines, style.DimFg.Render(line))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user