markup

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package markup defines styles and colors used to print messages on the shell as if they were HTML tags.

Index

Constants

This section is empty.

Variables

View Source
var (
	// H1 is used to style an heading 1, as the HTML <h1> tag.
	H1 = lipgloss.NewStyle().
		Margin(1, 0).
		BorderBottom(true).
		BorderForeground(purple).
		BorderStyle(lipgloss.ThickBorder()).Render

	// H2 is used to style an heading 2, as the HTML <h2> tag.
	H2 = lipgloss.NewStyle().
		MarginTop(1).
		Italic(true).
		BorderBottom(true).
		BorderStyle(lipgloss.NormalBorder()).
		Render

	// P is used to style a paragraph, as the HTML <p> tag.
	P = lipgloss.NewStyle().Render

	// A is used to style a link, as the HTML <a> tag.
	A = lipgloss.NewStyle().Foreground(green).Render

	// BR is used to prints a line breaks, as the HTML <br> tag.
	BR = lipgloss.NewStyle().Render("")

	// HR is used to style a horizontal rule, as the HTML <hr> tag.
	HR = func(width int) string {
		return lipgloss.NewStyle().
			MarginTop(1).
			BorderBottom(true).
			BorderStyle(lipgloss.NormalBorder()).
			Render(strings.Repeat(" ", width))
	}

	// Section is used to style a content section, as the HTML <section> tag.
	Section = func(title string, content []string) string {
		return lipgloss.NewStyle().Margin(1, 0).Render(
			lipgloss.JoinVertical(lipgloss.Left,
				H2(title),
				P(strings.Join(content, "\n")),
			))
	}

	// Code is used to style a code line.
	Code = func(content string) string {
		return lipgloss.NewStyle().Margin(0, 0, 0, 0).Render(
			codeBlockContentStyle(content),
		)
	}

	// CodeBlock is used to style a block of code <block><code>...</code></block>
	CodeBlock = func(strs ...string) string {
		return lipgloss.NewStyle().Margin(0, 0, 1, 0).Render(
			lipgloss.JoinVertical(lipgloss.Left, codeBlockContentStyle(strings.Join(strs, "\n"))),
		)
	}
	// UL is used to style an unordered list, as the HTML <ul> tag.
	UL = lipgloss.NewStyle().Margin(1, 0, 1, 1)

	// OL is used to style an ordered list, as the HTML <ol> tag.
	OL = lipgloss.NewStyle().Margin(1, 0, 0, 1)

	// LI is used to style a list item, as the HTML <li> tag..
	LI = lipgloss.NewStyle().Render
)
View Source
var (
	// Plain sets an as it is formatting rule for the text.
	Plain = lipgloss.NewStyle().Foreground(nocolor).Render
	// Italic sets an italic formatting rule for the text.
	Italic = lipgloss.NewStyle().Italic(true).Render
	// Bold sets a bold formatting rule for the text.
	Bold = lipgloss.NewStyle().Bold(true).Render
	//Underline sets an underlined rule for the text.
	Underline = lipgloss.NewStyle().Underline(true).Render
	// Gray sets foreground color to gray for the text.
	Gray = lipgloss.NewStyle().Foreground(gray).Render
	// Faint sets a rule for rendering the foreground color in a dimmer shade.
	Faint = lipgloss.NewStyle().Faint(true).Render

	// Green renders text in green
	Green = lipgloss.NewStyle().Foreground(green).Render
	// Amber renders text in amber
	Amber = lipgloss.NewStyle().Foreground(amber).Render
	// Yellow renders text in yellow
	Yellow = lipgloss.NewStyle().Foreground(yellow).Render
	// Purple renders text in purple
	Purple = lipgloss.NewStyle().Foreground(purple).Render
	// Blue renders text in blue
	Blue = lipgloss.NewStyle().Foreground(blue).Render

	// Bordered prints a bordered text.
	Bordered = lipgloss.NewStyle().
				Margin(1).
				Padding(1, 2).
				Border(lipgloss.RoundedBorder(), true, true, true, true).
				BorderForeground(lipgloss.Color("#874BFD")).
				Render
	// Centered prints a center aligned text
	Centered = lipgloss.NewStyle().Align(lipgloss.Center).Render
)
View Source
var (

	// CheckMark is used to print a checkmark char.
	CheckMark = lipgloss.NewStyle().SetString("✓").
				Foreground(green).
				PaddingRight(1).
				String()

	// Divider prints a dot char.
	Divider = lipgloss.NewStyle().
			SetString("•").
			Padding(0, 1).
			Faint(true).
			String()

	// Inline is used to style strings horizontally joined along their center.
	Inline = func(strs ...string) string {
		return lipgloss.NewStyle().Render(lipgloss.JoinHorizontal(lipgloss.Center, strings.Join(strs, " ")))
	}
	// LIWithIcon is used to style a list item with a check mark as prefix.
	LIWithIcon = func(s, v, icon string) string {
		return icon + lipgloss.NewStyle().
			Foreground(gray).
			Render(s) + Bold(v)
	}

	// NewUL is an utility function to help creating a new unordered list.
	NewUL = func(entries []string) string {
		return UL.Render(
			lipgloss.JoinVertical(lipgloss.Left,
				strings.Join(entries, "\n")))
	}

	// NewULWithIconPrefix is an utility function to help creating a new unordered list with an icon as prefix to the list items.
	NewULWithIconPrefix = func(title string, entries map[string]string, icon string) string {
		items := []string{}
		for k, v := range entries {
			items = append(items, LIWithIcon(k, v, icon))
		}

		return UL.Render(
			lipgloss.JoinVertical(lipgloss.Left,
				listTitle(title), strings.Join(items, "\n")))
	}

	// NewOL is an utility function to help creating a new ordered list.
	NewOL = func(entries []string) string {
		items := []string{}
		for k, v := range entries {
			items = append(items, LI(fmt.Sprintf("%d. %s", k+1, v)))
		}

		return OL.Render(
			lipgloss.JoinVertical(lipgloss.Left,
				strings.Join(items, "\n")))
	}

	// NewOLWithTitle is an utility function to help creating a new ordered list with a title text.
	NewOLWithTitle = func(title string, entries []string) string {
		return OL.Render(
			lipgloss.JoinVertical(lipgloss.Left,
				listTitle(title), NewOL(entries)))
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL