You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+68Lines changed: 68 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,54 @@ Gleeter understands the following commands:
60
60
*`id <number>`: Fetches the comic with the specified ID and displays it in the terminal. Replace `<number>` with the desired comic ID.
61
61
*`serve <port> <base_path>`: Starts a web server to serve the comics. `<port>` is optional and defaults to 8080. `<base_path>` is also optional and defaults to "". For example, `gleeter serve 3000 /comics` will start the server on port 3000 and serve the comics under the `/comics` path.
62
62
63
+
## Configuration File
64
+
65
+
Gleeter uses a TOML configuration file to customize its behavior. The configuration file allows you to configure the starting comic for random mode, set screen dimensions, and define aliases for comic IDs.
66
+
67
+
### Syntax
68
+
69
+
Here's an example configuration file (based on `test_data/config.toml`):
70
+
71
+
```toml
72
+
random_start = 38
73
+
74
+
[screen]
75
+
max_cols = 80
76
+
max_lines = 23
77
+
78
+
[[alias]]
79
+
name = "bobbytables"
80
+
type = "id"
81
+
id = 987
82
+
83
+
[[alias]]
84
+
name = "rnd"
85
+
type = "random"
86
+
87
+
[[alias]]
88
+
name = "l"
89
+
type = "latest"
90
+
```
91
+
92
+
### Structure and Usage
93
+
94
+
The configuration file is loaded when Gleeter starts. Gleeter looks for the configuration file in `$XDG_CONFIG_HOME/gleeter/config.toml` or `$HOME/.config/gleeter/config.toml`. If neither of these is found, it uses `./config.toml`. The settings defined in the file are used to initialize the application and control its behavior.
95
+
96
+
***`random_start`**: Specifies the starting comic number for the random comic selection. If not specified, a default value is used.
97
+
98
+
***`[screen]`**: This section configures the screen dimensions for displaying comics.
99
+
*`max_cols`: Specifies the maximum number of columns to use for displaying the comic.
100
+
*`max_lines`: Specifies the maximum number of lines to use for displaying the comic.
101
+
102
+
***`[[alias]]`**: This section defines aliases for accessing comics. You can define multiple aliases.
103
+
*`name`: The name of the alias.
104
+
*`type`: The type of alias. Valid values are `"id"`, `"random"`, and `"latest"`.
105
+
*`id`: (Only required for `"id"` aliases) The comic ID to associate with the alias.
106
+
107
+
The `src/gleeter/config.gleam` file defines the structure of the configuration data and how it is parsed from the TOML file.
108
+
109
+
To modify Gleeter's behavior, simply edit the configuration file and restart the application.
110
+
63
111
### Serve mode details
64
112
65
113
When Gleeter is run in `serve` mode, it starts an HTTP server that exposes the following endpoints:
@@ -78,6 +126,26 @@ You can customize the base path for these endpoints by using the `<base_path>` a
78
126
79
127
Gleeter also supports receiving the terminal size via HTTP headers. You can send the `X-TERMINAL-COLUMNS` and `X-TERMINAL-ROWS` headers with your request to specify the terminal size. This allows Gleeter to properly format the comic for your terminal. If these headers are not provided, Gleeter will use a default terminal size. Please be aware that for the resizing to work, you need to send **both** headers.
80
128
129
+
On top of that, Serve mode will also honour all the aliases defined in the [configuration file](#configuration-file), and expose them all at the root of the `base_path`. As a quick example, imagine you have the following defined in the `config.toml` file:
130
+
```toml
131
+
[[alias]]
132
+
name = "bobbytables"
133
+
type = "id"
134
+
id = 987
135
+
136
+
[[alias]]
137
+
name = "rnd"
138
+
type = "random"
139
+
140
+
[[alias]]
141
+
name = "l"
142
+
type = "latest"
143
+
```
144
+
145
+
And you start the server with `gleeter serve 8080 /comics`, on top of the URLs mentioned above, you will also get the following:
146
+
*`/comics/bobbytables`, which will be an alias for `/comics/id/987`
147
+
*`/comics/rnd`, which will be an alias for `/comics/random`
148
+
*`/comics/l`, which will be an alias for `/comics/latest`
0 commit comments