Commit b859cc34cf

b859cc34cf0321c9f6e731dbe5b56aa76bf6004b

parent: 8591e980de

Unregistered key

tr1x_em <admin@trix.is-a.dev> · 2026-08-06 08:38 UTC
committer: <noreply@github.com>

feat(curd): Added ShowNewEpisode (#115)

* feat(curd): Added ShowNewEpisode

Signed-off-by: tr1xem <admin@trix.is-a.dev>

* fix(curd): Different naming conventions in different rofi mode

Signed-off-by: tr1xem <admin@trix.is-a.dev>

---------

Signed-off-by: tr1xem <admin@trix.is-a.dev>

Layout: unified · split

cmd/curd/main.go +1
@@ -79,6 +79,7 @@ func main() {
7979 flag.StringVar(&userCurdConfig.DiscordClientId, "discord-client-id", userCurdConfig.DiscordClientId, "Discord client ID for Rich Presence")
8080 flag.BoolVar(&userCurdConfig.VimKeys, "vim-keys", userCurdConfig.VimKeys, "Enable vim motions in selection menus (j/k/h/l, / search) (true/false)")
8181 flag.BoolVar(&userCurdConfig.CheckUpdates, "check-updates", userCurdConfig.CheckUpdates, "Check for curd updates in the background when idle (true/false)")
82 flag.BoolVar(&userCurdConfig.ShowNewEpisodes, "show-new-episodes", userCurdConfig.ShowNewEpisodes, "Show new episode indicators in currently watching list (true/false)")
8283 continueLast := flag.Bool("c", false, "Continue last episode")
8384 addNewAnime := flag.Bool("new", false, "Add new anime")
8485 rofiSelection := flag.Bool("rofi", false, "Open selection in rofi")
internal/anilist.go +15
@@ -534,6 +534,10 @@ func GetUserData(token string, userID int) (map[string]interface{}, error) {
534534 native
535535 }
536536 status
537 nextAiringEpisode {
538 episode
539 timeUntilAiring
540 }
537541 }
538542 status
539543 score
@@ -597,6 +601,10 @@ func GetUserDataPreview(token string, userID int) (map[string]interface{}, error
597601 native
598602 }
599603 status
604 nextAiringEpisode {
605 episode
606 timeUntilAiring
607 }
600608 }
601609 status
602610 score
@@ -1171,6 +1179,13 @@ func ParseAnimeList(input map[string]interface{}) AnimeList {
11711179 animeEntry.CoverImage = safeString(coverImage["large"])
11721180 }
11731181
1182 if nextEp, ok := media["nextAiringEpisode"].(map[string]interface{}); ok && nextEp != nil {
1183 animeEntry.Media.NextAiringEpisode = &NextAiringEpisodeInfo{
1184 Episode: toInt(nextEp["episode"]),
1185 TimeUntilAiring: toInt(nextEp["timeUntilAiring"]),
1186 }
1187 }
1188
11741189 // Defense in depth: never insert the same media twice even if AniList
11751190 // returns the entry under multiple non-custom lists.
11761191 if animeEntry.Media.ID != 0 {
internal/anilist_cache.go +18 −4
@@ -269,9 +269,16 @@ func buildCategorySelectionOptions(list AnimeList, category string) []SelectionO
269269 for _, entry := range getEntriesByCategory(list, category) {
270270 title := mediaDisplayTitle(entry.Media, userCurdConfig)
271271
272 hasNew := false
273 if userCurdConfig.ShowNewEpisodes && entry.Media.NextAiringEpisode != nil {
274 nextWatched := nextEpisodeFromProgress(entry.Progress)
275 hasNew = entry.Media.NextAiringEpisode.Episode > nextWatched
276 }
277
272278 options = append(options, SelectionOption{
273 Key: strconv.Itoa(entry.Media.ID),
274 Label: title,
279 Key: strconv.Itoa(entry.Media.ID),
280 Label: title,
281 HasNewEpisodes: hasNew,
275282 })
276283 }
277284
@@ -285,9 +292,16 @@ func buildCategoryPreviewOptions(list AnimeList, category string) map[string]Rof
285292 for _, entry := range getEntriesByCategory(list, category) {
286293 title := mediaDisplayTitle(entry.Media, userCurdConfig)
287294
295 hasNew := false
296 if userCurdConfig.ShowNewEpisodes && entry.Media.NextAiringEpisode != nil {
297 nextWatched := nextEpisodeFromProgress(entry.Progress)
298 hasNew = entry.Media.NextAiringEpisode.Episode > nextWatched
299 }
300
288301 options[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{
289 Title: title,
290 CoverImage: entry.CoverImage,
302 Title: title,
303 CoverImage: entry.CoverImage,
304 HasNewEpisodes: hasNew,
291305 }
292306 }
293307
internal/config.go +2
@@ -76,6 +76,7 @@ type CurdConfig struct {
7676 MyAnimeListClientSecret string `config:"MyAnimeListClientSecret"`
7777 MyAnimeListImported bool `config:"MyAnimeListImported"`
7878 MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"`
79 ShowNewEpisodes bool `config:"ShowNewEpisodes"`
7980}
8081
8182const (
@@ -137,6 +138,7 @@ func defaultConfigMap() map[string]string {
137138 "MyAnimeListClientSecret": "",
138139 "MyAnimeListImported": "false",
139140 "MyAnimeListImportDismissed": "false",
141 "ShowNewEpisodes": "true",
140142 }
141143}
142144
internal/selection_menu.go +50 −14
@@ -78,6 +78,11 @@ var (
7878
7979 quitHintStyle = lipgloss.NewStyle().
8080 Foreground(lipgloss.Color("#FFD700")) // Gold
81
82 newEpisodeItemStyle = lipgloss.NewStyle().
83 Foreground(lipgloss.Color("#4CAF50")) // Green
84
85 rofiNewEpisodeColor = "#4CAF50"
8186)
8287
8388// Init initializes the model
@@ -318,10 +323,18 @@ func (m Model) View() string {
318323
319324 // Render the options within the visible range
320325 for i := start; i < end; i++ {
326 label := m.filteredKeys[i].Label
327
321328 if i == m.selected {
322 b.WriteString(selectedItemStyle.Render(m.filteredKeys[i].Label) + "\n")
329 if m.filteredKeys[i].HasNewEpisodes {
330 b.WriteString(newEpisodeItemStyle.Render(" [NEW]") + selectedItemStyle.Render(label) + "\n")
331 } else {
332 b.WriteString(selectedItemStyle.Render(label) + "\n")
333 }
334 } else if m.filteredKeys[i].HasNewEpisodes {
335 b.WriteString(newEpisodeItemStyle.Render(" [NEW]") + regularItemStyle.Render(label) + "\n")
323336 } else {
324 b.WriteString(regularItemStyle.Render(m.filteredKeys[i].Label) + "\n")
337 b.WriteString(regularItemStyle.Render(label) + "\n")
325338 }
326339 }
327340 }
@@ -339,11 +352,19 @@ func (m Model) visibleItemsCount() int {
339352 return count
340353}
341354
355func displayLabel(opt SelectionOption) string {
356 if opt.HasNewEpisodes {
357 return "[NEW]" + opt.Label
358 }
359 return opt.Label
360}
361
342362// filterOptions filters and sorts options based on the search term
343363func (m *Model) filterOptions() {
344364 m.filteredKeys = nil
345365 for _, opt := range m.allOptions {
346 if strings.Contains(strings.ToLower(opt.Label), strings.ToLower(m.filter)) {
366 // Small function to also consider new episode from list
367 if strings.Contains(strings.ToLower(displayLabel(opt)), strings.ToLower(m.filter)) {
347368 m.filteredKeys = append(m.filteredKeys, opt)
348369 }
349370 }
@@ -498,8 +519,9 @@ func previewOptionsToSortedSelection(options map[string]RofiSelectPreview) []Sel
498519 selectionOptions := make([]SelectionOption, 0, len(options))
499520 for id, opt := range options {
500521 selectionOptions = append(selectionOptions, SelectionOption{
501 Label: opt.Title,
502 Key: id,
522 Label: opt.Title,
523 Key: id,
524 HasNewEpisodes: opt.HasNewEpisodes,
503525 })
504526 }
505527
@@ -531,18 +553,22 @@ func DynamicSelectPreviewWithRefresh(options map[string]RofiSelectPreview, addne
531553 Log(fmt.Sprintf("Error caching image: %v", err))
532554 continue
533555 }
534 rofiInput.WriteString(fmt.Sprintf("%s\x00icon\x1f%s\n", opt.Label, cachePath))
556 label := opt.Label
557 if opt.HasNewEpisodes {
558 label = fmt.Sprintf("<span foreground=\"%s\">[NEW]</span> %s ", rofiNewEpisodeColor, opt.Label)
559 }
560 rofiInput.WriteString(fmt.Sprintf("%s\x00icon\x1f%s\n", label, cachePath))
535561 }
536562
537563 if addnewoption {
538
539564 rofiInput.WriteString("Add new anime\n")
540565 }
541566 rofiInput.WriteString("Back\n")
542567 rofiInput.WriteString("Quit\n")
543568
544569 configPath := filepath.Join(GetStoragePath(), "selectanimepreview.rasi")
545 cmd := exec.Command("rofi", "-dmenu", "-theme", configPath, "-show-icons", "-p", "Select Anime", "-i", "-no-custom")
570 // NOTE: Need `-markup-rows` to enable pango
571 cmd := exec.Command("rofi", "-dmenu", "-theme", configPath, "-show-icons", "-markup-rows", "-p", "Select Anime", "-i", "-no-custom")
546572 cmd.Stdin = strings.NewReader(rofiInput.String())
547573 var stdout, stderr bytes.Buffer
548574 cmd.Stdout = &stdout
@@ -613,6 +639,9 @@ func preDownloadImages(options map[string]RofiSelectPreview, count int) {
613639
614640func parsePreviewSelection(rawSelection string, selectionOptions []SelectionOption) (SelectionOption, error) {
615641 selected := strings.TrimSpace(rawSelection)
642 selected = strings.TrimSpace(pangoStrip.ReplaceAllString(selected, ""))
643 selected = strings.TrimPrefix(selected, "[NEW] ")
644 selected = strings.TrimSpace(selected)
616645
617646 switch selected {
618647 case "":
@@ -641,7 +670,7 @@ func downloadToCache(imageURL string) (string, error) {
641670 }
642671
643672 cacheDir := os.ExpandEnv("${HOME}/.cache/curd/images")
644 if err := os.MkdirAll(cacheDir, 0755); err != nil {
673 if err := os.MkdirAll(cacheDir, 0o755); err != nil {
645674 return "", fmt.Errorf("failed to create cache directory: %w", err)
646675 }
647676
@@ -725,8 +754,7 @@ func rofiSelectInternal(options []SelectionOption, isHomeMenu bool, refreshConfi
725754 for {
726755 optionsString := buildRofiOptionsString(currentOptions, isHomeMenu)
727756 configPath := filepath.Join(GetStoragePath(), "selectanime.rasi")
728 // -markup: enable Pango in -mesg (and prompts where supported)
729 args := []string{"-dmenu", "-theme", configPath, "-i", "-markup", "-p", prompt}
757 args := []string{"-dmenu", "-theme", configPath, "-i", "-markup", "-markup-rows", "-p", prompt}
730758 if msg := strings.TrimSpace(message); msg != "" {
731759 args = append(args, "-mesg", msg)
732760 }
@@ -894,7 +922,11 @@ func dynamicSelectInternal(options []SelectionOption, refreshConfig *SelectionRe
894922func buildRofiOptionsString(options []SelectionOption, isHomeMenu bool) string {
895923 optionsList := make([]string, 0, len(options)+2)
896924 for _, opt := range options {
897 optionsList = append(optionsList, opt.Label)
925 if opt.HasNewEpisodes {
926 optionsList = append(optionsList, fmt.Sprintf("<span foreground=\"%s\">[NEW]</span> %s", rofiNewEpisodeColor, opt.Label))
927 } else {
928 optionsList = append(optionsList, opt.Label)
929 }
898930 }
899931
900932 if !isHomeMenu {
@@ -917,8 +949,12 @@ func parseRofiSelection(err error, rawSelection string, options []SelectionOptio
917949 }
918950
919951 selected := strings.TrimSpace(rawSelection)
920 // Strip accidental Pango/markup noise if a theme echoes it.
921 selected = strings.TrimSpace(ansiStrip.ReplaceAllString(selected, ""))
952 // strip accidental pango noise if a theme echoes it.
953 selected = strings.TrimSpace(pangoStrip.ReplaceAllString(
954 ansiStrip.ReplaceAllString(selected, ""), "",
955 ))
956 selected = strings.TrimPrefix(selected, "[NEW] ")
957 selected = strings.TrimSpace(selected)
922958 switch {
923959 case selected == "":
924960 if isHomeMenu {
internal/structs.go +22 −14
@@ -71,6 +71,11 @@ type NextEpisode struct {
7171 Mode string
7272}
7373
74type NextAiringEpisodeInfo struct {
75 Episode int
76 TimeUntilAiring int
77}
78
7479// StreamPlaybackHint carries MPV playback metadata for a resolved stream URL.
7580type StreamPlaybackHint struct {
7681 Referrer string
@@ -127,13 +132,14 @@ type ResponseData struct {
127132}
128133
129134type Media struct {
130 Duration int `json:"duration"`
131 Episodes int `json:"episodes"`
132 Format string `json:"format"`
133 ID int `json:"id"`
134 MalID int `json:"mal_id"`
135 Title AnimeTitle `json:"title"`
136 Status string `json:"status"`
135 Duration int `json:"duration"`
136 Episodes int `json:"episodes"`
137 Format string `json:"format"`
138 ID int `json:"id"`
139 MalID int `json:"mal_id"`
140 Title AnimeTitle `json:"title"`
141 Status string `json:"status"`
142 NextAiringEpisode *NextAiringEpisodeInfo `json:"nextAiringEpisode,omitempty"`
137143}
138144
139145type Entry struct {
@@ -159,8 +165,9 @@ type AnimeList struct {
159165}
160166
161167type RofiSelectPreview struct {
162 Title string `json:"title"`
163 CoverImage string `json:"coverImage"`
168 Title string `json:"title"`
169 CoverImage string `json:"coverImage"`
170 HasNewEpisodes bool `json:"-"`
164171}
165172
166173type SelectionOptionImage struct {
@@ -171,9 +178,10 @@ type SelectionOptionImage struct {
171178
172179// SelectionOption holds the label and the internal key
173180type SelectionOption struct {
174 Title string
175 Label string
176 Key string
177 Thumbnail string
178 ExtraData interface{}
181 Title string
182 Label string
183 Key string
184 Thumbnail string
185 ExtraData interface{}
186 HasNewEpisodes bool
179187}
internal/update.go +1
@@ -287,6 +287,7 @@ var (
287287 mdLinkRe = regexp.MustCompile(`\[([^\]]+)\]\(([^)]+)\)`)
288288 mdURLRe = regexp.MustCompile(`https?://[^\s<>\]]+`)
289289 ansiStrip = regexp.MustCompile(`\x1b\[[0-9;]*m`)
290 pangoStrip = regexp.MustCompile(`<[^>]*>`)
290291)
291292
292293// markdownToPango turns common GitHub release markdown into Rofi-friendly Pango.
rofi/selectanimepreview.rasi +1 −1
@@ -6,7 +6,7 @@
66 text-color: #BBBBBB; /* Default text color (light gray) */
77 text-color-selected: #FFFFFF; /* Text color when selected (white) */
88 primary: rgba(53, 132, 228, 0.75); /* Blusish primary color */
9 important: rgba(53, 132, 228, 0.75); /* Bluish primary color */
9 important: rgba(53, 132, 228, 0.75); /* Bluish primary color */
1010}
1111
1212configuration {