diff --git a/examples/hyperlink/main.go b/examples/hyperlink/main.go new file mode 100644 index 00000000..46208576 --- /dev/null +++ b/examples/hyperlink/main.go @@ -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), + ), + ) +} diff --git a/examples/layout/main.go b/examples/layout/main.go index e3281c6b..ed21c88a 100644 --- a/examples/layout/main.go +++ b/examples/layout/main.go @@ -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{ @@ -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) @@ -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(