Skip to content

Commit e87d677

Browse files
committed
add catpuccin themes
1 parent f9acf99 commit e87d677

16 files changed

+628
-580
lines changed

README.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
- **push**: Quickly send text to the `vimbin` server from the command line. This allows for easy integration with other tools and scripts, streamlining the process of sharing content through `vimbin`.
88

9+
## Themes
10+
11+
For the editor you can chooe between the catppuchin themes `latte`, `mocha`, `frappe` or `macchiato`. If theme is set to `auto`, it gets system preference.
12+
13+
Themes are borrowed from [here](https://github.com/catppuccin/codemirror).
14+
915
## Commands
1016

1117
### Global Flags
@@ -28,13 +34,14 @@ Start the server:
2834

2935
**Flags:**
3036

31-
| Flag | Description |
32-
| :-------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------- |
33-
| `-d`, `--directory` `DIRECTORY` | The path to the storage directory. (default `$(pwd)`) |
34-
| `-a`, `--listen-address` `ADDRESS:PORT` | The address to listen on for HTTP requests. (default `:8080`) |
35-
| `-n`, `--name` string | The name of the file to save. (default ".vimbin") |
36-
| `--theme` THEME | The theme to use. Can be `auto`, `light` or `dark`. (default `auto`). Can also be set with the environment variable `VIMBIN_THEME` |
37-
| `-h`, `--help` | help for serve |
37+
| Flag | Description |
38+
| :-------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
39+
| `-d`, `--directory` `DIRECTORY` | The path to the storage directory. (default `$(pwd)`) |
40+
| `-a`, `--listen-address` `ADDRESS:PORT` | The address to listen on for HTTP requests. (default `:8080`) |
41+
| `-n`, `--name` string | The name of the file to save. (default ".vimbin") |
42+
| `--theme` THEME | The theme to use. Can be `auto`, `light` or `dark`. (default `auto`). Can also be set with the environment variable `VIMBIN_THEME` |
43+
| `--dark-theme` THEME | When `theme` set to `auto`, use this as dark theme. Can be `mocha`, `frappe`, `macchiato`. (default `frappe`). Can also be set with the environment variable `VIMBIN_DARK_THEME` |
44+
| `-h`, `--help` | help for serve |
3845

3946
### Push
4047

cmd/serve.go

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func init() {
7575
return config.SupportedThemes, cobra.ShellCompDirectiveDefault
7676
})
7777

78+
serveCmd.PersistentFlags().StringVarP(&config.App.Server.Web.Theme, "dark-theme", "", "frappe", fmt.Sprintf("When theme set to auto, use this as dark theme. Can be %s.", config.DarkThemes))
79+
serveCmd.RegisterFlagCompletionFunc("dark-theme", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
80+
return config.DarkThemes, cobra.ShellCompDirectiveDefault
81+
})
7882
serveCmd.PersistentFlags().StringVarP(&config.App.Storage.Directory, "directory", "d", "$(pwd)", "The path to the storage directory. Defaults to the current working directory.")
7983
serveCmd.PersistentFlags().StringVarP(&config.App.Storage.Name, "name", "n", ".vimbin", "The name of the file to save.")
8084
}

internal/config/parse.go

+14
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ func (c *Config) Parse() (err error) {
6464
log.Debug().Msgf("Generated API token: %s", c.Server.Api.Token.Get())
6565
}
6666

67+
// Theme defaults
68+
c.Server.Web.LightTheme = "latte"
69+
if c.Server.Web.DarkTheme == "" {
70+
c.Server.Web.DarkTheme = "frappe"
71+
}
72+
6773
// Check if the theme was set as ENV variable
6874
if theme := os.Getenv("VIMBIN_THEME"); theme != "" {
6975
if !utils.IsInList(theme, SupportedThemes) {
@@ -73,5 +79,13 @@ func (c *Config) Parse() (err error) {
7379
log.Debug().Msgf("Using theme from ENV variable: %s", theme)
7480
}
7581

82+
if darkTheme := os.Getenv("VIMBIN_DARK_THEME"); darkTheme != "" {
83+
if !utils.IsInList(darkTheme, DarkThemes) {
84+
return fmt.Errorf("Unsupported dark theme: %s. Supported dark themes are: %s", darkTheme, DarkThemes)
85+
}
86+
c.Server.Web.DarkTheme = darkTheme
87+
log.Debug().Msgf("Using dark theme from ENV variable: %s", darkTheme)
88+
}
89+
7690
return nil
7791
}

internal/config/structs.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ type Config struct {
1919

2020
// Web represents the web configuration.
2121
type Web struct {
22-
Theme string `mapstructure:"server"` // Theme is the theme to use for the web interface.
23-
Address string `mapstructure:"address"` // Address is the address to listen on for HTTP requests.
22+
Theme string `mapstructure:"server"` // Theme is the theme to use for the web interface.
23+
DarkTheme string `mapstructure:"darkTheme"` // DarkTheme is the theme to use for the web interface when dark mode is enabled.
24+
LightTheme string `mapstructure:"lightTheme"` // LightTheme is the theme to use for the web interface when light mode is enabled.
25+
Address string `mapstructure:"address"` // Address is the address to listen on for HTTP requests.
2426
}
2527

2628
// Token represents the API token.

internal/config/utils.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,27 @@ return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
3333
// Themes is a list of themes supported by the serve command.
3434
type Themes []string
3535

36-
// SupportedThemes is a list of themes supported by the serve command.
37-
var SupportedThemes = Themes{"auto", "light", "dark"}
38-
3936
// String returns the list of themes as a string.
4037
func (t Themes) String() string {
4138
return strings.Join(t, ", ")
4239
}
4340

41+
var (
42+
DarkThemes Themes
43+
LightThemes Themes
44+
DarkTheme string
45+
SupportedThemes Themes
46+
)
47+
48+
func init() {
49+
LightThemes = Themes{"latte"}
50+
DarkThemes = Themes{"mocha", "frappe", "macchiato"}
51+
DarkTheme = "mocha" // dark theme if theme is set to auto
52+
53+
SupportedThemes = append(Themes{"auto"}, LightThemes...)
54+
SupportedThemes = append(SupportedThemes, DarkThemes...)
55+
}
56+
4457
// checkStorageFile checks if the storage file exists; if not, it creates it with default content.
4558
//
4659
// Parameters:

internal/handlers/home.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ func Home(w http.ResponseWriter, r *http.Request) {
2727
log.Trace().Msg(generateHTTPRequestLogEntry(r))
2828

2929
page := Page{
30-
Title: "vimbin - a pastebin with vim motion",
31-
Content: config.App.Storage.Content.Get(),
32-
Token: config.App.Server.Api.Token.Get(),
33-
Theme: config.App.Server.Web.Theme,
34-
Version: config.App.Version,
30+
Title: "vimbin - a pastebin with vim motion",
31+
Content: config.App.Storage.Content.Get(),
32+
Token: config.App.Server.Api.Token.Get(),
33+
Theme: config.App.Server.Web.Theme,
34+
LightTheme: config.App.Server.Web.LightTheme,
35+
DarkTheme: config.App.Server.Web.DarkTheme,
36+
Version: config.App.Version,
3537
}
3638

3739
if err := config.App.HtmlTemplate.Execute(w, page); err != nil {

internal/handlers/structs.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ package handlers
55
// This struct holds information about the title and content of a page, which can be
66
// utilized by the HTML template to render dynamic content.
77
type Page struct {
8-
Title string // Title is the title of the page.
9-
Content string // Content is the content of the page.
10-
Token string // Token is the API token.
11-
Theme string // Theme is the theme of the page.
12-
Version string // Version is the version of the application.
8+
Title string // Title is the title of the page.
9+
Content string // Content is the content of the page.
10+
Token string // Token is the API token.
11+
Theme string // Theme is the theme of the page.
12+
LightTheme string // LightTheme is the light theme of the page.
13+
DarkTheme string // DarkTheme is the dark theme of the page.
14+
Version string // Version is the version of the application.
1315
}

0 commit comments

Comments
 (0)