From 87f3c26e471b9ebe69a732a745c60d75f6ee0701 Mon Sep 17 00:00:00 2001 From: Dhruv Thakur Date: Thu, 25 Jul 2024 00:20:14 +0200 Subject: [PATCH] refactor: use gruvbox for md rendering --- cmd/guide_test.go | 2 +- internal/ui/assets/gruvbox.json | 205 ++++++++++++++++++++++++++++++++ internal/ui/assets/help.md | 2 +- internal/ui/list_delegate.go | 2 +- internal/ui/markdown.go | 19 ++- internal/ui/markdown_test.go | 24 ++++ internal/ui/styles.go | 4 +- internal/ui/view.go | 2 +- 8 files changed, 243 insertions(+), 17 deletions(-) create mode 100644 internal/ui/assets/gruvbox.json create mode 100644 internal/ui/markdown_test.go diff --git a/cmd/guide_test.go b/cmd/guide_test.go index d85845b..2136c62 100644 --- a/cmd/guide_test.go +++ b/cmd/guide_test.go @@ -9,7 +9,7 @@ import ( func TestGetContext(t *testing.T) { for _, entry := range guideEntries { got, err := getContext(entry.summary) - assert.Nil(t, err) + assert.NoError(t, err) assert.NotEmpty(t, got) } } diff --git a/internal/ui/assets/gruvbox.json b/internal/ui/assets/gruvbox.json new file mode 100644 index 0000000..ea28361 --- /dev/null +++ b/internal/ui/assets/gruvbox.json @@ -0,0 +1,205 @@ +{ + "document": { + "block_prefix": "", + "block_suffix": "", + "color": "#fbf1c7", + "margin": 2 + }, + "block_quote": { + "indent": 1, + "indent_token": "│ " + }, + "paragraph": {}, + "list": { + "level_indent": 2 + }, + "heading": { + "block_suffix": "\n", + "color": "#fe8019", + "bold": true + }, + "h1": { + "prefix": "# ", + "suffix": "", + "color": "#fe8019", + "bold": true + }, + "h2": { + "prefix": "## ", + "color": "#83a598" + }, + "h3": { + "prefix": "### ", + "color": "#83a598" + }, + "h4": { + "prefix": "#### ", + "color": "#83a598" + }, + "h5": { + "prefix": "", + "color": "#fabd2f" + }, + "h6": { + "prefix": "", + "color": "#8ec07c", + "bold": false + }, + "text": {}, + "strikethrough": { + "crossed_out": true + }, + "emph": { + "italic": true, + "color": "#83a598" + }, + "strong": { + "bold": true, + "color": "#fe8019" + }, + "hr": { + "color": "#928374", + "format": "\n--------\n" + }, + "item": { + "block_prefix": "• " + }, + "enumeration": { + "block_prefix": ". " + }, + "task": { + "ticked": "[✓] ", + "unticked": "[ ] " + }, + "link": { + "color": "#83a598", + "underline": true + }, + "link_text": { + "color": "#458588", + "bold": true + }, + "image": { + "color": "132", + "underline": true + }, + "image_text": { + "color": "245", + "format": "Image: {{.text}} →" + }, + "code": { + "prefix": " ", + "suffix": " ", + "color": "#b8bb26", + "background_color": "#3c3836" + }, + "code_block": { + "color": "244", + "margin": 2, + "chroma": { + "text": { + "color": "#bdae93" + }, + "error": { + "color": "#282828", + "background_color": "#fb4934" + }, + "comment": { + "color": "#928374" + }, + "comment_preproc": { + "color": "#8ec07c" + }, + "keyword": { + "color": "#fe8019" + }, + "keyword_reserved": { + "color": "#8ec07c" + }, + "keyword_namespace": { + "color": "#d3869b" + }, + "keyword_type": { + "color": "#fabd2f" + }, + "operator": { + "color": "#fe8019" + }, + "punctuation": { + "color": "#928374" + }, + "name": { + "color": "#ebdbb2" + }, + "name_builtin": { + "color": "#fabd2f" + }, + "name_tag": { + "color": "#fb4934" + }, + "name_attribute": { + "color": "#b8bb26" + }, + "name_class": { + "color": "#fe8019", + "bold": true + }, + "name_constant": {}, + "name_decorator": { + "color": "#d3869b" + }, + "name_exception": { + "color": "#fb4934" + }, + "name_function": { + "color": "#fabd2f" + }, + "name_other": {}, + "literal": {}, + "literal_number": { + "color": "#fabd2f" + }, + "literal_date": {}, + "literal_string": { + "color": "#b8bb26" + }, + "literal_string_escape": { + "color": "#83a598" + }, + "generic_deleted": { + "color": "#fb4934", + "background_color": "#282828" + }, + "generic_emph": { + "italic": true, + "color": "#83a598" + }, + "generic_inserted": { + "color": "#b8bb26", + "background_color": "#282828" + }, + "generic_strong": { + "bold": true, + "color": "#ebdbb2" + }, + "generic_subheading": { + "color": "#b8bb26" + }, + "background": { + "background_color": "#3c3836" + } + } + }, + "table": { + "center_separator": "┼", + "column_separator": "│", + "row_separator": "─" + }, + "definition_list": {}, + "definition_term": {}, + "definition_description": { + "block_prefix": "\n🠶 " + }, + "html_block": {}, + "html_span": {} +} diff --git a/internal/ui/assets/help.md b/internal/ui/assets/help.md index f1e6ef9..45bd4d5 100644 --- a/internal/ui/assets/help.md +++ b/internal/ui/assets/help.md @@ -1,6 +1,6 @@ ## Overview -**omm** ("on-my-mind") is a keyboard-driven task manager for the command line. +omm ("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. diff --git a/internal/ui/list_delegate.go b/internal/ui/list_delegate.go index 9e12088..54ad1a1 100644 --- a/internal/ui/list_delegate.go +++ b/internal/ui/list_delegate.go @@ -13,7 +13,7 @@ func newListDelegate(color lipgloss.Color, showDesc bool, spacing int) list.Defa d.Styles.NormalTitle = d.Styles. NormalTitle. - Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#ffffff"}) + Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#fbf1c7"}) d.Styles.SelectedTitle = d.Styles. SelectedTitle. diff --git a/internal/ui/markdown.go b/internal/ui/markdown.go index 748a46c..74fab09 100644 --- a/internal/ui/markdown.go +++ b/internal/ui/markdown.go @@ -1,24 +1,21 @@ package ui import ( + _ "embed" + "github.com/charmbracelet/glamour" "github.com/muesli/termenv" ) -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 +var ( + //go:embed assets/gruvbox.json + glamourJsonBytes []byte +) +func getMarkDownRenderer(wrap int) (*glamour.TermRenderer, error) { return glamour.NewTermRenderer( + glamour.WithStylesFromJSONBytes(glamourJsonBytes), glamour.WithColorProfile(termenv.TrueColor), - glamour.WithStyles(dracula), glamour.WithWordWrap(wrap), ) } diff --git a/internal/ui/markdown_test.go b/internal/ui/markdown_test.go new file mode 100644 index 0000000..ccb9703 --- /dev/null +++ b/internal/ui/markdown_test.go @@ -0,0 +1,24 @@ +package ui + +import ( + "encoding/json" + "testing" + + "github.com/charmbracelet/glamour" + "github.com/stretchr/testify/assert" +) + +func TestGetGlamourStyleFromFile(t *testing.T) { + gotOption := glamour.WithStylesFromJSONBytes(glamourJsonBytes) + renderer, err := glamour.NewTermRenderer(gotOption) + assert.NoError(t, err) + assert.NotNil(t, renderer) + + _, err = renderer.Render("a") + assert.NoError(t, err) +} + +func TestGlamourStylesFileIsValid(t *testing.T) { + got := json.Valid(glamourJsonBytes) + assert.True(t, got) +} diff --git a/internal/ui/styles.go b/internal/ui/styles.go index 8295fa7..84e7f64 100644 --- a/internal/ui/styles.go +++ b/internal/ui/styles.go @@ -12,13 +12,13 @@ const ( prefixSearchColor = "#d3896b" contextTitleColor = "#8ec07c" taskEntryTitleColor = "#b8bb26" - taskDetailsTitleColor = "#bd93f9" + taskDetailsTitleColor = "#d3869b" taskListHeaderColor = "#928374" formHelpColor = "#928374" formColor = "#928374" helpMsgColor = "#928374" helpViewTitleColor = "#83a598" - helpTitleColor = "#bd93f9" + helpTitleColor = "#83a598" sBSuccessMsgColor = "#d3869b" sBErrMsgColor = "#fb4934" footerColor = "#928374" diff --git a/internal/ui/view.go b/internal/ui/view.go index 3f6641b..54b569b 100644 --- a/internal/ui/view.go +++ b/internal/ui/view.go @@ -9,7 +9,7 @@ import ( var ( TaskListDefaultTitle = "omm" - taskDetailsWordWrap = 80 + taskDetailsWordWrap = 120 contextWordWrapUpperLimit = 160 )