Skip to content

Commit

Permalink
feat: add support for toml config (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth authored Jul 19, 2024
1 parent ae25b22 commit 8d2e169
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 276 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ justfile
debug.log
tasks.txt
.cmds
dist
53 changes: 39 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ omm guide

### TUI

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

#### Active Tasks List

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

- the `--editor` flag
- the environment variable `OMM_EDITOR`
- the environment variable `EDITOR`
- the environment variable `VISUAL`
- the "--editor" flag
- $OMM_EDITOR
- "editor" property in omm's toml config
- $EDITOR/$VISUAL
- `vi` (fallback)

The context pane can be hidden on startup by either setting the environment
variable `OMM_SHOW_CONTEXT=0`, or by providing the flag `--show-context=false`
(the latter takes priority).

![active-tasks](https://tools.dhruvs.space/images/omm/omm-context-1.png)

**[`^ back to top ^`](#omm)**

#### Task Entry Pane

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

### Configuration

`omm` allows you to change the some of its behavior via configuration, which it
will consider in the order listed below:

- CLI flags (run `omm -h` to see details)
- Environment variables (eg. `OMM_EDITOR`)
- A TOML configuration file (run `omm -h` to see where this lives; you can
change this via the flag `--config-path`)

Here's a sample config file:

```toml
db_path = "~/.local/share/omm/omm-w.db"
tl_color = "#b8bb26"
atl_color = "#fabd2f"
title = "work"
list_density = "spacious"
show_context = false
editor = "vi -u NONE"
```

**[`^ back to top ^`](#omm)**

Outputting tasks
---

Expand Down Expand Up @@ -225,8 +248,10 @@ Context Bookmarks List
Acknowledgements
---

`omm` is built using [bubbletea][1], and is released using [goreleaser][2], both
of which are amazing tools.
`omm` stands on the shoulders of giants.

- [bubbletea](https://github.com/charmbracelet/bubbletea) as the TUI framework
- [sqlite](https://www.sqlite.org) as the local database
- [goreleaser](https://github.com/goreleaser/goreleaser) for releasing binaries

[1]: https://github.com/charmbracelet/bubbletea
[2]: https://github.com/goreleaser/goreleaser
**[`^ back to top ^`](#omm)**
12 changes: 12 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cmd

var (
sampleCfg = `db_path = "~/.local/share/omm/omm-w.db"
tl_color = "#b8bb26"
atl_color = "#fabd2f"
title = "work"
list_density = "spacious"
show_context = false
editor = "vi -u NONE"
`
)
24 changes: 15 additions & 9 deletions cmd/db_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"database/sql"
"fmt"
"time"
)

Expand Down Expand Up @@ -46,10 +47,10 @@ LIMIT 1;
return dbVersion, err
}

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

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

if latestVersionInDB.version < latestDBVersion {
upgradeDB(db, latestVersionInDB.version)
err := upgradeDB(db, latestVersionInDB.version)
if err != nil {
return err
}
}

return nil
}

func upgradeDB(db *sql.DB, currentVersion int) {
func upgradeDB(db *sql.DB, currentVersion int) error {
migrations := getMigrations()
for i := currentVersion + 1; i <= latestDBVersion; i++ {
migrateQuery := migrations[i]
migrateErr := runMigration(db, migrateQuery, i)
if migrateErr != nil {
die(`Something went wrong migrating omm's database to version %d. This is not
return fmt.Errorf(`Something went wrong migrating omm's database to version %d. This is not
supposed to happen. You can try running omm by passing it a custom database
file path (using --dbpath; this will create a new database) to see if that fixes
things. If that works, you can either delete the previous database, or keep
using this new database (both are not ideal).
If you can, let %s know about this error via
%s.
If you can, let %s know about this error via %s.
Sorry for breaking the upgrade step!
---
Error: %s
DB Error: %s
`, i, author, repoIssuesUrl, migrateErr)
}
}
return nil
}

func runMigration(db *sql.DB, migrateQuery string, version int) error {
Expand Down
81 changes: 52 additions & 29 deletions cmd/guide.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"database/sql"
"fmt"
"time"

pers "github.com/dhth/omm/internal/persistence"
Expand Down Expand Up @@ -31,7 +32,7 @@ instructions.
true,
},
{
"guide: tasks",
"domain: tasks",
`omm ("on-my-mind") is a task manager. You can also think of it as a keyboard
driven to-do list.
Expand All @@ -46,7 +47,7 @@ you want to save details that don't fit in a single line.
true,
},
{
"guide: task state",
"domain: task state",
`A task can be in one of two states: active or archived.
This list shows active tasks.
Expand All @@ -60,7 +61,7 @@ Press <tab> to see the archived list.
true,
},
{
"guide: task details",
"domain: task details",
`The "Task Details" pane is intended for when you simply want to read all the
details associated with a task in a full screen view.
Expand All @@ -78,7 +79,7 @@ smaller display at the moment.
true,
},
{
"guide: an archived task",
"domain: an archived task",
`This is the archived list, meaning it holds tasks that are no longer being
worked on.
Expand All @@ -92,41 +93,34 @@ Press tab/q/esc/ctrl+c to go back to the active list.
false,
},
{
"guide: list density",
"visuals: list density",
`omm's task lists can be viewed in two density modes: compact and spacious.
This is the compact mode. As opposed to this, the spacious mode shows tasks in a
more roomier list, alongside highlighting prefixes (we'll see what that means),
and showing creation timestamps. Since the list in this mode takes more space,
the context pane is shorter than the one in the compact mode.
omm starts up with compact mode by default, but you can change that by either
setting the environment variable $OMM_LIST_DENSITY=spacious, or by passing the
flag "--list-density=spacious" to omm (the latter takes priority).
You can toggle between the two modes by pressing "v". Choose whichever mode fits
your workflow better.
omm starts up with compact mode by default (you can change this, as we'll see
soon). You can toggle between the two modes by pressing "v". Choose whichever
mode fits your workflow better.
Try it out. Come back to this mode once you're done.
`,
true,
},
{
"guide: toggling context pane",
"visuals: toggling context pane",
`The context pane can be toggled on/off by pressing "C".
You can choose to display it or not based on your preference. For convenience,
the lists will always highlight tasks that have a context associated with them
by having a "(c)" marker on them.
You can start omm with the context pane hidden by either setting the environment
variable OMM_SHOW_CONTEXT to "0/1" or "true/false", or by passing the flag
"--show-context=false" (the latter takes priority).
`,
true,
},
{
"guide: adding tasks",
"actions: adding tasks",
`Let's get to the crux of omm: adding and prioritizing tasks.
We'll begin with adding tasks. You can add a task below the cursor by pressing
Expand All @@ -145,7 +139,7 @@ Go ahead, create a task, then move to the next guided item.
true,
},
{
"guide: adding tasks via the CLI",
"actions: adding tasks via the CLI",
`You can also add a task to omm via its command line interface. For example:
omm 'prefix: a task summary'
Expand All @@ -166,24 +160,19 @@ omm will expect each line in stdin to hold one task's summary.
true,
},
{
"guide: adding context",
"actions: adding context",
`As mentioned before, once a task is created, you might want to add context to
it.
You do that by pressing "c". This will open up the text editor you've configured
via the environment variables $OMM_EDITOR/$EDITOR/$VISUAL (looked up in that
order). You can override this behavior by passing the "editor" flag to omm, like
"--editor='vi -u NONE'". If none of these are set, omm falls back to "vi".
Go ahead, press "c". Try changing the text, and then save the file. This context
text should get updated accordingly.
You do that by pressing "c". Go ahead, try it out. Try changing the text, and
then save the file. This context text should get updated accordingly.
Once saved, you can also copy a tasks's context to your system clipboard by pressing "y".
`,
true,
},
{
"guide: context bookmarks",
"domain: context bookmarks",
`Sometimes you'll save some URLs to a task's context.
Such URLs (eg. https://github.com/dhth/omm, https://tools.dhruvs.space,
Expand All @@ -201,7 +190,7 @@ Try both approaches now. Press "b", interact with the list, and then press "B".
true,
},
{
"guide: task priorities",
"domain: task priorities",
`At its core, omm is a dynamic list that maintains a sequence of tasks based on
the priorities you assign them.
Expand All @@ -220,7 +209,7 @@ the top.
true,
},
{
"guide: updating task details",
"actions: updating task details",
`Once a task is created, its summary and context can be changed at any point.
You can update a task's summary by pressing "u".
Expand All @@ -235,6 +224,40 @@ Similarly, you can also update a task's context any time (by pressing "c").
`,
true,
},
{
"config: changing the defaults",
`omm allows you to change the some of its behavior via configuration, which it
will consider in the order listed below:
- CLI flags (run "omm -h" to see details)
- Environment variables (eg. "OMM_EDITOR")
- A TOML configuration file (run "omm -h" to see where this lives; you can
change this via the flag "--config-path")
omm will consider configuration in the order laid out above, ie, CLI flags will
take the highest priority.
`,
true,
},
{
"config: flags, env vars, and config file",
`Every flag listed by "omm -h" (except "--config-path") has an environment
variable counterpart, as well as a TOML config counterpart.
For example:
--show-context -> OMM_SHOW_CONTEXT -> show_context
--editor -> OMM_EDITOR -> editor
`,
true,
},
{
"config: a sample TOML config",
fmt.Sprintf(`Here's a sample TOML configuration file:
%s`, sampleCfg),
true,
},
{
"guide: and that's it!",
`That's it for the walkthrough!
Expand Down
Loading

0 comments on commit 8d2e169

Please sign in to comment.