Skip to content

Commit c8c2be4

Browse files
authored
feat: allow opening urls in context (#7)
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
1 parent 786aa7e commit c8c2be4

18 files changed

+628
-150
lines changed

README.md

+27-10
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,29 @@ omm tasks
179179
---
180180

181181
```text
182+
General
183+
q/esc/ctrl+c go back
184+
Q quit from anywhere
185+
186+
Active/Archived Tasks List
182187
j/↓ move cursor down
183188
k/↑ move cursor up
189+
h go to previous page
190+
l go to next page
191+
g go to the top
192+
G go to the end
193+
tab move between lists
194+
C toggle showing context
195+
d toggle Task Details pane
196+
b open context bookmarks list
197+
B open all bookmarks in the current task's context
198+
c update context for a task
199+
ctrl+d archive/unarchive task
200+
ctrl+x delete task
201+
v toggle between compact and spacious view
202+
203+
Active Tasks List
204+
q/esc/ctrl+c quit
184205
o/a add task below cursor
185206
O add task above cursor
186207
I add task at the top
@@ -190,17 +211,13 @@ u update task summary
190211
[2-9] move task at index [x] to top (only in compact view)
191212
J move task one position down
192213
K move task one position up
193-
ctrl+d archive/unarchive task
194-
ctrl+x delete task
195-
g go to the top
196-
G go to the end
197-
tab move between views
198-
c update context for a task
199-
C toggle showing context
200-
d toggle Task Details pane
201-
v toggle between compact and spacious view
214+
215+
Task Details Pane
202216
h/l move backwards/forwards when in the task details view
203-
q/esc/ctrl+c go back/quit
217+
B open all bookmarks in the current task's context
218+
219+
Context Bookmarks List
220+
⏎ open URL in browser
204221
```
205222

206223
Acknowledgements

cmd/guide.go

+36-15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ be "on your mind". However, there are benefits to having a list of archived
5656
tasks as well.
5757
5858
Press <tab> to see the archived list.
59+
`,
60+
true,
61+
},
62+
{
63+
"guide: task details",
64+
`The "Task Details" pane is intended for when you simply want to read all the
65+
details associated with a task in a full screen view.
66+
67+
You can view this pane by pressing "d".
68+
69+
Whilst in this pane, you can move backwards and forwards in the
70+
task list by pressing "h/<-/->/l". You quit out of this pane by either pressing
71+
"d" again, or q/esc/ctrl+c.
72+
73+
Try it out. Come back to this entry when you're done.
74+
75+
You might have to view this guide in the "Task Details" pane if you're on a
76+
smaller display at the moment.
5977
`,
6078
true,
6179
},
@@ -159,6 +177,24 @@ order). You can override this behavior by passing the "editor" flag to omm, like
159177
160178
Go ahead, press "c". Try changing the text, and then save the file. This context
161179
text should get updated accordingly.
180+
`,
181+
true,
182+
},
183+
{
184+
"guide: context bookmarks",
185+
`Sometimes you'll save some URLs to a task's context.
186+
187+
Such URLs (eg. https://github.com/dhth/omm, https://tools.dhruvs.space,
188+
https://c.xkcd.com/random/comic) could be placed anywhere in the context.
189+
190+
omm lets you open these URLs via a single keypress. You can either press "b" to
191+
open up a list of all URLs, and then open one of them by pressing ⏎, or open all
192+
of them by pressing "B".
193+
194+
Note: if the context has a single URL in it, pressing "b" will skip showing the
195+
list, and open the URL directly.
196+
197+
Try both approaches now. Press "b", interact with the list, and then press "B".
162198
`,
163199
true,
164200
},
@@ -178,21 +214,6 @@ priority order. It has the following keymaps to achieve this:
178214
179215
It's recommended that you move the task that you're currently focussing on to
180216
the top.
181-
`,
182-
true,
183-
},
184-
{
185-
"guide: task details",
186-
`The "Task Details" pane is intended for when you simply want to read all the
187-
details associated with a task in a full screen view.
188-
189-
You can view this pane by pressing "d".
190-
191-
Whilst in this pane, you can move backwards and forwards in the
192-
task list by pressing "h/l". You quit out of this pane by either pressing "d"
193-
again, or q/esc/ctrl+c.
194-
195-
Try it out. Come back to this entry when you're done.
196217
`,
197218
true,
198219
},

go.mod

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ require (
66
github.com/charmbracelet/bubbles v0.18.0
77
github.com/charmbracelet/bubbletea v0.26.6
88
github.com/charmbracelet/lipgloss v0.11.0
9+
github.com/dustin/go-humanize v1.0.1
910
github.com/spf13/cobra v1.8.1
11+
github.com/stretchr/testify v1.9.0
1012
modernc.org/sqlite v1.30.1
13+
mvdan.cc/xurls/v2 v2.5.0
1114

1215
)
1316

@@ -18,7 +21,7 @@ require (
1821
github.com/charmbracelet/x/input v0.1.2 // indirect
1922
github.com/charmbracelet/x/term v0.1.1 // indirect
2023
github.com/charmbracelet/x/windows v0.1.2 // indirect
21-
github.com/dustin/go-humanize v1.0.1 // indirect
24+
github.com/davecgh/go-spew v1.1.1 // indirect
2225
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
2326
github.com/google/uuid v1.6.0 // indirect
2427
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
@@ -32,6 +35,7 @@ require (
3235
github.com/muesli/reflow v0.3.0 // indirect
3336
github.com/muesli/termenv v0.15.2 // indirect
3437
github.com/ncruces/go-strftime v0.1.9 // indirect
38+
github.com/pmezard/go-difflib v1.0.0 // indirect
3539
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
3640
github.com/rivo/uniseg v0.4.7 // indirect
3741
github.com/sahilm/fuzzy v0.1.1 // indirect
@@ -40,6 +44,7 @@ require (
4044
golang.org/x/sync v0.7.0 // indirect
4145
golang.org/x/sys v0.22.0 // indirect
4246
golang.org/x/text v0.16.0 // indirect
47+
gopkg.in/yaml.v3 v3.0.1 // indirect
4348
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // indirect
4449
modernc.org/libc v1.54.3 // indirect
4550
modernc.org/mathutil v1.6.0 // indirect

go.sum

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKU
1717
github.com/charmbracelet/x/windows v0.1.2 h1:Iumiwq2G+BRmgoayww/qfcvof7W/3uLoelhxojXlRWg=
1818
github.com/charmbracelet/x/windows v0.1.2/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ=
1919
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
20+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
21+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2022
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
2123
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
2224
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
@@ -65,6 +67,8 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
6567
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
6668
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
6769
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
70+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
71+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
6872
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
6973
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
7074
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 h1:mchzmB1XO2pMaKFRqk/+MV3mgGG96aqaPXaMifQU47w=
@@ -81,7 +85,9 @@ golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
8185
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
8286
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
8387
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
88+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8489
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
90+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
8591
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8692
modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ=
8793
modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
@@ -109,3 +115,5 @@ modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
109115
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
110116
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
111117
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
118+
mvdan.cc/xurls/v2 v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
119+
mvdan.cc/xurls/v2 v2.5.0/go.mod h1:yQgaGQ1rFtJUzkmKiHYSSfuQxqfYmd//X6PxvholpeE=

internal/persistence/queries.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
const (
1212
TaskNumLimit = 300
13-
ContentMaxBytes = 3000
13+
ContextMaxBytes = 4096 // 4KB seems to be sufficient for context
1414
)
1515

1616
func FetchNumActiveTasksFromDB(db *sql.DB) (int, error) {

internal/types/types.go

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
prefixDelimiter = ":"
1717
prefixPadding = 80
1818
createdAtPadding = 40
19+
GOOSDarwin = "darwin"
1920
)
2021

2122
var (
@@ -53,6 +54,8 @@ type Task struct {
5354
UpdatedAt time.Time
5455
}
5556

57+
type ContextBookmark string
58+
5659
func (t Task) Title() string {
5760
summEls := strings.Split(t.Summary, prefixDelimiter)
5861
if len(summEls) == 1 {
@@ -100,3 +103,15 @@ func getDynamicStyle(str string) lipgloss.Style {
100103
return lipgloss.NewStyle().
101104
Foreground(lipgloss.Color(color))
102105
}
106+
107+
func (c ContextBookmark) Title() string {
108+
return string(c)
109+
}
110+
111+
func (c ContextBookmark) Description() string {
112+
return ""
113+
}
114+
115+
func (c ContextBookmark) FilterValue() string {
116+
return string(c)
117+
}

internal/ui/cmds.go

+26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ui
22

33
import (
44
"os/exec"
5+
"runtime"
56
"time"
67

78
"database/sql"
@@ -89,3 +90,28 @@ func openTextEditor(fPath string, editorCmd []string, taskIndex int, taskId uint
8990
return tea.Msg(textEditorClosed{fPath, taskIndex, taskId, oldContext, err})
9091
})
9192
}
93+
94+
func openURL(url string) tea.Cmd {
95+
var cmd string
96+
var args []string
97+
switch runtime.GOOS {
98+
case "windows":
99+
cmd = "cmd"
100+
args = []string{"/c", "start"}
101+
case "darwin":
102+
cmd = "open"
103+
default:
104+
cmd = "xdg-open"
105+
}
106+
c := exec.Command(cmd, append(args, url)...)
107+
return tea.ExecProcess(c, func(err error) tea.Msg {
108+
return urlOpenedMsg{url, err}
109+
})
110+
}
111+
112+
func openURLsDarwin(urls []string) tea.Cmd {
113+
c := exec.Command("open", urls...)
114+
return tea.ExecProcess(c, func(err error) tea.Msg {
115+
return urlsOpenedDarwinMsg{urls, err}
116+
})
117+
}

internal/ui/help.go

+62-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,62 @@
11
package ui
22

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

5-
Tip: Run "omm guide" for a guided walkthrough of omm's features.
5+
var (
6+
helpStr = fmt.Sprintf(`%s%s
67
7-
[Keymaps]
8-
j/↓ move cursor down
8+
%s
9+
10+
%s
11+
12+
%s
13+
14+
%s
15+
%s
16+
17+
%s
18+
%s
19+
20+
%s
21+
%s
22+
23+
%s
24+
%s
25+
26+
%s
27+
%s
28+
`, helpHeadingStyle.Render("omm"),
29+
helpSectionStyle.Render(` ("on-my-mind") is a keyboard-driven task manager for the command line.
30+
31+
Tip: Run "omm guide" for a guided walkthrough of omm's features.`),
32+
helpHeadingStyle.Render("omm has 5 components"),
33+
helpSectionStyle.Render(`1: Active Tasks List
34+
2: Archived Tasks List
35+
3: Task creation/update Pane
36+
4: Task Details Pane
37+
5: Context Bookmarks List`),
38+
helpHeadingStyle.Render("Keymaps"),
39+
helpSubHeadingStyle.Render("General"),
40+
helpSectionStyle.Render(`q/esc/ctrl+c go back
41+
Q quit from anywhere`),
42+
helpSubHeadingStyle.Render("Active/Archived Tasks List"),
43+
helpSectionStyle.Render(`j/↓ move cursor down
944
k/↑ move cursor up
45+
h go to previous page
46+
l go to next page
47+
g go to the top
48+
G go to the end
49+
tab move between lists
50+
C toggle showing context
51+
d toggle Task Details pane
52+
b open context bookmarks list
53+
B open all bookmarks in the current task's context
54+
c update context for a task
55+
ctrl+d archive/unarchive task
56+
ctrl+x delete task
57+
v toggle between compact and spacious view`),
58+
helpSubHeadingStyle.Render("Active Tasks List"),
59+
helpSectionStyle.Render(`q/esc/ctrl+c quit
1060
o/a add task below cursor
1161
O add task above cursor
1262
I add task at the top
@@ -15,16 +65,11 @@ u update task summary
1565
⏎ move task to the top
1666
[2-9] move task at index [x] to top (only in compact view)
1767
J move task one position down
18-
K move task one position up
19-
ctrl+d archive/unarchive task
20-
ctrl+x delete task
21-
g go to the top
22-
G go to the end
23-
tab move between views
24-
c update context for a task
25-
C toggle showing context
26-
d toggle Task Details pane
27-
v toggle between compact and spacious view
28-
h/l move backwards/forwards when in the task details view
29-
q/esc/ctrl+c go back/quit
30-
`
68+
K move task one position up`),
69+
helpSubHeadingStyle.Render("Task Details Pane"),
70+
helpSectionStyle.Render(`h/l move backwards/forwards when in the task details view
71+
B open all bookmarks in the current task's context`),
72+
helpSubHeadingStyle.Render("Context Bookmarks List"),
73+
helpSectionStyle.Render(`⏎ open URL in browser`),
74+
)
75+
)

0 commit comments

Comments
 (0)