Skip to content

Commit 8d2e169

Browse files
authored
feat: add support for toml config (#8)
1 parent ae25b22 commit 8d2e169

File tree

10 files changed

+483
-276
lines changed

10 files changed

+483
-276
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ justfile
77
debug.log
88
tasks.txt
99
.cmds
10+
dist

README.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ omm guide
5959

6060
### TUI
6161

62-
`omm`'s TUI is comprised of several panes: 2 lists (for active and archived
63-
tasks), a context pane, and a task entry/update pane.
62+
`omm`'s TUI is comprised of several panes: 3 lists (for active and archived
63+
tasks, and one for context bookmarks), a context pane, and a task entry/update
64+
pane.
6465

6566
#### Active Tasks List
6667

@@ -92,18 +93,16 @@ For tasks that need more details that you can fit in a one line summary, there
9293
is the context pane. You add/update context for a task via a text editor which
9394
is chosen based on the following look ups:
9495

95-
- the `--editor` flag
96-
- the environment variable `OMM_EDITOR`
97-
- the environment variable `EDITOR`
98-
- the environment variable `VISUAL`
96+
- the "--editor" flag
97+
- $OMM_EDITOR
98+
- "editor" property in omm's toml config
99+
- $EDITOR/$VISUAL
99100
- `vi` (fallback)
100101

101-
The context pane can be hidden on startup by either setting the environment
102-
variable `OMM_SHOW_CONTEXT=0`, or by providing the flag `--show-context=false`
103-
(the latter takes priority).
104-
105102
![active-tasks](https://tools.dhruvs.space/images/omm/omm-context-1.png)
106103

104+
**[`^ back to top ^`](#omm)**
105+
107106
#### Task Entry Pane
108107

109108
This is where you enter/update a task summary. If you enter a summary in the
@@ -166,6 +165,30 @@ up the TUI.
166165
omm "Install spring-loaded boxing glove"
167166
```
168167

168+
### Configuration
169+
170+
`omm` allows you to change the some of its behavior via configuration, which it
171+
will consider in the order listed below:
172+
173+
- CLI flags (run `omm -h` to see details)
174+
- Environment variables (eg. `OMM_EDITOR`)
175+
- A TOML configuration file (run `omm -h` to see where this lives; you can
176+
change this via the flag `--config-path`)
177+
178+
Here's a sample config file:
179+
180+
```toml
181+
db_path = "~/.local/share/omm/omm-w.db"
182+
tl_color = "#b8bb26"
183+
atl_color = "#fabd2f"
184+
title = "work"
185+
list_density = "spacious"
186+
show_context = false
187+
editor = "vi -u NONE"
188+
```
189+
190+
**[`^ back to top ^`](#omm)**
191+
169192
Outputting tasks
170193
---
171194

@@ -225,8 +248,10 @@ Context Bookmarks List
225248
Acknowledgements
226249
---
227250

228-
`omm` is built using [bubbletea][1], and is released using [goreleaser][2], both
229-
of which are amazing tools.
251+
`omm` stands on the shoulders of giants.
252+
253+
- [bubbletea](https://github.com/charmbracelet/bubbletea) as the TUI framework
254+
- [sqlite](https://www.sqlite.org) as the local database
255+
- [goreleaser](https://github.com/goreleaser/goreleaser) for releasing binaries
230256

231-
[1]: https://github.com/charmbracelet/bubbletea
232-
[2]: https://github.com/goreleaser/goreleaser
257+
**[`^ back to top ^`](#omm)**

cmd/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cmd
2+
3+
var (
4+
sampleCfg = `db_path = "~/.local/share/omm/omm-w.db"
5+
tl_color = "#b8bb26"
6+
atl_color = "#fabd2f"
7+
title = "work"
8+
list_density = "spacious"
9+
show_context = false
10+
editor = "vi -u NONE"
11+
`
12+
)

cmd/db_migrations.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"database/sql"
5+
"fmt"
56
"time"
67
)
78

@@ -46,10 +47,10 @@ LIMIT 1;
4647
return dbVersion, err
4748
}
4849

49-
func upgradeDBIfNeeded(db *sql.DB) {
50+
func upgradeDBIfNeeded(db *sql.DB) error {
5051
latestVersionInDB, versionErr := fetchLatestDBVersion(db)
5152
if versionErr != nil {
52-
die(`Couldn't get omm's latest database version. This is a fatal error; let %s
53+
return fmt.Errorf(`Couldn't get omm's latest database version. This is a fatal error; let %s
5354
know about this via %s.
5455
5556
Error: %s`,
@@ -59,38 +60,43 @@ Error: %s`,
5960
}
6061

6162
if latestVersionInDB.version > latestDBVersion {
62-
die(`Looks like you downgraded omm. You should either delete omm's
63+
return fmt.Errorf(`Looks like you downgraded omm. You should either delete omm's
6364
database file (you will lose data by doing that), or upgrade omm to
6465
the latest version.`)
6566
}
6667

6768
if latestVersionInDB.version < latestDBVersion {
68-
upgradeDB(db, latestVersionInDB.version)
69+
err := upgradeDB(db, latestVersionInDB.version)
70+
if err != nil {
71+
return err
72+
}
6973
}
74+
75+
return nil
7076
}
7177

72-
func upgradeDB(db *sql.DB, currentVersion int) {
78+
func upgradeDB(db *sql.DB, currentVersion int) error {
7379
migrations := getMigrations()
7480
for i := currentVersion + 1; i <= latestDBVersion; i++ {
7581
migrateQuery := migrations[i]
7682
migrateErr := runMigration(db, migrateQuery, i)
7783
if migrateErr != nil {
78-
die(`Something went wrong migrating omm's database to version %d. This is not
84+
return fmt.Errorf(`Something went wrong migrating omm's database to version %d. This is not
7985
supposed to happen. You can try running omm by passing it a custom database
8086
file path (using --dbpath; this will create a new database) to see if that fixes
8187
things. If that works, you can either delete the previous database, or keep
8288
using this new database (both are not ideal).
8389
84-
If you can, let %s know about this error via
85-
%s.
90+
If you can, let %s know about this error via %s.
8691
Sorry for breaking the upgrade step!
8792
8893
---
8994
90-
Error: %s
95+
DB Error: %s
9196
`, i, author, repoIssuesUrl, migrateErr)
9297
}
9398
}
99+
return nil
94100
}
95101

96102
func runMigration(db *sql.DB, migrateQuery string, version int) error {

cmd/guide.go

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"database/sql"
5+
"fmt"
56
"time"
67

78
pers "github.com/dhth/omm/internal/persistence"
@@ -31,7 +32,7 @@ instructions.
3132
true,
3233
},
3334
{
34-
"guide: tasks",
35+
"domain: tasks",
3536
`omm ("on-my-mind") is a task manager. You can also think of it as a keyboard
3637
driven to-do list.
3738
@@ -46,7 +47,7 @@ you want to save details that don't fit in a single line.
4647
true,
4748
},
4849
{
49-
"guide: task state",
50+
"domain: task state",
5051
`A task can be in one of two states: active or archived.
5152
5253
This list shows active tasks.
@@ -60,7 +61,7 @@ Press <tab> to see the archived list.
6061
true,
6162
},
6263
{
63-
"guide: task details",
64+
"domain: task details",
6465
`The "Task Details" pane is intended for when you simply want to read all the
6566
details associated with a task in a full screen view.
6667
@@ -78,7 +79,7 @@ smaller display at the moment.
7879
true,
7980
},
8081
{
81-
"guide: an archived task",
82+
"domain: an archived task",
8283
`This is the archived list, meaning it holds tasks that are no longer being
8384
worked on.
8485
@@ -92,41 +93,34 @@ Press tab/q/esc/ctrl+c to go back to the active list.
9293
false,
9394
},
9495
{
95-
"guide: list density",
96+
"visuals: list density",
9697
`omm's task lists can be viewed in two density modes: compact and spacious.
9798
9899
This is the compact mode. As opposed to this, the spacious mode shows tasks in a
99100
more roomier list, alongside highlighting prefixes (we'll see what that means),
100101
and showing creation timestamps. Since the list in this mode takes more space,
101102
the context pane is shorter than the one in the compact mode.
102103
103-
omm starts up with compact mode by default, but you can change that by either
104-
setting the environment variable $OMM_LIST_DENSITY=spacious, or by passing the
105-
flag "--list-density=spacious" to omm (the latter takes priority).
106-
107-
You can toggle between the two modes by pressing "v". Choose whichever mode fits
108-
your workflow better.
104+
omm starts up with compact mode by default (you can change this, as we'll see
105+
soon). You can toggle between the two modes by pressing "v". Choose whichever
106+
mode fits your workflow better.
109107
110108
Try it out. Come back to this mode once you're done.
111109
`,
112110
true,
113111
},
114112
{
115-
"guide: toggling context pane",
113+
"visuals: toggling context pane",
116114
`The context pane can be toggled on/off by pressing "C".
117115
118116
You can choose to display it or not based on your preference. For convenience,
119117
the lists will always highlight tasks that have a context associated with them
120118
by having a "(c)" marker on them.
121-
122-
You can start omm with the context pane hidden by either setting the environment
123-
variable OMM_SHOW_CONTEXT to "0/1" or "true/false", or by passing the flag
124-
"--show-context=false" (the latter takes priority).
125119
`,
126120
true,
127121
},
128122
{
129-
"guide: adding tasks",
123+
"actions: adding tasks",
130124
`Let's get to the crux of omm: adding and prioritizing tasks.
131125
132126
We'll begin with adding tasks. You can add a task below the cursor by pressing
@@ -145,7 +139,7 @@ Go ahead, create a task, then move to the next guided item.
145139
true,
146140
},
147141
{
148-
"guide: adding tasks via the CLI",
142+
"actions: adding tasks via the CLI",
149143
`You can also add a task to omm via its command line interface. For example:
150144
151145
omm 'prefix: a task summary'
@@ -166,24 +160,19 @@ omm will expect each line in stdin to hold one task's summary.
166160
true,
167161
},
168162
{
169-
"guide: adding context",
163+
"actions: adding context",
170164
`As mentioned before, once a task is created, you might want to add context to
171165
it.
172166
173-
You do that by pressing "c". This will open up the text editor you've configured
174-
via the environment variables $OMM_EDITOR/$EDITOR/$VISUAL (looked up in that
175-
order). You can override this behavior by passing the "editor" flag to omm, like
176-
"--editor='vi -u NONE'". If none of these are set, omm falls back to "vi".
177-
178-
Go ahead, press "c". Try changing the text, and then save the file. This context
179-
text should get updated accordingly.
167+
You do that by pressing "c". Go ahead, try it out. Try changing the text, and
168+
then save the file. This context text should get updated accordingly.
180169
181170
Once saved, you can also copy a tasks's context to your system clipboard by pressing "y".
182171
`,
183172
true,
184173
},
185174
{
186-
"guide: context bookmarks",
175+
"domain: context bookmarks",
187176
`Sometimes you'll save some URLs to a task's context.
188177
189178
Such URLs (eg. https://github.com/dhth/omm, https://tools.dhruvs.space,
@@ -201,7 +190,7 @@ Try both approaches now. Press "b", interact with the list, and then press "B".
201190
true,
202191
},
203192
{
204-
"guide: task priorities",
193+
"domain: task priorities",
205194
`At its core, omm is a dynamic list that maintains a sequence of tasks based on
206195
the priorities you assign them.
207196
@@ -220,7 +209,7 @@ the top.
220209
true,
221210
},
222211
{
223-
"guide: updating task details",
212+
"actions: updating task details",
224213
`Once a task is created, its summary and context can be changed at any point.
225214
226215
You can update a task's summary by pressing "u".
@@ -235,6 +224,40 @@ Similarly, you can also update a task's context any time (by pressing "c").
235224
`,
236225
true,
237226
},
227+
{
228+
"config: changing the defaults",
229+
`omm allows you to change the some of its behavior via configuration, which it
230+
will consider in the order listed below:
231+
232+
- CLI flags (run "omm -h" to see details)
233+
- Environment variables (eg. "OMM_EDITOR")
234+
- A TOML configuration file (run "omm -h" to see where this lives; you can
235+
change this via the flag "--config-path")
236+
237+
omm will consider configuration in the order laid out above, ie, CLI flags will
238+
take the highest priority.
239+
`,
240+
true,
241+
},
242+
{
243+
"config: flags, env vars, and config file",
244+
`Every flag listed by "omm -h" (except "--config-path") has an environment
245+
variable counterpart, as well as a TOML config counterpart.
246+
247+
For example:
248+
249+
--show-context -> OMM_SHOW_CONTEXT -> show_context
250+
--editor -> OMM_EDITOR -> editor
251+
`,
252+
true,
253+
},
254+
{
255+
"config: a sample TOML config",
256+
fmt.Sprintf(`Here's a sample TOML configuration file:
257+
258+
%s`, sampleCfg),
259+
true,
260+
},
238261
{
239262
"guide: and that's it!",
240263
`That's it for the walkthrough!

0 commit comments

Comments
 (0)