Skip to content

Commit

Permalink
feat!(config): allow for actual ints ig
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Jun 7, 2024
1 parent 59b4654 commit afa0726
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
26 changes: 14 additions & 12 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"log"
"strconv"

"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -53,19 +52,22 @@ func (m Model) handleWindowSize(msg tea.WindowSizeMsg) Model {
}

var glamWidth glamour.TermRendererOption
switch lib.UserConfig.Reader.Size {
case "full", "fullscreen":
glamWidth = glamour.WithWordWrap(width)
case "most":
glamWidth = glamour.WithWordWrap(int(float64(width) * 0.75))
case "recomended":
glamWidth = glamour.WithWordWrap(80)
default:
w, err := strconv.Atoi(lib.UserConfig.Reader.Size)
if err != nil {
log.Fatalf("could not convert reader size to int: %v", err)
switch lib.UserConfig.Reader.Size.(type) {
case string:
switch lib.UserConfig.Reader.Size {
case "full", "fullscreen":
glamWidth = glamour.WithWordWrap(width)
case "most":
glamWidth = glamour.WithWordWrap(int(float64(width) * 0.75))
case "recomended":
glamWidth = glamour.WithWordWrap(80)
}

case int64:
w := int(lib.UserConfig.Reader.Size.(int64))
glamWidth = glamour.WithWordWrap(w)
default:
log.Fatalf("invalid reader size: %v", lib.UserConfig.Reader.Size)
}
m.glam, _ = glamour.NewTermRenderer(
glamour.WithEnvironmentConfig(),
Expand Down
4 changes: 2 additions & 2 deletions example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ read_threshold = 0.75

# this value can be "most", "recommended" or "full" and controls the
# width of the article should be displayed to the users screen
# this value can also be a number contained by "", however this is not
# recommended as it will not be responsive to screen sizes
# this value can also be an int, however this is not recommended as
# it will not be responsive to screen sizes
size = "full"

# these values can be any format that lipgloss supports
Expand Down
12 changes: 6 additions & 6 deletions lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ var UserConfig = config{

// Config is the struct that holds the configuration
type config struct {
Colors colors `toml:"colors"`
Reader reader `toml:"reader"`
DateFormat string `toml:"dateformat"`
Urls []string `toml:"urls"`
Colors colors `toml:"colors"`
Reader reader `toml:"reader"`
DateFormat string `toml:"dateformat"`
Urls []string `toml:"urls"`
}

type colors struct {
Expand All @@ -64,6 +64,6 @@ type colors struct {
}

type reader struct {
Size string `toml:"size"`
ReadThreshold float64 `toml:"read_threshold"`
Size interface{} `toml:"size"`
ReadThreshold float64 `toml:"read_threshold"`
}

0 comments on commit afa0726

Please sign in to comment.