Skip to content

Commit

Permalink
feat: allow opening urls in context (#7)
Browse files Browse the repository at this point in the history
Overview
---

- Allows opening URLs saved in a task's context, either one by one, or all in one go.
- Updates the help section by segmenting key maps into sections based on the pane/view they apply to.
- Adds an entry regarding context bookmarks in the onboarding guide

Notes:
---

- Opening URLs on Windows needs to be tested
  • Loading branch information
dhth authored Jul 17, 2024
1 parent 786aa7e commit c8c2be4
Show file tree
Hide file tree
Showing 18 changed files with 628 additions and 150 deletions.
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,29 @@ omm tasks
---

```text
General
q/esc/ctrl+c go back
Q quit from anywhere
Active/Archived Tasks List
j/↓ move cursor down
k/↑ move cursor up
h go to previous page
l go to next page
g go to the top
G go to the end
tab move between lists
C toggle showing context
d toggle Task Details pane
b open context bookmarks list
B open all bookmarks in the current task's context
c update context for a task
ctrl+d archive/unarchive task
ctrl+x delete task
v toggle between compact and spacious view
Active Tasks List
q/esc/ctrl+c quit
o/a add task below cursor
O add task above cursor
I add task at the top
Expand All @@ -190,17 +211,13 @@ u update task summary
[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
C toggle showing context
d toggle Task Details pane
v toggle between compact and spacious view
Task Details Pane
h/l move backwards/forwards when in the task details view
q/esc/ctrl+c go back/quit
B open all bookmarks in the current task's context
Context Bookmarks List
⏎ open URL in browser
```

Acknowledgements
Expand Down
51 changes: 36 additions & 15 deletions cmd/guide.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ be "on your mind". However, there are benefits to having a list of archived
tasks as well.
Press <tab> to see the archived list.
`,
true,
},
{
"guide: 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.
You can view this pane by pressing "d".
Whilst in this pane, you can move backwards and forwards in the
task list by pressing "h/<-/->/l". You quit out of this pane by either pressing
"d" again, or q/esc/ctrl+c.
Try it out. Come back to this entry when you're done.
You might have to view this guide in the "Task Details" pane if you're on a
smaller display at the moment.
`,
true,
},
Expand Down Expand Up @@ -159,6 +177,24 @@ order). You can override this behavior by passing the "editor" flag to omm, like
Go ahead, press "c". Try changing the text, and then save the file. This context
text should get updated accordingly.
`,
true,
},
{
"guide: 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,
https://c.xkcd.com/random/comic) could be placed anywhere in the context.
omm lets you open these URLs via a single keypress. You can either press "b" to
open up a list of all URLs, and then open one of them by pressing ⏎, or open all
of them by pressing "B".
Note: if the context has a single URL in it, pressing "b" will skip showing the
list, and open the URL directly.
Try both approaches now. Press "b", interact with the list, and then press "B".
`,
true,
},
Expand All @@ -178,21 +214,6 @@ priority order. It has the following keymaps to achieve this:
It's recommended that you move the task that you're currently focussing on to
the top.
`,
true,
},
{
"guide: 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.
You can view this pane by pressing "d".
Whilst in this pane, you can move backwards and forwards in the
task list by pressing "h/l". You quit out of this pane by either pressing "d"
again, or q/esc/ctrl+c.
Try it out. Come back to this entry when you're done.
`,
true,
},
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ require (
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.26.6
github.com/charmbracelet/lipgloss v0.11.0
github.com/dustin/go-humanize v1.0.1
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
modernc.org/sqlite v1.30.1
mvdan.cc/xurls/v2 v2.5.0

)

Expand All @@ -18,7 +21,7 @@ require (
github.com/charmbracelet/x/input v0.1.2 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.1.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
Expand All @@ -32,6 +35,7 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sahilm/fuzzy v0.1.1 // indirect
Expand All @@ -40,6 +44,7 @@ require (
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // indirect
modernc.org/libc v1.54.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKU
github.com/charmbracelet/x/windows v0.1.2 h1:Iumiwq2G+BRmgoayww/qfcvof7W/3uLoelhxojXlRWg=
github.com/charmbracelet/x/windows v0.1.2/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
Expand Down Expand Up @@ -65,6 +67,8 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 h1:mchzmB1XO2pMaKFRqk/+MV3mgGG96aqaPXaMifQU47w=
Expand All @@ -81,7 +85,9 @@ golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ=
modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
Expand Down Expand Up @@ -109,3 +115,5 @@ modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
mvdan.cc/xurls/v2 v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
mvdan.cc/xurls/v2 v2.5.0/go.mod h1:yQgaGQ1rFtJUzkmKiHYSSfuQxqfYmd//X6PxvholpeE=
2 changes: 1 addition & 1 deletion internal/persistence/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

const (
TaskNumLimit = 300
ContentMaxBytes = 3000
ContextMaxBytes = 4096 // 4KB seems to be sufficient for context
)

func FetchNumActiveTasksFromDB(db *sql.DB) (int, error) {
Expand Down
15 changes: 15 additions & 0 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
prefixDelimiter = ":"
prefixPadding = 80
createdAtPadding = 40
GOOSDarwin = "darwin"
)

var (
Expand Down Expand Up @@ -53,6 +54,8 @@ type Task struct {
UpdatedAt time.Time
}

type ContextBookmark string

func (t Task) Title() string {
summEls := strings.Split(t.Summary, prefixDelimiter)
if len(summEls) == 1 {
Expand Down Expand Up @@ -100,3 +103,15 @@ func getDynamicStyle(str string) lipgloss.Style {
return lipgloss.NewStyle().
Foreground(lipgloss.Color(color))
}

func (c ContextBookmark) Title() string {
return string(c)
}

func (c ContextBookmark) Description() string {
return ""
}

func (c ContextBookmark) FilterValue() string {
return string(c)
}
26 changes: 26 additions & 0 deletions internal/ui/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ui

import (
"os/exec"
"runtime"
"time"

"database/sql"
Expand Down Expand Up @@ -89,3 +90,28 @@ func openTextEditor(fPath string, editorCmd []string, taskIndex int, taskId uint
return tea.Msg(textEditorClosed{fPath, taskIndex, taskId, oldContext, err})
})
}

func openURL(url string) tea.Cmd {
var cmd string
var args []string
switch runtime.GOOS {
case "windows":
cmd = "cmd"
args = []string{"/c", "start"}
case "darwin":
cmd = "open"
default:
cmd = "xdg-open"
}
c := exec.Command(cmd, append(args, url)...)
return tea.ExecProcess(c, func(err error) tea.Msg {
return urlOpenedMsg{url, err}
})
}

func openURLsDarwin(urls []string) tea.Cmd {
c := exec.Command("open", urls...)
return tea.ExecProcess(c, func(err error) tea.Msg {
return urlsOpenedDarwinMsg{urls, err}
})
}
79 changes: 62 additions & 17 deletions internal/ui/help.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
package ui

var helpStr = `omm ("on-my-mind") is a keyboard-driven task manager for the command line.
import "fmt"

Tip: Run "omm guide" for a guided walkthrough of omm's features.
var (
helpStr = fmt.Sprintf(`%s%s
[Keymaps]
j/↓ move cursor down
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
`, helpHeadingStyle.Render("omm"),
helpSectionStyle.Render(` ("on-my-mind") is a keyboard-driven task manager for the command line.
Tip: Run "omm guide" for a guided walkthrough of omm's features.`),
helpHeadingStyle.Render("omm has 5 components"),
helpSectionStyle.Render(`1: Active Tasks List
2: Archived Tasks List
3: Task creation/update Pane
4: Task Details Pane
5: Context Bookmarks List`),
helpHeadingStyle.Render("Keymaps"),
helpSubHeadingStyle.Render("General"),
helpSectionStyle.Render(`q/esc/ctrl+c go back
Q quit from anywhere`),
helpSubHeadingStyle.Render("Active/Archived Tasks List"),
helpSectionStyle.Render(`j/↓ move cursor down
k/↑ move cursor up
h go to previous page
l go to next page
g go to the top
G go to the end
tab move between lists
C toggle showing context
d toggle Task Details pane
b open context bookmarks list
B open all bookmarks in the current task's context
c update context for a task
ctrl+d archive/unarchive task
ctrl+x delete task
v toggle between compact and spacious view`),
helpSubHeadingStyle.Render("Active Tasks List"),
helpSectionStyle.Render(`q/esc/ctrl+c quit
o/a add task below cursor
O add task above cursor
I add task at the top
Expand All @@ -15,16 +65,11 @@ 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
C toggle showing context
d toggle Task Details pane
v toggle between compact and spacious view
h/l move backwards/forwards when in the task details view
q/esc/ctrl+c go back/quit
`
K move task one position up`),
helpSubHeadingStyle.Render("Task Details Pane"),
helpSectionStyle.Render(`h/l move backwards/forwards when in the task details view
B open all bookmarks in the current task's context`),
helpSubHeadingStyle.Render("Context Bookmarks List"),
helpSectionStyle.Render(`⏎ open URL in browser`),
)
)
Loading

0 comments on commit c8c2be4

Please sign in to comment.