Commit f7b6e56773

f7b6e56773f3311bde9720321189611a03e23040

parent: c81d45e2c8

Unsigned

Wraient <wraient.911@gmail.com> · 2026-07-22 20:43 UTC

Show real GitHub release markdown; drop numbered update options

Refresh release notes from the GitHub API when showing the update prompt,
remove 1/2/3 prefixes, and preserve option order so Update now stays first.

Layout: unified · split

internal/selection_menu.go +23 −13
@@ -30,6 +30,7 @@ type Model struct {
30 scrollOffset int 30 scrollOffset int
31 addNewOption bool 31 addNewOption bool
32 isHomeMenu bool // If true, ESC quits; if false, ESC goes back 32 isHomeMenu bool // If true, ESC quits; if false, ESC goes back
33 preserveOrder bool // skip alphabetical sort (action menus with a fixed priority)
33} 34}
34 35
35type optionsRefreshedMsg struct { 36type optionsRefreshedMsg struct {
@@ -347,12 +348,14 @@ func (m *Model) filterOptions() {
347 } 348 }
348 } 349 }
349 350
350 // Sort the filtered options alphabetically unless this is a menu selection 351 // Sort alphabetically unless this is a home menu or an ordered action list.
351 isMenu := false 352 isMenu := m.preserveOrder
352 for _, opt := range m.allOptions { 353 if !isMenu {
353 if opt.Key == "ALL" || opt.Key == "CURRENT" { 354 for _, opt := range m.allOptions {
354 isMenu = true 355 if opt.Key == "ALL" || opt.Key == "CURRENT" {
355 break 356 isMenu = true
357 break
358 }
356 } 359 }
357 } 360 }
358 361
@@ -745,21 +748,27 @@ func rofiSelectInternal(options []SelectionOption, isHomeMenu bool, refreshConfi
745} 748}
746 749
747func DynamicSelectFromSlice(options []SelectionOption) (SelectionOption, error) { 750func DynamicSelectFromSlice(options []SelectionOption) (SelectionOption, error) {
748 return dynamicSelectInternal(options, nil) 751 return dynamicSelectInternal(options, nil, false)
749} 752}
750 753
751// DynamicSelect displays a simple selection prompt without extra features 754// DynamicSelect displays a simple selection prompt without extra features
752func DynamicSelect(options []SelectionOption) (SelectionOption, error) { 755func DynamicSelect(options []SelectionOption) (SelectionOption, error) {
753 return dynamicSelectInternal(options, nil) 756 return dynamicSelectInternal(options, nil, false)
757}
758
759// DynamicSelectPreserveOrder is like DynamicSelect but keeps the caller's option order
760// (no alphabetical sort). Use for action menus where the first item is the primary action.
761func DynamicSelectPreserveOrder(options []SelectionOption) (SelectionOption, error) {
762 return dynamicSelectInternal(options, nil, true)
754} 763}
755 764
756var promptSelect = DynamicSelect 765var promptSelect = DynamicSelect
757 766
758func DynamicSelectWithRefresh(options []SelectionOption, refreshConfig *SelectionRefreshConfig) (SelectionOption, error) { 767func DynamicSelectWithRefresh(options []SelectionOption, refreshConfig *SelectionRefreshConfig) (SelectionOption, error) {
759 return dynamicSelectInternal(options, refreshConfig) 768 return dynamicSelectInternal(options, refreshConfig, false)
760} 769}
761 770
762func dynamicSelectInternal(options []SelectionOption, refreshConfig *SelectionRefreshConfig) (SelectionOption, error) { 771func dynamicSelectInternal(options []SelectionOption, refreshConfig *SelectionRefreshConfig, preserveOrder bool) (SelectionOption, error) {
763 isHomeMenu := detectHomeMenu(options) 772 isHomeMenu := detectHomeMenu(options)
764 773
765 if isHomeMenu { 774 if isHomeMenu {
@@ -783,9 +792,10 @@ func dynamicSelectInternal(options []SelectionOption, refreshConfig *SelectionRe
783 } 792 }
784 793
785 model := &Model{ 794 model := &Model{
786 allOptions: cleanOptions, 795 allOptions: cleanOptions,
787 isHomeMenu: isHomeMenu, 796 isHomeMenu: isHomeMenu,
788 addNewOption: hasAddNew, 797 addNewOption: hasAddNew,
798 preserveOrder: preserveOrder,
789 } 799 }
790 model.filterOptions() 800 model.filterOptions()
791 801
internal/update.go +57 −9
@@ -286,15 +286,52 @@ func buildUpdatePromptMessage(currentVersion string, state updatePendingState) (
286 fmt.Fprintf(&b, "%s\n", state.HTMLURL) 286 fmt.Fprintf(&b, "%s\n", state.HTMLURL)
287 } 287 }
288 b.WriteString("\n") 288 b.WriteString("\n")
289 b.WriteString(state.ReleaseNotes) 289 notes := strings.TrimSpace(state.ReleaseNotes)
290 if notes == "" {
291 notes = "(No release notes on GitHub for this release.)"
292 }
293 b.WriteString(notes)
290 message = strings.TrimSpace(b.String()) 294 message = strings.TrimSpace(b.String())
291 // Rofi -mesg stays readable; keep a hard cap. 295 // Rofi -mesg stays readable; keep a hard cap.
292 if runes := []rune(message); len(runes) > maxReleaseNotesRunes { 296 if runes := []rune(message); len(runes) > maxReleaseNotesRunes {
293 message = string(runes[:maxReleaseNotesRunes]) + "\n… (truncated)" 297 message = string(runes[:maxReleaseNotesRunes]) + "\n… (truncated — full notes on GitHub)"
294 } 298 }
295 return prompt, message 299 return prompt, message
296} 300}
297 301
302// refreshUpdateStateFromGitHub reloads tag/name/body/url from the live release API
303// so the prompt shows real markdown notes instead of a stale/test seed.
304func refreshUpdateStateFromGitHub(state *updatePendingState) {
305 if state == nil {
306 return
307 }
308 release, err := fetchLatestGitHubRelease(defaultUpdateRepo)
309 if err != nil {
310 Log(fmt.Sprintf("Could not refresh release notes from GitHub: %v", err))
311 return
312 }
313 latest := normalizeReleaseVersion(release.TagName)
314 if latest == "" {
315 return
316 }
317 // If GitHub moved past what we flagged, still show the newest release.
318 state.LatestTag = release.TagName
319 state.LatestVersion = latest
320 state.ReleaseName = strings.TrimSpace(release.Name)
321 if state.ReleaseName == "" {
322 state.ReleaseName = "Curd " + latest
323 }
324 // Full markdown body from the GitHub release page (API `body` field).
325 // Do not seed/test stubs here — always prefer live API content when online.
326 state.ReleaseNotes = strings.TrimSpace(release.Body)
327 state.HTMLURL = release.HTMLURL
328 state.CheckedAt = time.Now().UTC().Format(time.RFC3339)
329 if asset, assetErr := curdReleaseBinaryName(); assetErr == nil {
330 state.AssetName = asset
331 }
332 state.Available = true
333}
334
298// updateUserMessage prints a single status line. With Rofi mode, CurdOut becomes 335// updateUserMessage prints a single status line. With Rofi mode, CurdOut becomes
299// notify-send — so we only send one short notification (or log) for status. 336// notify-send — so we only send one short notification (or log) for status.
300func updateUserMessage(config *CurdConfig, msg string) { 337func updateUserMessage(config *CurdConfig, msg string) {
@@ -324,13 +361,24 @@ func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool {
324 return false 361 return false
325 } 362 }
326 363
327 // Numbered labels keep priority order under DynamicSelect's alphabetical sort. 364 // Pull live release markdown from GitHub so notes match the release page.
365 refreshUpdateStateFromGitHub(&state)
366 if !pendingUpdateShouldPrompt(config, currentVersion, state) {
367 // e.g. already up to date after refresh
368 state.Available = false
369 _ = saveUpdatePendingState(config.StoragePath, state)
370 return false
371 }
372 _ = saveUpdatePendingState(config.StoragePath, state)
373
374 // Fixed order (Update now first). No index prefixes — Rofi keeps order;
375 // CLI uses DynamicSelectPreserveOrder so labels aren't alpha-sorted.
328 options := []SelectionOption{ 376 options := []SelectionOption{
329 {Key: "update", Label: "1. Update now"}, 377 {Key: "update", Label: "Update now"},
330 {Key: "later", Label: "2. Remind me later"}, 378 {Key: "later", Label: "Remind me later"},
331 {Key: "skip", Label: "3. Skip this version"}, 379 {Key: "skip", Label: "Skip this version"},
332 {Key: "disable", Label: "4. Turn off automatic update checks"}, 380 {Key: "disable", Label: "Turn off automatic update checks"},
333 {Key: "continue", Label: "5. Continue without updating"}, 381 {Key: "continue", Label: "Continue without updating"},
334 } 382 }
335 prompt, message := buildUpdatePromptMessage(currentVersion, state) 383 prompt, message := buildUpdatePromptMessage(currentVersion, state)
336 384
@@ -343,7 +391,7 @@ func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool {
343 fmt.Println(prompt) 391 fmt.Println(prompt)
344 fmt.Println(message) 392 fmt.Println(message)
345 fmt.Println() 393 fmt.Println()
346 selected, err = promptSelect(options) 394 selected, err = DynamicSelectPreserveOrder(options)
347 } 395 }
348 if err != nil || selected.Key == "-1" || selected.Key == "-2" || selected.Key == "continue" || selected.Key == "" { 396 if err != nil || selected.Key == "-1" || selected.Key == "-2" || selected.Key == "continue" || selected.Key == "" {
349 return false 397 return false