Skip to content

Commit

Permalink
Allow theming via the configuration of the reader
Browse files Browse the repository at this point in the history
  • Loading branch information
zMoooooritz committed Nov 11, 2023
1 parent b7ac021 commit ba3b96b
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 212 deletions.
6 changes: 4 additions & 2 deletions configs/example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ Application:
# Configuration of the theming
# Currently only the configuration of colors is implemented
Theme:
PrimaryColor: "62"
SecondaryColor: "230"
PrimaryColor: "#3636D1"
SecondaryColor: "#F8F8F2"
NormalTitleColor: "#DDDDDD"
NormalDescColor: "#777777"
SelectedPrimaryColor: "#AD58B4"
SelectedSecondaryColor: "#EE6FF8"
BreakingColor: "#FF0000"
ReaderHighlightColor: "#FFB86C"
ReaderHeadingColor: "#BD93F9"

9 changes: 3 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"flag"
"fmt"
"os"

"gopkg.in/yaml.v3"
Expand All @@ -21,6 +20,8 @@ type ThemeConfig struct {
SelectedPrimaryColor string `yaml:"SelectedPrimaryColor"`
SelectedSecondaryColor string `yaml:"SelectedSecondaryColor"`
BreakingColor string `yaml:"BreakingColor"`
ReaderHighlightColor string `yaml:"ReaderHighlightColor"`
ReaderHeadingColor string `yaml:"ReaderHeadingColor"`
}

type ApplicationsConfig struct {
Expand Down Expand Up @@ -62,13 +63,9 @@ func (c Config) Load() Configuration {

data, err := os.ReadFile(c.file)
if err != nil {
fmt.Println(err)
return config
}

err = yaml.Unmarshal(data, &config)
if err != nil {
fmt.Println(err)
}
_ = yaml.Unmarshal(data, &config)
return config
}
294 changes: 96 additions & 198 deletions pkg/config/glamour.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,220 +2,118 @@ package config

import "github.com/charmbracelet/glamour/ansi"

var NachrichtenStyleConfig = ansi.StyleConfig{
Document: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
BlockPrefix: "\n",
BlockSuffix: "\n",
Color: stringPtr("#f8f8f2"),
},
Margin: uintPtr(2),
},
BlockQuote: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr("#f1fa8c"),
Italic: boolPtr(true),
},
Indent: uintPtr(1),
IndentToken: stringPtr("| "),
},
List: ansi.StyleList{
LevelIndent: 2,
},
Heading: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
BlockSuffix: "\n",
Color: stringPtr("#bd93f9"),
Bold: boolPtr(true),
},
},
H1: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
Suffix: "",
Color: stringPtr("#bd93f9"),
BackgroundColor: stringPtr("#bd93f9"),
Bold: boolPtr(true),
},
},
H2: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "| ",
},
},
H3: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
},
},
H4: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
},
},
H5: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
},
},
H6: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
Color: stringPtr("#bd93f9"),
Bold: boolPtr(false),
},
},
Strikethrough: ansi.StylePrimitive{
CrossedOut: boolPtr(true),
},
Emph: ansi.StylePrimitive{
Italic: boolPtr(true),
},
Strong: ansi.StylePrimitive{
Bold: boolPtr(true),
Color: stringPtr("#ffb86c"),
},
HorizontalRule: ansi.StylePrimitive{
Color: stringPtr("#6272A4"),
Format: "\n--------\n",
},
Item: ansi.StylePrimitive{
BlockPrefix: "• ",
},
Enumeration: ansi.StylePrimitive{
BlockPrefix: ". ",
Color: stringPtr("#8be9fd"),
},
Task: ansi.StyleTask{
StylePrimitive: ansi.StylePrimitive{},
Ticked: "[✓] ",
Unticked: "[ ] ",
},
Link: ansi.StylePrimitive{
Color: stringPtr("#8be9fd"),
Underline: boolPtr(true),
},
LinkText: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
},
Image: ansi.StylePrimitive{
Color: stringPtr("#8be9fd"),
Underline: boolPtr(true),
},
ImageText: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
Format: "Image: {{.text}} →",
},
Code: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr("#50fa7b"),
},
},
CodeBlock: ansi.StyleCodeBlock{
StyleBlock: ansi.StyleBlock{
func CreateReaderStyle(t ThemeConfig) ansi.StyleConfig {
return ansi.StyleConfig{
Document: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr("#ffb86c"),
BlockSuffix: "\n",
Color: stringPtr(t.SecondaryColor),
},
Margin: uintPtr(2),
},
Chroma: &ansi.Chroma{
Text: ansi.StylePrimitive{
Color: stringPtr("#f8f8f2"),
},
Error: ansi.StylePrimitive{
Color: stringPtr("#f8f8f2"),
BackgroundColor: stringPtr("#ff5555"),
},
Comment: ansi.StylePrimitive{
Color: stringPtr("#6272A4"),
},
CommentPreproc: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
},
Keyword: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
},
KeywordReserved: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
},
KeywordNamespace: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
},
KeywordType: ansi.StylePrimitive{
Color: stringPtr("#8be9fd"),
},
Operator: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
},
Punctuation: ansi.StylePrimitive{
Color: stringPtr("#f8f8f2"),
},
Name: ansi.StylePrimitive{
Color: stringPtr("#8be9fd"),
},
NameBuiltin: ansi.StylePrimitive{
Color: stringPtr("#8be9fd"),
},
NameTag: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
},
NameAttribute: ansi.StylePrimitive{
Color: stringPtr("#50fa7b"),
},
NameClass: ansi.StylePrimitive{
Color: stringPtr("#8be9fd"),
},
NameConstant: ansi.StylePrimitive{
Color: stringPtr("#bd93f9"),
},
NameDecorator: ansi.StylePrimitive{
Color: stringPtr("#50fa7b"),
},
NameFunction: ansi.StylePrimitive{
Color: stringPtr("#50fa7b"),
BlockQuote: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr(""),
Italic: boolPtr(true),
},
LiteralNumber: ansi.StylePrimitive{
Color: stringPtr("#6EEFC0"),
},
List: ansi.StyleList{
LevelIndent: 2,
},
Heading: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr(t.ReaderHeadingColor),
Bold: boolPtr(true),
},
LiteralString: ansi.StylePrimitive{
Color: stringPtr("#f1fa8c"),
},
H1: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
},
LiteralStringEscape: ansi.StylePrimitive{
Color: stringPtr("#ff79c6"),
},
H2: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "| ",
},
GenericDeleted: ansi.StylePrimitive{
Color: stringPtr("#ff5555"),
},
H3: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
},
GenericEmph: ansi.StylePrimitive{
Color: stringPtr("#f1fa8c"),
Italic: boolPtr(true),
},
H4: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
},
GenericInserted: ansi.StylePrimitive{
Color: stringPtr("#50fa7b"),
},
H5: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
},
GenericStrong: ansi.StylePrimitive{
Color: stringPtr("#ffb86c"),
Bold: boolPtr(true),
},
H6: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Prefix: "",
},
GenericSubheading: ansi.StylePrimitive{
Color: stringPtr("#bd93f9"),
},
Strikethrough: ansi.StylePrimitive{
CrossedOut: boolPtr(true),
},
Emph: ansi.StylePrimitive{
Italic: boolPtr(true),
},
Strong: ansi.StylePrimitive{
Bold: boolPtr(true),
Color: stringPtr(t.ReaderHighlightColor),
},
HorizontalRule: ansi.StylePrimitive{
Color: stringPtr(""),
Format: "\n--------\n",
},
Item: ansi.StylePrimitive{
BlockPrefix: "• ",
},
Enumeration: ansi.StylePrimitive{
BlockPrefix: ". ",
Color: stringPtr(""),
},
Task: ansi.StyleTask{
StylePrimitive: ansi.StylePrimitive{},
Ticked: "[✓] ",
Unticked: "[ ] ",
},
Link: ansi.StylePrimitive{
Color: stringPtr(""),
Underline: boolPtr(true),
},
LinkText: ansi.StylePrimitive{
Color: stringPtr(""),
},
Image: ansi.StylePrimitive{
Color: stringPtr(""),
Underline: boolPtr(true),
},
ImageText: ansi.StylePrimitive{
Color: stringPtr(""),
Format: "Image: {{.text}} →",
},
Code: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr(""),
},
Background: ansi.StylePrimitive{
BackgroundColor: stringPtr("#282a36"),
},
Table: ansi.StyleTable{
StyleBlock: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{},
},
CenterSeparator: stringPtr("┼"),
ColumnSeparator: stringPtr("│"),
RowSeparator: stringPtr("─"),
},
},
Table: ansi.StyleTable{
StyleBlock: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{},
DefinitionDescription: ansi.StylePrimitive{
BlockPrefix: "\n🠶 ",
},
CenterSeparator: stringPtr("┼"),
ColumnSeparator: stringPtr("│"),
RowSeparator: stringPtr("─"),
},
DefinitionDescription: ansi.StylePrimitive{
BlockPrefix: "\n🠶 ",
},
}
}

func boolPtr(b bool) *bool { return &b }
Expand Down
Loading

0 comments on commit ba3b96b

Please sign in to comment.