caret

[ACTIVE] a command line tool for browsing Lobsters in your terminal
git clone git://git.figbert.com/caret.git
Log | Files | Refs | README | LICENSE

glamour.go (5284B)


      1 package ui
      2 
      3 import (
      4 	"strings"
      5 
      6 	"github.com/charmbracelet/glamour/ansi"
      7 	gloss "github.com/charmbracelet/lipgloss"
      8 )
      9 
     10 const block = "█"
     11 
     12 var GlamourConfig = ansi.StyleConfig{
     13 	Document: ansi.StyleBlock{
     14 		StylePrimitive: ansi.StylePrimitive{
     15 			BlockPrefix: "\n",
     16 			BlockSuffix: "\n",
     17 		},
     18 	},
     19 	BlockQuote: ansi.StyleBlock{
     20 		StylePrimitive: ansi.StylePrimitive{Color: stringPtr("244")},
     21 		Indent:         uintPtr(1),
     22 		IndentToken:    stringPtr("│ "),
     23 	},
     24 	List: ansi.StyleList{
     25 		LevelIndent: 2,
     26 	},
     27 	Heading: ansi.StyleBlock{
     28 		StylePrimitive: ansi.StylePrimitive{
     29 			BlockSuffix: "\n",
     30 			Bold:        boolPtr(true),
     31 		},
     32 	},
     33 	H1: ansi.StyleBlock{
     34 		StylePrimitive: ansi.StylePrimitive{
     35 			Prefix: gloss.NewStyle().Foreground(gloss.Color("15")).Render(block) + " ",
     36 		},
     37 	},
     38 	H2: ansi.StyleBlock{
     39 		StylePrimitive: ansi.StylePrimitive{
     40 			Prefix: gloss.NewStyle().Foreground(gloss.Color("12")).Render(block) + " ",
     41 		},
     42 	},
     43 	H3: ansi.StyleBlock{
     44 		StylePrimitive: ansi.StylePrimitive{
     45 			Prefix: gloss.NewStyle().Foreground(gloss.Color("9")).Render(strings.Repeat(block, 2)) + " ",
     46 		},
     47 	},
     48 	H4: ansi.StyleBlock{
     49 		StylePrimitive: ansi.StylePrimitive{
     50 			Prefix: gloss.NewStyle().Foreground(gloss.Color("13")).Render(strings.Repeat(block, 3)) + " ",
     51 		},
     52 	},
     53 	H5: ansi.StyleBlock{
     54 		StylePrimitive: ansi.StylePrimitive{
     55 			Prefix: gloss.NewStyle().Foreground(gloss.Color("11")).Render(strings.Repeat(block, 4)) + " ",
     56 		},
     57 	},
     58 	H6: ansi.StyleBlock{
     59 		StylePrimitive: ansi.StylePrimitive{
     60 			Prefix: gloss.NewStyle().Foreground(gloss.Color("10")).Render(strings.Repeat(block, 5)) + " ",
     61 		},
     62 	},
     63 	Strikethrough: ansi.StylePrimitive{
     64 		CrossedOut: boolPtr(true),
     65 	},
     66 	Emph: ansi.StylePrimitive{
     67 		Italic: boolPtr(true),
     68 	},
     69 	Strong: ansi.StylePrimitive{
     70 		Bold: boolPtr(true),
     71 	},
     72 	HorizontalRule: ansi.StylePrimitive{
     73 		Color:  stringPtr("240"),
     74 		Format: "\n--------\n",
     75 	},
     76 	Item: ansi.StylePrimitive{
     77 		BlockPrefix: "• ",
     78 	},
     79 	Enumeration: ansi.StylePrimitive{
     80 		BlockPrefix: ". ",
     81 	},
     82 	Task: ansi.StyleTask{
     83 		StylePrimitive: ansi.StylePrimitive{},
     84 		Ticked:         "[✓] ",
     85 		Unticked:       "[ ] ",
     86 	},
     87 	Link:     ansi.StylePrimitive{Color: stringPtr("#7d0e09")},
     88 	LinkText: ansi.StylePrimitive{Bold: boolPtr(true)},
     89 	Image: ansi.StylePrimitive{
     90 		Color:     stringPtr("245"),
     91 		Underline: boolPtr(true),
     92 	},
     93 	ImageText: ansi.StylePrimitive{
     94 		Color:  stringPtr("88"),
     95 		Format: "Image: {{.text}} →",
     96 	},
     97 	Code: ansi.StyleBlock{
     98 		StylePrimitive: ansi.StylePrimitive{
     99 			Color:  stringPtr("1"),
    100 			Italic: boolPtr(true),
    101 		},
    102 	},
    103 	CodeBlock: ansi.StyleCodeBlock{
    104 		StyleBlock: ansi.StyleBlock{
    105 			StylePrimitive: ansi.StylePrimitive{
    106 				Color: stringPtr("244"),
    107 			},
    108 			Margin: uintPtr(2),
    109 		},
    110 		Chroma: &ansi.Chroma{
    111 			Text: ansi.StylePrimitive{
    112 				Color: stringPtr("#C4C4C4"),
    113 			},
    114 			Error: ansi.StylePrimitive{
    115 				Color:           stringPtr("#F1F1F1"),
    116 				BackgroundColor: stringPtr("#F05B5B"),
    117 			},
    118 			Comment: ansi.StylePrimitive{
    119 				Color: stringPtr("#676767"),
    120 			},
    121 			CommentPreproc: ansi.StylePrimitive{
    122 				Color: stringPtr("#FF875F"),
    123 			},
    124 			Keyword: ansi.StylePrimitive{
    125 				Color: stringPtr("#00AAFF"),
    126 			},
    127 			KeywordReserved: ansi.StylePrimitive{
    128 				Color: stringPtr("#FF5FD2"),
    129 			},
    130 			KeywordNamespace: ansi.StylePrimitive{
    131 				Color: stringPtr("#FF5F87"),
    132 			},
    133 			KeywordType: ansi.StylePrimitive{
    134 				Color: stringPtr("#6E6ED8"),
    135 			},
    136 			Operator: ansi.StylePrimitive{
    137 				Color: stringPtr("#EF8080"),
    138 			},
    139 			Punctuation: ansi.StylePrimitive{
    140 				Color: stringPtr("#E8E8A8"),
    141 			},
    142 			Name: ansi.StylePrimitive{
    143 				Color: stringPtr("#C4C4C4"),
    144 			},
    145 			NameBuiltin: ansi.StylePrimitive{
    146 				Color: stringPtr("#FF8EC7"),
    147 			},
    148 			NameTag: ansi.StylePrimitive{
    149 				Color: stringPtr("#B083EA"),
    150 			},
    151 			NameAttribute: ansi.StylePrimitive{
    152 				Color: stringPtr("#7A7AE6"),
    153 			},
    154 			NameClass: ansi.StylePrimitive{
    155 				Color:     stringPtr("#F1F1F1"),
    156 				Underline: boolPtr(true),
    157 				Bold:      boolPtr(true),
    158 			},
    159 			NameDecorator: ansi.StylePrimitive{
    160 				Color: stringPtr("#FFFF87"),
    161 			},
    162 			NameFunction: ansi.StylePrimitive{
    163 				Color: stringPtr("#00D787"),
    164 			},
    165 			LiteralNumber: ansi.StylePrimitive{
    166 				Color: stringPtr("#6EEFC0"),
    167 			},
    168 			LiteralString: ansi.StylePrimitive{
    169 				Color: stringPtr("#C69669"),
    170 			},
    171 			LiteralStringEscape: ansi.StylePrimitive{
    172 				Color: stringPtr("#AFFFD7"),
    173 			},
    174 			GenericDeleted: ansi.StylePrimitive{
    175 				Color: stringPtr("#FD5B5B"),
    176 			},
    177 			GenericEmph: ansi.StylePrimitive{
    178 				Italic: boolPtr(true),
    179 			},
    180 			GenericInserted: ansi.StylePrimitive{
    181 				Color: stringPtr("#00D787"),
    182 			},
    183 			GenericStrong: ansi.StylePrimitive{
    184 				Bold: boolPtr(true),
    185 			},
    186 			GenericSubheading: ansi.StylePrimitive{
    187 				Color: stringPtr("#777777"),
    188 			},
    189 			Background: ansi.StylePrimitive{
    190 				BackgroundColor: stringPtr("#373737"),
    191 			},
    192 		},
    193 	},
    194 	Table: ansi.StyleTable{
    195 		StyleBlock: ansi.StyleBlock{
    196 			StylePrimitive: ansi.StylePrimitive{},
    197 		},
    198 		CenterSeparator: stringPtr("┼"),
    199 		ColumnSeparator: stringPtr("│"),
    200 		RowSeparator:    stringPtr("─"),
    201 	},
    202 	DefinitionDescription: ansi.StylePrimitive{
    203 		BlockPrefix: "\n🠶 ",
    204 	},
    205 }
    206 
    207 func boolPtr(b bool) *bool       { return &b }
    208 func stringPtr(s string) *string { return &s }
    209 func uintPtr(u uint) *uint       { return &u }