Skip to content

Commit

Permalink
feat: bookmarks include urls in task summary
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Jul 19, 2024
1 parent 03ae2e9 commit 4a90459
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 49 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ omm guide
### TUI

`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
tasks, and one for task bookmarks), a context pane, and a task entry/update
pane.

#### Active Tasks List
Expand Down Expand Up @@ -216,11 +216,12 @@ 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
b open task bookmarks list
B open all bookmarks added to current task
c update context for a task
ctrl+d archive/unarchive task
ctrl+x delete task
ctrl+r reload task lists
y copy selected task's context to system clipboard
v toggle between compact and spacious view
Expand All @@ -239,9 +240,9 @@ K move task one position up
Task Details Pane
h/l move backwards/forwards when in the task details view
y copy selected task's context to system clipboard
B open all bookmarks in the current task's context
B open all bookmarks added to current task
Context Bookmarks List
Task Bookmarks List
⏎ open URL in browser
```

Expand Down
11 changes: 8 additions & 3 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"
"errors"
"fmt"
"time"
)
Expand All @@ -10,6 +11,12 @@ const (
latestDBVersion = 2 // only upgrade this after adding a migration in getMigrations
)

var (
dbDowngradedErr = errors.New(`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.`)
)

type dbVersionInfo struct {
id int
version int
Expand Down Expand Up @@ -60,9 +67,7 @@ Error: %s`,
}

if latestVersionInDB.version > latestDBVersion {
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.`)
return dbDowngradedErr
}

if latestVersionInDB.version < latestDBVersion {
Expand Down
11 changes: 6 additions & 5 deletions cmd/guide.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,19 @@ Once saved, you can also copy a tasks's context to your system clipboard by pres
true,
},
{
"domain: context bookmarks",
`Sometimes you'll save some URLs to a task's context.
"domain: task bookmarks",
`Sometimes you'll add URLs to a task's summary or its 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.
https://c.xkcd.com/random/comic) could be placed anywhere in the summary/
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.
Note: if the task has a single URL added to 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".
`,
Expand Down
14 changes: 10 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

pers "github.com/dhth/omm/internal/persistence"
"github.com/dhth/omm/internal/types"
"github.com/dhth/omm/internal/ui"
"github.com/dhth/omm/internal/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -44,6 +45,8 @@ var (
nothingToImportErr = errors.New("Nothing to import")

listDensityIncorrectErr = errors.New("List density is incorrect; valid values: compact/spacious")

taskSummaryTooLongErr = fmt.Errorf("Task summary is too long; max length allowed: %d", types.TaskSummaryMaxLen)
)

func Execute(version string) {
Expand Down Expand Up @@ -196,8 +199,11 @@ Tip: Quickly add a task using 'omm "task summary goes here"'.
RunE: func(cmd *cobra.Command, args []string) error {

if len(args) != 0 {
summary := utils.Trim(args[0], ui.TaskSummaryMaxLen)
err := importTask(db, summary)
if len(args[0]) > types.TaskSummaryMaxLen {
return taskSummaryTooLongErr
}

err := importTask(db, args[0])
if err != nil {
return err
}
Expand Down Expand Up @@ -259,8 +265,8 @@ Tip: Quickly add a task using 'omm "task summary goes here"'.

line := scanner.Text()
line = strings.TrimSpace(line)
if len(line) > ui.TaskSummaryMaxLen {
line = utils.Trim(line, ui.TaskSummaryMaxLen)
if len(line) > types.TaskSummaryMaxLen {
line = utils.Trim(line, types.TaskSummaryMaxLen)
}

if line != "" {
Expand Down
14 changes: 8 additions & 6 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
)

const (
timeFormat = "2006/01/02 15:04"
prefixDelimiter = ":"
prefixPadding = 80
createdAtPadding = 40
GOOSDarwin = "darwin"
timeFormat = "2006/01/02 15:04"
prefixDelimiter = ":"
prefixPadding = 80
createdAtPadding = 40
GOOSDarwin = "darwin"
taskSummaryWidth = 100
TaskSummaryMaxLen = 300
)

var (
Expand Down Expand Up @@ -61,7 +63,7 @@ func (t Task) Title() string {
if len(summEls) == 1 {
return t.Summary
}
return strings.TrimSpace(strings.Join(summEls[1:], prefixDelimiter))
return utils.Trim(strings.TrimSpace(strings.Join(summEls[1:], prefixDelimiter)), taskSummaryWidth)
}

func (t Task) Description() string {
Expand Down
11 changes: 6 additions & 5 deletions internal/ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Tip: Run "omm guide" for a guided walkthrough of omm's features.`),
2: Archived Tasks List
3: Task creation/update Pane
4: Task Details Pane
5: Context Bookmarks List`),
5: Task Bookmarks List`),
helpHeadingStyle.Render("Keymaps"),
helpSubHeadingStyle.Render("General"),
helpSectionStyle.Render(`q/esc/ctrl+c go back
Expand All @@ -49,11 +49,12 @@ 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
b open Task Bookmarks list
B open all bookmarks added to current task
c update context for a task
ctrl+d archive/unarchive task
ctrl+x delete task
ctrl+r reload task lists
y copy selected task's context to system clipboard
v toggle between compact and spacious view`),
helpSubHeadingStyle.Render("Active Tasks List"),
Expand All @@ -70,8 +71,8 @@ K move task one position up`),
helpSubHeadingStyle.Render("Task Details Pane"),
helpSectionStyle.Render(`h/l move backwards/forwards when in the task details view
y copy current task's context to system clipboard
B open all bookmarks in the current task's context`),
helpSubHeadingStyle.Render("Context Bookmarks List"),
B open all bookmarks added to current task`),
helpSubHeadingStyle.Render("Task Bookmarks List"),
helpSectionStyle.Render(`⏎ open URL in browser`),
)
)
19 changes: 8 additions & 11 deletions internal/ui/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import (
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/lipgloss"
"github.com/dhth/omm/internal/types"
"mvdan.cc/xurls/v2"
)

const (
TaskSummaryMaxLen = 100
)

func InitialModel(db *sql.DB, config Config) model {

taskItems := make([]list.Item, 0)
Expand All @@ -22,10 +19,10 @@ func InitialModel(db *sql.DB, config Config) model {
var taskList list.Model
switch config.ListDensity {
case Compact:
taskList = list.New(taskItems, itemDelegate{selStyle: tlSelItemStyle}, TaskSummaryMaxLen, compactListHeight)
taskList = list.New(taskItems, itemDelegate{selStyle: tlSelItemStyle}, taskSummaryWidth, compactListHeight)
taskList.SetShowStatusBar(false)
case Spacious:
taskList = list.New(taskItems, newTaskListDelegate(lipgloss.Color(config.TaskListColor)), TaskSummaryMaxLen, 14)
taskList = list.New(taskItems, newTaskListDelegate(lipgloss.Color(config.TaskListColor)), taskSummaryWidth, 14)
taskList.SetShowStatusBar(true)
}
taskList.SetShowTitle(false)
Expand All @@ -47,10 +44,10 @@ func InitialModel(db *sql.DB, config Config) model {
var archivedTaskList list.Model
switch config.ListDensity {
case Compact:
archivedTaskList = list.New(archivedTaskItems, itemDelegate{selStyle: atlSelItemStyle}, TaskSummaryMaxLen, compactListHeight)
archivedTaskList = list.New(archivedTaskItems, itemDelegate{selStyle: atlSelItemStyle}, taskSummaryWidth, compactListHeight)
archivedTaskList.SetShowStatusBar(false)
case Spacious:
archivedTaskList = list.New(archivedTaskItems, newTaskListDelegate(lipgloss.Color(config.ArchivedTaskListColor)), TaskSummaryMaxLen, 16)
archivedTaskList = list.New(archivedTaskItems, newTaskListDelegate(lipgloss.Color(config.ArchivedTaskListColor)), taskSummaryWidth, 16)
archivedTaskList.SetShowStatusBar(true)
}
archivedTaskList.SetShowTitle(false)
Expand All @@ -68,10 +65,10 @@ func InitialModel(db *sql.DB, config Config) model {

taskInput := textinput.New()
taskInput.Placeholder = "prefix: task summary goes here"
taskInput.CharLimit = TaskSummaryMaxLen
taskInput.Width = TaskSummaryMaxLen
taskInput.CharLimit = types.TaskSummaryMaxLen
taskInput.Width = taskSummaryWidth

contextBMList := list.New(nil, newContextURLListDel(contextBMColor), TaskSummaryMaxLen, compactListHeight)
contextBMList := list.New(nil, newContextURLListDel(contextBMColor), taskSummaryWidth, compactListHeight)

contextBMList.SetShowTitle(false)
contextBMList.SetShowHelp(false)
Expand Down
3 changes: 2 additions & 1 deletion internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
compactListHeight = 10
prefixPadding = 20
timeFormat = "2006/01/02 15:04"
taskSummaryWidth = 100
)

type itemDelegate struct {
Expand Down Expand Up @@ -52,7 +53,7 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
if t.Context != nil {
hasContext = "(c)"
}
str := fmt.Sprintf("[%d]\t%s%s", si+1, utils.RightPadTrim(summ, TaskSummaryMaxLen, true), hasContext)
str := fmt.Sprintf("[%d]\t%s%s", si+1, utils.RightPadTrim(summ, taskSummaryWidth, true), hasContext)

fn := itemStyle.Render
if index == m.Index() {
Expand Down
27 changes: 19 additions & 8 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.activeView = taskEntryView
return m, tea.Batch(cmds...)

case "ctrl+r":
if m.activeView != taskListView && m.activeView != archivedTaskListView {
break
}

cmds = append(cmds, fetchTasks(m.db, true, pers.TaskNumLimit))
cmds = append(cmds, fetchTasks(m.db, false, pers.TaskNumLimit))

case "ctrl+d":
switch m.activeView {
case taskListView:
Expand Down Expand Up @@ -746,18 +754,19 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

m.taskDetailsVP.GotoTop()
m.setContextFSContent(t)

case "b":
if m.activeView != taskListView && m.activeView != archivedTaskListView {
break
}

urls, ok := m.getContextUrls()
urls, ok := m.getTaskUrls()
if !ok {
break
}

if len(urls) == 0 {
m.errorMsg = "No bookmarks in this task's context"
m.errorMsg = "No bookmarks for this task"
break
}

Expand Down Expand Up @@ -785,13 +794,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
break
}

urls, ok := m.getContextUrls()
urls, ok := m.getTaskUrls()
if !ok {
break
}

if len(urls) == 0 {
m.errorMsg = "No bookmarks in this task's context"
m.errorMsg = "No bookmarks for this task"
break
}

Expand Down Expand Up @@ -1158,7 +1167,7 @@ last updated at %s
m.taskDetailsVP.SetContent(details)
}

func (m model) getContextUrls() ([]string, bool) {
func (m model) getTaskUrls() ([]string, bool) {
var t types.Task
var ok bool

Expand All @@ -1179,9 +1188,11 @@ func (m model) getContextUrls() ([]string, bool) {
return nil, false
}

if t.Context == nil {
return nil, true
var urls []string
urls = append(urls, utils.ExtractURLs(m.urlRegex, t.Summary)...)
if t.Context != nil {
urls = append(urls, utils.ExtractURLs(m.urlRegex, *t.Context)...)
}

return utils.ExtractURLs(m.urlRegex, *t.Context), true
return urls, true
}
2 changes: 1 addition & 1 deletion internal/ui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (m model) View() string {
return lipgloss.JoinVertical(lipgloss.Left, headerStyle.Render(header), context, statusBar)

case contextBookmarksView:
header = fmt.Sprintf("%s%s", contextBMTitleStyle.Render("Context Bookmarks"), helpMsg)
header = fmt.Sprintf("%s%s", contextBMTitleStyle.Render("Task Bookmarks"), helpMsg)

content = listStyle.Render(m.contextBMList.View())

Expand Down

0 comments on commit 4a90459

Please sign in to comment.