Skip to content

Commit

Permalink
fix: context not appearing when switching modes
Browse files Browse the repository at this point in the history
updated_at is updated on summary/context change
  • Loading branch information
dhth committed Jul 13, 2024
1 parent 9daef72 commit dd1a781
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 127 deletions.
100 changes: 66 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,49 @@ omm guide
`omm`'s TUI is comprised of several panes: 2 lists (for active and archived
tasks), a context pane, and a task entry/update pane.

You can do the following via the TUI:

- create/update tasks at a specific position in the priority list
- add/update context for a task
- add a task at the start/end of the list
- move a task to the top of the list (indicating that it takes the highest
priority at the moment)
- move task up/down based on changing priorities
- archive/unarchive a task
- view archived tasks
- delete a task
#### Active Tasks List

As the name suggests, the active tasks list is for the tasks you're actively
working on right now. It allows you to do the following:

- Create/update tasks at a specific position in the priority list
- Add a task at the start/end of the list
- Move a task to the top of the list (indicating that it takes the highest
Priority at the moment)
- Move task up/down based on changing priorities
- Permanently delete a task

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

#### Archived Tasks List

Once you're done with a task, you can archive it, which puts it in the archived
tasks list. It's more for historical reference, but you can also unarchive a
task and put it in the active list, if you need to. You can also permanently
delete tasks from here.

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

#### Context Pane

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 `EDITOR`
- the environment variable `VISUAL`
- `vi` (fallback)

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

#### Task Entry Pane

This is where you enter/update a task summary. If you enter a summary in the
format `prefix: task summary goes here`, `omm` will highlight the prefix for you
in the task lists.

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

#### Tweaking the TUI

Expand All @@ -93,11 +125,11 @@ omm --list-density=spacious

Compact mode:

![compact mode](https://tools.dhruvs.space/images/omm/omm-1.png)
![compact](https://tools.dhruvs.space/images/omm/omm-compact-1.png)

Spacious mode:

![spacious mode](https://tools.dhruvs.space/images/omm/omm-2.png)
![spacious](https://tools.dhruvs.space/images/omm/omm-spacious-1.png)

### Importing tasks

Expand Down Expand Up @@ -136,27 +168,27 @@ omm tasks
---

```text
j/↓ move cursor down
k/↑ move cursor up
o/a add task below cursor
O add task above cursor
I add task at the top
A add task at the end
u update task summary
⏎ move task to the top
[2-9] move task at index [x] to top (only in compact view)
J move task one position down
K move task one position up
ctrl+d archive/unarchive task
ctrl+x delete task
g go to the top
G go to the end
tab move between views
c update context for a task
d show task details in a full screen pane
v toggle between compact and spacious view
` toggle showing context
q/esc/ctrl+c go back/quit
j/↓ move cursor down
k/↑ move cursor up
o/a add task below cursor
O add task above cursor
I add task at the top
A add task at the end
u update task summary
move task to the top
[2-9] move task at index [x] to top (only in compact view)
J move task one position down
K move task one position up
ctrl+d archive/unarchive task
ctrl+x delete task
g go to the top
G go to the end
tab move between views
c update context for a task
d show task details in a full screen pane
v toggle between compact and spacious view
` toggle showing context
q/esc/ctrl+c go back/quit
```

Acknowledgements
Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
listDensityVal string
viewType ui.ListDensityType
textEditorCmd string
contextPane bool
showContext bool
)

func die(msg string, args ...any) {
Expand Down Expand Up @@ -166,7 +166,7 @@ Tip: Quickly add a task using 'omm "task summary goes here"'.
ArchivedTaskListColor: archivedTaskListColor,
TaskListTitle: taskListTitle,
TextEditorCmd: strings.Fields(editorCmd),
ContextPane: contextPane,
ShowContext: showContext,
}

ui.RenderUI(db, config)
Expand Down Expand Up @@ -259,7 +259,7 @@ Error: %s`, author, repoIssuesUrl, guideErr)
ArchivedTaskListColor: archivedTaskListColor,
TaskListTitle: taskListTitle,
TextEditorCmd: strings.Fields(editorCmd),
ContextPane: contextPane,
ShowContext: showContext,
Guide: true,
}

Expand Down Expand Up @@ -305,7 +305,7 @@ func init() {
rootCmd.Flags().StringVar(&taskListTitle, "title", ui.TaskListDefaultTitle, fmt.Sprintf("title of the task list, will trim till %d chars", taskListTitleMaxLen))
rootCmd.Flags().StringVar(&listDensityVal, "list-density", ui.CompactDensityVal, fmt.Sprintf("type of density for the list; possible values: [%s, %s]", ui.CompactDensityVal, ui.SpaciousDensityVal))
rootCmd.Flags().StringVar(&textEditorCmd, "editor", "", "editor command to run when adding/editing context to a task; if absent, omm falls back to $EDITOR, or $VISUAL, in that order")
rootCmd.Flags().BoolVar(&contextPane, "context-pane", true, "whether to start omm with a visible task context pane or not; this can be toggled on/off in the TUI by pressing the backtick(`) key")
rootCmd.Flags().BoolVar(&showContext, "show-context", true, "whether to start omm with a visible task context pane or not; this can later be toggled on/off in the TUI by pressing the backtick(`) key")

tasksCmd.Flags().Uint8VarP(&printTasksNum, "num", "n", printTasksDefault, "number of tasks to print")

Expand Down
37 changes: 24 additions & 13 deletions internal/persistence/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func UpdateTaskSequenceInDB(db *sql.DB, sequence []uint64) error {
}

stmt, err := db.Prepare(`
UPDATE task_sequence SET sequence = ? where id = 1;
UPDATE task_sequence
SET sequence = ?
WHERE id = 1;
`)
if err != nil {
return err
Expand Down Expand Up @@ -125,7 +127,9 @@ VALUES (?, ?, ?, ?);`
}

seqUpdateStmt, err := tx.Prepare(`
UPDATE task_sequence SET sequence = ? where id = 1;
UPDATE task_sequence
SET sequence = ?
WHERE id = 1;
`)
if err != nil {
return err
Expand Down Expand Up @@ -210,7 +214,9 @@ VALUES `
}

seqUpdateStmt, err := tx.Prepare(`
UPDATE task_sequence SET sequence = ? where id = 1;
UPDATE task_sequence
SET sequence = ?
WHERE id = 1;
`)
if err != nil {
return err
Expand Down Expand Up @@ -273,7 +279,9 @@ VALUES `
}

seqUpdateStmt, err := tx.Prepare(`
UPDATE task_sequence SET sequence = ? where id = 1;
UPDATE task_sequence
SET sequence = ?
WHERE id = 1;
`)
if err != nil {
return err
Expand All @@ -293,59 +301,62 @@ UPDATE task_sequence SET sequence = ? where id = 1;
return nil
}

func UpdateTaskSummaryInDB(db *sql.DB, id uint64, summary string) error {
func UpdateTaskSummaryInDB(db *sql.DB, id uint64, summary string, updatedAt time.Time) error {

stmt, err := db.Prepare(`
UPDATE task
SET summary = ?
SET summary = ?,
updated_at = ?
WHERE id = ?
`)
if err != nil {
return err
}
defer stmt.Close()

_, err = stmt.Exec(summary, id)
_, err = stmt.Exec(summary, updatedAt.UTC(), id)

if err != nil {
return err
}
return nil
}

func UpdateTaskContextInDB(db *sql.DB, id uint64, context string) error {
func UpdateTaskContextInDB(db *sql.DB, id uint64, context string, updatedAt time.Time) error {

stmt, err := db.Prepare(`
UPDATE task
SET context = ?
SET context = ?,
updated_at = ?
WHERE id = ?
`)
if err != nil {
return err
}
defer stmt.Close()

_, err = stmt.Exec(context, id)
_, err = stmt.Exec(context, updatedAt.UTC(), id)

if err != nil {
return err
}
return nil
}

func UnsetTaskContextInDB(db *sql.DB, id uint64) error {
func UnsetTaskContextInDB(db *sql.DB, id uint64, updatedAt time.Time) error {

stmt, err := db.Prepare(`
UPDATE task
SET context = NULL
SET context = NULL,
updated_at = ?
WHERE id = ?
`)
if err != nil {
return err
}
defer stmt.Close()

_, err = stmt.Exec(id)
_, err = stmt.Exec(updatedAt.UTC(), id)

if err != nil {
return err
Expand Down
12 changes: 7 additions & 5 deletions internal/ui/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ func deleteTask(db *sql.DB, id uint64, index int, active bool) tea.Cmd {

func updateTaskSummary(db *sql.DB, listIndex int, id uint64, summary string) tea.Cmd {
return func() tea.Msg {
err := pers.UpdateTaskSummaryInDB(db, id, summary)
return taskSummaryUpdatedMsg{listIndex, id, summary, err}
now := time.Now()
err := pers.UpdateTaskSummaryInDB(db, id, summary, now)
return taskSummaryUpdatedMsg{listIndex, id, summary, now, err}
}
}

func updateTaskContext(db *sql.DB, listIndex int, id uint64, context string, list taskListType) tea.Cmd {
return func() tea.Msg {
var err error
now := time.Now()
if context == "" {
err = pers.UnsetTaskContextInDB(db, id)
err = pers.UnsetTaskContextInDB(db, id, now)
} else {
err = pers.UpdateTaskContextInDB(db, id, context)
err = pers.UpdateTaskContextInDB(db, id, context, now)
}
return taskContextUpdatedMsg{listIndex, list, id, context, err}
return taskContextUpdatedMsg{listIndex, list, id, context, now, err}
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/ui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ type Config struct {
TextEditorCmd []string
Guide bool
DBPath string
ContextPane bool
ShowContext bool
}
42 changes: 21 additions & 21 deletions internal/ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ import "fmt"
var helpStr = fmt.Sprintf(`omm ("on-my-mind") is a keyboard-driven task manager for the command line.
[Keymaps]
j/↓ move cursor down
k/↑ move cursor up
o/a add task below cursor
O add task above cursor
I add task at the top
A add task at the end
u update task summary
⏎ move task to the top
[2-9] move task at index [x] to top (only in compact view)
J move task one position down
K move task one position up
ctrl+d archive/unarchive task
ctrl+x delete task
g go to the top
G go to the end
tab move between views
c update context for a task
d show task details in a full screen pane
v toggle between compact and spacious view
%s toggle showing context
q/esc/ctrl+c go back/quit
j/↓ move cursor down
k/↑ move cursor up
o/a add task below cursor
O add task above cursor
I add task at the top
A add task at the end
u update task summary
move task to the top
[2-9] move task at index [x] to top (only in compact view)
J move task one position down
K move task one position up
ctrl+d archive/unarchive task
ctrl+x delete task
g go to the top
G go to the end
tab move between views
c update context for a task
d show task details in a full screen pane
v toggle between compact and spacious view
%s toggle showing context
q/esc/ctrl+c go back/quit
Run "omm guide" for a guided walkthrough of omm's features.
`, "`")
1 change: 1 addition & 0 deletions internal/ui/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func InitialModel(db *sql.DB, config Config) model {
atlTitleStyle: archivedTaskListTitleStyle,
tlSelStyle: tlSelItemStyle,
atlSelStyle: atlSelItemStyle,
contextVPTaskId: 0,
}

return m
Expand Down
1 change: 1 addition & 0 deletions internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ type model struct {
atlSelStyle lipgloss.Style
terminalWidth int
terminalHeight int
contextVPTaskId uint64
}
2 changes: 2 additions & 0 deletions internal/ui/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type taskSummaryUpdatedMsg struct {
listIndex int
id uint64
taskSummary string
updatedAt time.Time
err error
}

Expand All @@ -39,6 +40,7 @@ type taskContextUpdatedMsg struct {
list taskListType
id uint64
context string
updatedAt time.Time
err error
}

Expand Down
Loading

0 comments on commit dd1a781

Please sign in to comment.