File size: 1,771 Bytes
8eb2cb0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
package server
import (
"fmt"
"io"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/jkuri/bore/internal/version"
)
const (
black = lipgloss.Color("0")
lightGreen = lipgloss.Color("10")
lightBlue = lipgloss.Color("12")
gray = lipgloss.Color("245")
lightGray = lipgloss.Color("241")
)
func renderTable(data clientResponse, w io.Writer) {
re := lipgloss.NewRenderer(w)
var (
HeaderStyle = re.NewStyle().Foreground(lightBlue).Align(lipgloss.Center)
CellStyle = re.NewStyle().Padding(0, 1).Width(20).Align(lipgloss.Center)
OddRowStyle = CellStyle.Copy().Foreground(gray)
EvenRowStyle = CellStyle.Copy().Foreground(lightGray)
BorderStyle = lipgloss.NewStyle().Foreground(lightBlue)
)
rows := [][]string{
{"HTTP", fmt.Sprintf("http://%s.%s", data.id, data.domain)},
{"HTTPS", fmt.Sprintf("https://%s.%s", data.id, data.domain)},
{"TCP", fmt.Sprintf("tcp://%s:%d", data.domain, data.port)},
}
t := table.New().
Border(lipgloss.ThickBorder()).
BorderStyle(BorderStyle).
StyleFunc(func(row, col int) lipgloss.Style {
var style lipgloss.Style
switch {
case row == 0:
return HeaderStyle
case row%2 == 0:
style = EvenRowStyle
default:
style = OddRowStyle
}
// Make the second column a little wider.
if col == 1 {
style = style.Copy().Width(60)
}
return style
}).
Headers("Protocol", "URL").
Rows(rows...)
io.WriteString(w, t.String())
io.WriteString(w, "\n")
}
func renderMessage(data clientResponse, w io.Writer) {
style := lipgloss.NewStyle().Bold(true).Foreground(lightGreen).Background(black)
io.WriteString(w, style.Render("Welcome to bore server", version.Version, "at", data.domain))
io.WriteString(w, "\n")
}
|