Skip to content

Commit

Permalink
feat: render help using glamour
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Jul 22, 2024
1 parent 09d3cdb commit d501179
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 98 deletions.
149 changes: 70 additions & 79 deletions internal/ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,74 @@ package ui
import "fmt"

var (
helpStr = fmt.Sprintf(`%s%s
%s
%s
%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 6 components"),
helpSectionStyle.Render(`1: Active Tasks List
2: Archived Tasks List
3: Task creation/update Pane
4: Task Details Pane
5: Task Bookmarks List
6: Quick Filter 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 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
/ filter list by task prefix
ctrl+p open the "Quick Filter List"
y copy selected task's context to system clipboard
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
A add task at the end
u update task summary
⏎ move task to the top
J move task one position down
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 added to current task`),
helpSubHeadingStyle.Render("Task Bookmarks List"),
helpSectionStyle.Render(`⏎ open URL in browser`),
helpSubHeadingStyle.Render("Quick Filter List"),
helpSectionStyle.Render(`⏎ pre-populate task list's search prompt with chosen prefix`),
)
helpStr = fmt.Sprintf(`## Overview
**omm** ("on-my-mind") is a keyboard-driven task manager for the command line.
Tip: Run %s for a guided walkthrough of omm's features.
omm has 6 components:
- Active Tasks List
- Archived Tasks List
- Task creation/update Pane
- Task Details Pane
- Task Bookmarks List
- Quick Filter List
## Keymaps
### 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 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
/ filter list by task prefix
ctrl+p open the "Quick Filter List"
y copy selected task's context to system clipboard
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
A add task at the end
u update task summary
⏎ move task to the top
J move task one position down
K move task one position up
### Task Details Pane
h/←/→/l move backwards/forwards when in the task details view
y copy current task's context to system clipboard
B open all bookmarks added to current task
### Task Bookmarks List
⏎ open URL in browser
### Quick Filter List
⏎ pre-populate task list's search prompt with chosen prefix
`, "`omm guide`")
)
4 changes: 4 additions & 0 deletions internal/ui/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ func getMarkDownRenderer(wrap int) (*glamour.TermRenderer, error) {
var margin uint = 2
dracula := glamour.DraculaStyleConfig
dracula.Document.BlockPrefix = ""
dracula.H1.Prefix = ""
dracula.H2.Prefix = ""
dracula.H3.Prefix = ""
dracula.H4.Prefix = ""
dracula.Document.Margin = &margin

return glamour.NewTermRenderer(
Expand Down
10 changes: 0 additions & 10 deletions internal/ui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,11 @@ var (
formHelpStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color(formHelpColor))

helpViewStyle = lipgloss.NewStyle().
PaddingLeft(2)

helpStyle = lipgloss.NewStyle()

helpHeadingStyle = helpStyle.
Bold(true).
Foreground(lipgloss.Color(helpHeaderColor))

helpSectionStyle = helpStyle.
Foreground(lipgloss.Color(helpSectionColor))

helpSubHeadingStyle = helpSectionStyle.
Bold(true)

helpMsgStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color(helpMsgColor))
)
26 changes: 19 additions & 7 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,27 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.taskDetailsVP.Height = m.terminalHeight - 4
}

crWrap := (msg.Width - 4)
if crWrap > contextWordWrapUpperLimit {
crWrap = contextWordWrapUpperLimit
}
m.contextMdRenderer, _ = getMarkDownRenderer(crWrap)

helpToRender := helpStr
switch m.contextMdRenderer {
case nil:
break
default:
helpStrGl, err := m.contextMdRenderer.Render(helpStr)
if err != nil {
break
}
helpToRender = helpStrGl
}

if !m.helpVPReady {
m.helpVP = viewport.New(msg.Width-3, m.terminalHeight-4)
m.helpVP.SetContent(helpStr)
m.helpVP.SetContent(helpToRender)
m.helpVP.KeyMap.Up.SetEnabled(false)
m.helpVP.KeyMap.Down.SetEnabled(false)
m.helpVPReady = true
Expand All @@ -149,12 +167,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.helpVP.Height = m.terminalHeight - 4
}

crWrap := (msg.Width - 4)
if crWrap > contextWordWrapUpperLimit {
crWrap = contextWordWrapUpperLimit
}
m.contextMdRenderer, _ = getMarkDownRenderer(crWrap)

case tea.KeyMsg:
switch keypress := msg.String(); keypress {

Expand Down
4 changes: 2 additions & 2 deletions internal/ui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ func (m model) View() string {
`, helpTitleStyle.Render("help"), helpSectionStyle.Render("(scroll with j/k/↓/↑)"))
if !m.helpVPReady {
content = helpViewStyle.Render("Initializing...")
content = "Initializing..."
} else {
content = header + helpViewStyle.Render(m.helpVP.View())
content = header + m.helpVP.View()
}
}

Expand Down

0 comments on commit d501179

Please sign in to comment.