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 {
3030 scrollOffset int
3131 addNewOption bool
3232 isHomeMenu bool // If true, ESC quits; if false, ESC goes back
33 preserveOrder bool // skip alphabetical sort (action menus with a fixed priority)
3334}
3435
3536type optionsRefreshedMsg struct {
@@ -347,12 +348,14 @@ func (m *Model) filterOptions() {
347348 }
348349 }
349350
350 // Sort the filtered options alphabetically unless this is a menu selection
351 isMenu := false
352 for _, opt := range m.allOptions {
353 if opt.Key == "ALL" || opt.Key == "CURRENT" {
354 isMenu = true
355 break
351 // Sort alphabetically unless this is a home menu or an ordered action list.
352 isMenu := m.preserveOrder
353 if !isMenu {
354 for _, opt := range m.allOptions {
355 if opt.Key == "ALL" || opt.Key == "CURRENT" {
356 isMenu = true
357 break
358 }
356359 }
357360 }
358361
@@ -745,21 +748,27 @@ func rofiSelectInternal(options []SelectionOption, isHomeMenu bool, refreshConfi
745748}
746749
747750func DynamicSelectFromSlice(options []SelectionOption) (SelectionOption, error) {
748 return dynamicSelectInternal(options, nil)
751 return dynamicSelectInternal(options, nil, false)
749752}
750753
751754// DynamicSelect displays a simple selection prompt without extra features
752755func 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)
754763}
755764
756765var promptSelect = DynamicSelect
757766
758767func DynamicSelectWithRefresh(options []SelectionOption, refreshConfig *SelectionRefreshConfig) (SelectionOption, error) {
759 return dynamicSelectInternal(options, refreshConfig)
768 return dynamicSelectInternal(options, refreshConfig, false)
760769}
761770
762func dynamicSelectInternal(options []SelectionOption, refreshConfig *SelectionRefreshConfig) (SelectionOption, error) {
771func dynamicSelectInternal(options []SelectionOption, refreshConfig *SelectionRefreshConfig, preserveOrder bool) (SelectionOption, error) {
763772 isHomeMenu := detectHomeMenu(options)
764773
765774 if isHomeMenu {
@@ -783,9 +792,10 @@ func dynamicSelectInternal(options []SelectionOption, refreshConfig *SelectionRe
783792 }
784793
785794 model := &Model{
786 allOptions: cleanOptions,
787 isHomeMenu: isHomeMenu,
788 addNewOption: hasAddNew,
795 allOptions: cleanOptions,
796 isHomeMenu: isHomeMenu,
797 addNewOption: hasAddNew,
798 preserveOrder: preserveOrder,
789799 }
790800 model.filterOptions()
791801
internal/update.go +57 −9
@@ -286,15 +286,52 @@ func buildUpdatePromptMessage(currentVersion string, state updatePendingState) (
286286 fmt.Fprintf(&b, "%s\n", state.HTMLURL)
287287 }
288288 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)
290294 message = strings.TrimSpace(b.String())
291295 // Rofi -mesg stays readable; keep a hard cap.
292296 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)"
294298 }
295299 return prompt, message
296300}
297301
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
298335// updateUserMessage prints a single status line. With Rofi mode, CurdOut becomes
299336// notify-send — so we only send one short notification (or log) for status.
300337func updateUserMessage(config *CurdConfig, msg string) {
@@ -324,13 +361,24 @@ func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool {
324361 return false
325362 }
326363
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.
328376 options := []SelectionOption{
329 {Key: "update", Label: "1. Update now"},
330 {Key: "later", Label: "2. Remind me later"},
331 {Key: "skip", Label: "3. Skip this version"},
332 {Key: "disable", Label: "4. Turn off automatic update checks"},
333 {Key: "continue", Label: "5. Continue without updating"},
377 {Key: "update", Label: "Update now"},
378 {Key: "later", Label: "Remind me later"},
379 {Key: "skip", Label: "Skip this version"},
380 {Key: "disable", Label: "Turn off automatic update checks"},
381 {Key: "continue", Label: "Continue without updating"},
334382 }
335383 prompt, message := buildUpdatePromptMessage(currentVersion, state)
336384
@@ -343,7 +391,7 @@ func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool {
343391 fmt.Println(prompt)
344392 fmt.Println(message)
345393 fmt.Println()
346 selected, err = promptSelect(options)
394 selected, err = DynamicSelectPreserveOrder(options)
347395 }
348396 if err != nil || selected.Key == "-1" || selected.Key == "-2" || selected.Key == "continue" || selected.Key == "" {
349397 return false