Files
superwork/tui/internal/tui/create.go
T
2026-06-23 05:02:15 +08:00

89 lines
2.4 KiB
Go

package tui
import (
"fmt"
"strings"
"charm.land/lipgloss/v2"
"superwork-tui/internal/cc"
)
// createModalWidth returns the outer width of the new-issue modal for a given
// terminal width.
func createModalWidth(termWidth int) int {
width := 84
if termWidth > 0 && termWidth-8 < width {
width = termWidth - 8
}
if width < 40 {
width = 40
}
return width
}
// defaultProfileIdx picks the initially-selected profile, preferring the VSCode
// default name "offical", else the first profile, else -1 (默认/none).
func defaultProfileIdx(profiles []cc.ClaudeProfile) int {
for i, p := range profiles {
if p.Name == "offical" {
return i
}
}
if len(profiles) > 0 {
return 0
}
return -1
}
func profileRadios(profiles []cc.ClaudeProfile, sel int) string {
mark := func(on bool) string {
if on {
return "◉"
}
return "○"
}
parts := make([]string, 0, len(profiles)+1)
for i, p := range profiles {
parts = append(parts, mark(i == sel)+" "+p.Name)
}
parts = append(parts, mark(sel < 0)+" (默认)")
return strings.Join(parts, " ")
}
// createView renders the new-issue modal (title + multi-line request textarea +
// optional profile radios) centered over the board, matching the VSCode dialog.
func (m Model) createView() string {
bg := m.boardView()
width := createModalWidth(m.width)
innerW := width - 2
hint := lipgloss.NewStyle().Faint(true)
block := func(s string) string {
return lipgloss.NewStyle().Width(innerW).PaddingLeft(1).Render(s)
}
var parts []string
parts = append(parts, block(lipgloss.NewStyle().Bold(true).Foreground(detailBorderColor).Render("新建工单")))
parts = append(parts, block(""))
parts = append(parts, block(m.createArea.View()))
if len(m.createImages) > 0 {
parts = append(parts, block(hint.Render(fmt.Sprintf("已粘贴 %d 张图片", len(m.createImages)))))
}
if len(m.profilePickerProfiles) > 0 {
parts = append(parts, block(""))
parts = append(parts, block(hint.Render("配置文件 (Tab 切换):")))
parts = append(parts, block(profileRadios(m.profilePickerProfiles, m.createProfileIdx)))
}
parts = append(parts, block(""))
parts = append(parts, block(hint.Render("Ctrl+S 确认 Ctrl+V 粘贴图片 Esc 取消")))
box := lipgloss.NewStyle().
Border(lipgloss.RoundedBorder()).
BorderForeground(detailBorderColor).
Width(width).
Render(lipgloss.JoinVertical(lipgloss.Left, parts...))
return placeOverlayCenter(bg, box)
}