(msg tea.KeyMsg)
| 161 | } |
| 162 | |
| 163 | func (f FirstTimeSetup) handlePRDNameKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) { |
| 164 | switch msg.String() { |
| 165 | case "ctrl+c": |
| 166 | f.result.Cancelled = true |
| 167 | return f, tea.Quit |
| 168 | |
| 169 | case "esc": |
| 170 | if f.showGitignore { |
| 171 | // Go back to gitignore step |
| 172 | f.step = StepGitignore |
| 173 | f.prdNameError = "" |
| 174 | return f, nil |
| 175 | } |
| 176 | f.result.Cancelled = true |
| 177 | return f, tea.Quit |
| 178 | |
| 179 | case "enter": |
| 180 | // Validate PRD name |
| 181 | name := strings.TrimSpace(f.prdName) |
| 182 | if name == "" { |
| 183 | f.prdNameError = "Name cannot be empty" |
| 184 | return f, nil |
| 185 | } |
| 186 | if !isValidPRDName(name) { |
| 187 | f.prdNameError = "Name can only contain letters, numbers, hyphens, and underscores" |
| 188 | return f, nil |
| 189 | } |
| 190 | f.result.PRDName = name |
| 191 | f.step = StepPostCompletion |
| 192 | return f, nil |
| 193 | |
| 194 | case "backspace": |
| 195 | if len(f.prdName) > 0 { |
| 196 | f.prdName = f.prdName[:len(f.prdName)-1] |
| 197 | f.prdNameError = "" |
| 198 | } |
| 199 | return f, nil |
| 200 | |
| 201 | default: |
| 202 | // Handle character input |
| 203 | if len(msg.String()) == 1 { |
| 204 | r := rune(msg.String()[0]) |
| 205 | // Only allow valid characters |
| 206 | if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || |
| 207 | (r >= '0' && r <= '9') || r == '-' || r == '_' { |
| 208 | f.prdName += string(r) |
| 209 | f.prdNameError = "" |
| 210 | } |
| 211 | } |
| 212 | return f, nil |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // isValidPRDName checks if a name is valid for a PRD. |
| 217 | func isValidPRDName(name string) bool { |
no test coverage detected