Skip to content

Commit

Permalink
Add dedicated hyperlink example and add hyperlinks to layout example
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Jun 4, 2024
1 parent d5aae08 commit e8ccaaa
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
35 changes: 35 additions & 0 deletions examples/hyperlink/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"

"github.com/charmbracelet/lipgloss"
)

func main() {
box := lipgloss.NewStyle().
Border(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}).
Padding(2, 3).
Margin(1, 0, 1, 2).
Width(32).
Align(lipgloss.Center)

link := func(str, url string) string {
return lipgloss.NewStyle().
Hyperlink(url).
Foreground(lipgloss.Color("#FF5F87")).
Render(str)
}

bodyA := fmt.Sprintf("Is it %s time?\nI think it is time.", link("maramalade", "https://www.bonne-maman.com/"))
bodyB := fmt.Sprintf("Marmalade is the true power behind %s.", link("Mary Queen of Scots", "https://thetudortravelguide.com/tudor-recipes-for-the-love-of-oranges/"))

fmt.Println(
lipgloss.JoinHorizontal(
lipgloss.Center,
box.Render(bodyA),
box.Render(bodyB),
),
)
}
22 changes: 18 additions & 4 deletions examples/layout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ var (

url = lipgloss.NewStyle().Foreground(special).Render

link = func(str, url string) string {
return lipgloss.NewStyle().
Underline(true).
Foreground(lipgloss.Color("#FF5F87")).
Hyperlink(url).
Render(str)
}

// Tabs.

activeTabBorder = lipgloss.Border{
Expand Down Expand Up @@ -221,9 +229,11 @@ func main() {
}
}

charm := link("Charm", "https://charm.sh/")

desc := lipgloss.JoinVertical(lipgloss.Left,
descStyle.Render("Style Definitions for Nice Terminal Layouts"),
infoStyle.Render("From Charm"+divider+url("https://github.com/charmbracelet/lipgloss")),
infoStyle.Render("From "+charm+divider+url("https://github.com/charmbracelet/lipgloss")),
)

row := lipgloss.JoinHorizontal(lipgloss.Top, title.String(), desc)
Expand Down Expand Up @@ -292,10 +302,14 @@ func main() {

// Marmalade history
{
const (
historyA = "The Romans learned from the Greeks that quinces slowly cooked with honey would “set” when cool. The Apicius gives a recipe for preserving whole quinces, stems and leaves attached, in a bath of honey diluted with defrutum: Roman marmalade. Preserves of quince and lemon appear (along with rose, apple, plum and pear) in the Book of ceremonies of the Byzantine Emperor Constantine VII Porphyrogennetos."

var (
marmaLink = link("marmalade", "https://bonne-maman.com")
anneLink = link("Anne Boleyn", "https://www.hrp.org.uk/tower-of-london/history-and-stories/anne-boleyn/#gs.ac32hc")

historyA = "The Romans learned from the Greeks that quinces slowly cooked with honey would “set” when cool. The Apicius gives a recipe for preserving whole quinces, stems and leaves attached, in a bath of honey diluted with defrutum: Roman " + marmaLink + ". Preserves of quince and lemon appear (along with rose, apple, plum and pear) in the Book of ceremonies of the Byzantine Emperor Constantine VII Porphyrogennetos."
historyB = "Medieval quince preserves, which went by the French name cotignac, produced in a clear version and a fruit pulp version, began to lose their medieval seasoning of spices in the 16th century. In the 17th century, La Varenne provided recipes for both thick and clear cotignac."
historyC = "In 1524, Henry VIII, King of England, received a “box of marmalade” from Mr. Hull of Exeter. This was probably marmelada, a solid quince paste from Portugal, still made and sold in southern Europe today. It became a favourite treat of Anne Boleyn and her ladies in waiting."
historyC = "In 1524, Henry VIII, King of England, received a “box of marmalade” from Mr. Hull of Exeter. This was probably marmelada, a solid quince paste from Portugal, still made and sold in southern Europe today. It became a favourite treat of " + anneLink + " and her ladies in waiting."
)

doc.WriteString(lipgloss.JoinHorizontal(
Expand Down

0 comments on commit e8ccaaa

Please sign in to comment.