-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac8231e
commit bc8e4c0
Showing
6 changed files
with
647 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module examples | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
replace github.com/charmbracelet/lipgloss => ../ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
const ( | ||
purple = lipgloss.Color("99") | ||
gray = lipgloss.Color("245") | ||
lightGray = lipgloss.Color("241") | ||
) | ||
|
||
var ( | ||
// HeaderStyle is the lipgloss style used for the table headers. | ||
HeaderStyle = lipgloss.NewStyle().Foreground(purple).Bold(true).Align(lipgloss.Center) | ||
// RowStyle is the base lipgloss style used for the table rows. | ||
RowStyle = lipgloss.NewStyle().Padding(1) | ||
// OddRowStyle is the lipgloss style used for odd-numbered table rows. | ||
OddRowStyle = RowStyle.Copy().Foreground(gray) | ||
// EvenRowStyle is the lipgloss style used for even-numbered table rows. | ||
EvenRowStyle = RowStyle.Copy().Foreground(lightGray) | ||
) | ||
|
||
func main() { | ||
t := lipgloss.NewTable(). | ||
Border(lipgloss.NormalBorder()). | ||
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("99"))). | ||
StyleFunc(func(row, col int) lipgloss.Style { | ||
switch { | ||
case row == 0: | ||
return HeaderStyle | ||
case row%2 == 0: | ||
return EvenRowStyle | ||
default: | ||
return OddRowStyle | ||
} | ||
}). | ||
Headers("LANGUAGE", "FORMAL", "INFORMAL"). | ||
Row("Chinese", "Nǐn hǎo", "Nǐ hǎo"). | ||
Row("French", "Bonjour", "Salut"). | ||
Row("Japanese", "こんにちは", "やあ"). | ||
Row("Russian", "Zdravstvuyte", "Privet"). | ||
Row("Spanish", "Hola", "¿Qué tal?") | ||
|
||
fmt.Println(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.