Skip to content

Commit

Permalink
Added list-width config command
Browse files Browse the repository at this point in the history
  • Loading branch information
aQaTL committed Feb 11, 2019
1 parent 819f424 commit f9d6f70
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
23 changes: 18 additions & 5 deletions anilist_app.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"math"
"net/url"
"sort"
"strconv"
Expand Down Expand Up @@ -229,6 +230,13 @@ func AniListApp(app *cli.App) *cli.App {
UsageText: "mal cfg max [number]",
Action: configChangeMax,
},
cli.Command{
Name: "list-width",
Usage: "Change the width of displayed list",
UsageText: "mal cfg list-width [width]",
SkipFlagParsing: true,
Action: configChangeListWidth,
},
cli.Command{
Name: "status",
Usage: "Status value of displayed entries",
Expand Down Expand Up @@ -307,18 +315,23 @@ func aniListDefaultAction(ctx *cli.Context) error {
visibleEntries = len(list)
}

fmt.Printf("No%64s%8s%6s\n", "Title", "Eps", "Score")
fmt.Println(strings.Repeat("=", 80))
pattern := "%2d%64.64s%8s%6d\n"
numberFieldWidth := int(math.Max(math.Ceil(math.Log10(float64(visibleEntries+1))), 2))
titleWidth := cfg.ListWidth - numberFieldWidth - 8 - 6
fmt.Printf("%*s%*.*s%8s%6s\n",
numberFieldWidth, "No", titleWidth, titleWidth, "Title", "Eps", "Score")
fmt.Println(strings.Repeat("=", cfg.ListWidth))
pattern := "%*d%*.*s%8s%6d\n"
var entry *anilist.MediaListEntry
for i := visibleEntries - 1; i >= 0; i-- {
entry = &list[i]
if entry.Id == cfg.ALSelectedID {
color.HiYellow(pattern, i+1, entry.Title.UserPreferred,
color.HiYellow(pattern, numberFieldWidth, i+1, titleWidth, titleWidth,
entry.Title.UserPreferred,
fmt.Sprintf("%d/%d", entry.Progress, entry.Episodes),
entry.Score)
} else {
fmt.Printf(pattern, i+1, entry.Title.UserPreferred,
fmt.Printf(pattern, numberFieldWidth, i+1, titleWidth, titleWidth,
entry.Title.UserPreferred,
fmt.Sprintf("%d/%d", entry.Progress, entry.Episodes),
entry.Score)
}
Expand Down
15 changes: 15 additions & 0 deletions config.go
Expand Up @@ -22,6 +22,7 @@ type Config struct {
StatusAutoUpdateMode StatusAutoUpdateMode
Sorting Sorting
LastUpdate time.Time
ListWidth int

BrowserPath string
TorrentClientPath string
Expand All @@ -42,6 +43,7 @@ func NewConfig() *Config {
MaxVisibleEntries: 20,
StatusAutoUpdateMode: Off,
Sorting: ByLastUpdated,
ListWidth: 80,

TorrentClientPath: "qbittorrent",

Expand Down Expand Up @@ -131,6 +133,19 @@ func configChangeMax(ctx *cli.Context) error {
return nil
}

func configChangeListWidth(ctx *cli.Context) error {
cfg := LoadConfig()

width, err := strconv.Atoi(ctx.Args().First())
if err != nil || width < 20 {
return fmt.Errorf("invalid or too small width")
}

cfg.ListWidth = width
cfg.Save()
return nil
}

func configChangeMalStatus(ctx *cli.Context) error {
cfg := LoadConfig()

Expand Down

0 comments on commit f9d6f70

Please sign in to comment.