summaryrefslogtreecommitdiffhomepage
path: root/internal/tui/styles
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-12 02:01:45 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 13:38:42 +0200
commit8d874b839db169906e18e4277cd198504018e022 (patch)
tree658a1adbee42a0ca2249252827fb37f7469f3667 /internal/tui/styles
parent08bd75bb6e1fde0427dfd37204ee9a3c43bb1e5b (diff)
downloadopencode-8d874b839db169906e18e4277cd198504018e022.tar.gz
opencode-8d874b839db169906e18e4277cd198504018e022.zip
add initial message handling
Diffstat (limited to 'internal/tui/styles')
-rw-r--r--internal/tui/styles/markdown.go446
1 files changed, 444 insertions, 2 deletions
diff --git a/internal/tui/styles/markdown.go b/internal/tui/styles/markdown.go
index 77dc314f5..b4e71c51e 100644
--- a/internal/tui/styles/markdown.go
+++ b/internal/tui/styles/markdown.go
@@ -36,12 +36,13 @@ var catppuccinDark = ansi.StyleConfig{
Italic: boolPtr(true),
Prefix: "┃ ",
},
- Indent: uintPtr(1),
- Margin: uintPtr(defaultMargin),
+ Indent: uintPtr(1),
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
},
List: ansi.StyleList{
LevelIndent: defaultMargin,
StyleBlock: ansi.StyleBlock{
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
StylePrimitive: ansi.StylePrimitive{
Color: stringPtr(dark.Text().Hex),
},
@@ -496,3 +497,444 @@ var catppuccinLight = ansi.StyleConfig{
Color: stringPtr(light.Sapphire().Hex),
},
}
+
+func MarkdownTheme(focused bool) ansi.StyleConfig {
+ if !focused {
+ return ASCIIStyleConfig
+ } else {
+ return DraculaStyleConfig
+ }
+}
+
+const (
+ defaultListIndent = 2
+ defaultListLevelIndent = 4
+)
+
+var ASCIIStyleConfig = ansi.StyleConfig{
+ Document: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Indent: uintPtr(1),
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
+ },
+ BlockQuote: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Indent: uintPtr(1),
+ IndentToken: stringPtr("| "),
+ },
+ Paragraph: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ List: ansi.StyleList{
+ StyleBlock: ansi.StyleBlock{
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ LevelIndent: defaultListLevelIndent,
+ },
+ Heading: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ BlockSuffix: "\n",
+ },
+ },
+ H1: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ Prefix: "# ",
+ },
+ },
+ H2: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ Prefix: "## ",
+ },
+ },
+ H3: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ Prefix: "### ",
+ },
+ },
+ H4: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ Prefix: "#### ",
+ },
+ },
+ H5: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ Prefix: "##### ",
+ },
+ },
+ H6: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ Prefix: "###### ",
+ },
+ },
+ Strikethrough: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ BlockPrefix: "~~",
+ BlockSuffix: "~~",
+ },
+ Emph: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ BlockPrefix: "*",
+ BlockSuffix: "*",
+ },
+ Strong: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ BlockPrefix: "**",
+ BlockSuffix: "**",
+ },
+ HorizontalRule: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ Format: "\n--------\n",
+ },
+ Item: ansi.StylePrimitive{
+ BlockPrefix: "• ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Enumeration: ansi.StylePrimitive{
+ BlockPrefix: ". ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Task: ansi.StyleTask{
+ Ticked: "[x] ",
+ Unticked: "[ ] ",
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ ImageText: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ Format: "Image: {{.text}} →",
+ },
+ Code: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BlockPrefix: "`",
+ BlockSuffix: "`",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ CodeBlock: ansi.StyleCodeBlock{
+ StyleBlock: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Margin: uintPtr(defaultMargin),
+ },
+ },
+ Table: ansi.StyleTable{
+ StyleBlock: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
+ },
+ CenterSeparator: stringPtr("|"),
+ ColumnSeparator: stringPtr("|"),
+ RowSeparator: stringPtr("-"),
+ },
+ DefinitionDescription: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ BlockPrefix: "\n* ",
+ },
+}
+
+var DraculaStyleConfig = ansi.StyleConfig{
+ Document: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Color: stringPtr(Forground.Dark),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Indent: uintPtr(defaultMargin),
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
+ },
+ BlockQuote: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Color: stringPtr("#f1fa8c"),
+ Italic: boolPtr(true),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Indent: uintPtr(defaultMargin),
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
+ },
+ Paragraph: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ List: ansi.StyleList{
+ LevelIndent: defaultMargin,
+ StyleBlock: ansi.StyleBlock{
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
+ StylePrimitive: ansi.StylePrimitive{
+ Color: stringPtr(Forground.Dark),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ },
+ Heading: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BlockSuffix: "\n",
+ Color: stringPtr("#bd93f9"),
+ Bold: boolPtr(true),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ H1: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Prefix: "# ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ H2: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Prefix: "## ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ H3: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Prefix: "### ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ H4: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Prefix: "#### ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ H5: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Prefix: "##### ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ H6: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Prefix: "###### ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ Strikethrough: ansi.StylePrimitive{
+ CrossedOut: boolPtr(true),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Emph: ansi.StylePrimitive{
+ Color: stringPtr("#f1fa8c"),
+ Italic: boolPtr(true),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Strong: ansi.StylePrimitive{
+ Bold: boolPtr(true),
+ Color: stringPtr("#ffb86c"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ HorizontalRule: ansi.StylePrimitive{
+ Color: stringPtr("#6272A4"),
+ Format: "\n--------\n",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Item: ansi.StylePrimitive{
+ BlockPrefix: "• ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Enumeration: ansi.StylePrimitive{
+ BlockPrefix: ". ",
+ Color: stringPtr("#8be9fd"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Task: ansi.StyleTask{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Ticked: "[✓] ",
+ Unticked: "[ ] ",
+ },
+ Link: ansi.StylePrimitive{
+ Color: stringPtr("#8be9fd"),
+ Underline: boolPtr(true),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ LinkText: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Image: ansi.StylePrimitive{
+ Color: stringPtr("#8be9fd"),
+ Underline: boolPtr(true),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ ImageText: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ Format: "Image: {{.text}} →",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Code: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Color: stringPtr("#50fa7b"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ Text: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ DefinitionList: ansi.StyleBlock{},
+ CodeBlock: ansi.StyleCodeBlock{
+ StyleBlock: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ Color: stringPtr("#ffb86c"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Margin: uintPtr(defaultMargin),
+ },
+ Chroma: &ansi.Chroma{
+ NameOther: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Literal: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ NameException: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ LiteralDate: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Text: ansi.StylePrimitive{
+ Color: stringPtr(Forground.Dark),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Error: ansi.StylePrimitive{
+ Color: stringPtr("#f8f8f2"),
+ BackgroundColor: stringPtr("#ff5555"),
+ },
+ Comment: ansi.StylePrimitive{
+ Color: stringPtr("#6272A4"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ CommentPreproc: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Keyword: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ KeywordReserved: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ KeywordNamespace: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ KeywordType: ansi.StylePrimitive{
+ Color: stringPtr("#8be9fd"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Operator: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Punctuation: ansi.StylePrimitive{
+ Color: stringPtr(Forground.Dark),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Name: ansi.StylePrimitive{
+ Color: stringPtr("#8be9fd"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ NameBuiltin: ansi.StylePrimitive{
+ Color: stringPtr("#8be9fd"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ NameTag: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ NameAttribute: ansi.StylePrimitive{
+ Color: stringPtr("#50fa7b"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ NameClass: ansi.StylePrimitive{
+ Color: stringPtr("#8be9fd"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ NameConstant: ansi.StylePrimitive{
+ Color: stringPtr("#bd93f9"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ NameDecorator: ansi.StylePrimitive{
+ Color: stringPtr("#50fa7b"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ NameFunction: ansi.StylePrimitive{
+ Color: stringPtr("#50fa7b"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ LiteralNumber: ansi.StylePrimitive{
+ Color: stringPtr("#6EEFC0"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ LiteralString: ansi.StylePrimitive{
+ Color: stringPtr("#f1fa8c"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ LiteralStringEscape: ansi.StylePrimitive{
+ Color: stringPtr("#ff79c6"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ GenericDeleted: ansi.StylePrimitive{
+ Color: stringPtr("#ff5555"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ GenericEmph: ansi.StylePrimitive{
+ Color: stringPtr("#f1fa8c"),
+ Italic: boolPtr(true),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ GenericInserted: ansi.StylePrimitive{
+ Color: stringPtr("#50fa7b"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ GenericStrong: ansi.StylePrimitive{
+ Color: stringPtr("#ffb86c"),
+ Bold: boolPtr(true),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ GenericSubheading: ansi.StylePrimitive{
+ Color: stringPtr("#bd93f9"),
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ Background: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ },
+ },
+ Table: ansi.StyleTable{
+ StyleBlock: ansi.StyleBlock{
+ StylePrimitive: ansi.StylePrimitive{
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+ IndentToken: stringPtr(BaseStyle.Render(" ")),
+ },
+ },
+ DefinitionDescription: ansi.StylePrimitive{
+ BlockPrefix: "\n* ",
+ BackgroundColor: stringPtr(Background.Dark),
+ },
+}