Display: Use Style colors
This commit is contained in:
parent
71efe818a1
commit
09e780385e
11
client.go
11
client.go
|
@ -130,6 +130,15 @@ func (c *Client) DisplayPage(page *Page) {
|
|||
// ParseGeminiPage parses bytes in page in returns a rendered string for the
|
||||
// page
|
||||
func (c *Client) ParseGeminiPage(page *Page) string {
|
||||
var (
|
||||
h1Style = c.style.gmiH1.Sprint
|
||||
h2Style = c.style.gmiH2.Sprint
|
||||
h3Style = c.style.gmiH3.Sprint
|
||||
preStyle = c.style.gmiPre.Sprint
|
||||
linkStyle = c.style.gmiLink.Sprint
|
||||
quoteStyle = c.style.gmiQuote.Sprint
|
||||
)
|
||||
|
||||
termWidth, _, err := term.GetSize(0)
|
||||
if err != nil {
|
||||
// TODO do something
|
||||
|
@ -162,7 +171,7 @@ func (c *Client) ParseGeminiPage(page *Page) string {
|
|||
// NOT doing this anymore!
|
||||
// (because it looked bad if quotes are continuous)
|
||||
// TODO: remove extra new lines in the end
|
||||
rendered += ansiwrap.GreedyIndent(line, width, 1+sides, 3+sides) + "\n"
|
||||
rendered += ansiwrap.GreedyIndent(quoteStyle(line), width, 1+sides, 3+sides) + "\n"
|
||||
|
||||
} else if strings.HasPrefix(line, "* ") { // whitespace after * is mandatory
|
||||
// Using width - 3 because of 3 spaces " " indent at the start
|
||||
|
|
10
display.go
10
display.go
|
@ -27,10 +27,12 @@ var DefaultStyle = Style{
|
|||
Prompt: color.FgCyan,
|
||||
StatusError: color.New(color.FgYellow),
|
||||
|
||||
gmiH1: color.New(color.Bold, color.Underline, color.FgYellow),
|
||||
gmiH2: color.New(color.Bold, color.FgGreen),
|
||||
gmiH3: color.New(color.FgMagenta),
|
||||
gmiLink: color.New(color.FgBlue),
|
||||
gmiH1: color.New(color.Bold, color.Underline, color.FgYellow),
|
||||
gmiH2: color.New(color.Bold, color.FgMagenta),
|
||||
gmiH3: color.New(color.FgHiGreen),
|
||||
gmiPre: color.New(color.FgYellow),
|
||||
gmiLink: color.New(color.FgBlue),
|
||||
gmiQuote: color.New(color.Italic, color.FgGreen),
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
14
gemini.go
14
gemini.go
|
@ -10,8 +10,6 @@ import (
|
|||
//"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
type GeminiResponse struct {
|
||||
|
@ -30,16 +28,6 @@ type GeminiResponse struct {
|
|||
//ErrDecodeMetaFail = errors.New("failed to decode meta header")
|
||||
//)
|
||||
|
||||
var (
|
||||
h1Style = color.New(color.Bold).Add(color.Underline).Add(color.FgHiMagenta).SprintFunc()
|
||||
h2Style = color.New(color.Bold).Add(color.FgGreen).SprintFunc()
|
||||
h3Style = color.New(color.Bold).Add(color.FgMagenta).SprintFunc()
|
||||
preStyle = color.New(color.FgYellow).SprintFunc()
|
||||
linkStyle = color.New(color.FgBlue).SprintFunc()
|
||||
// style only applied to first line for some reason, so removing it all together :P
|
||||
// quoteStyle = color.New(color.Italic).SprintFunc()
|
||||
)
|
||||
|
||||
// GeminiParsedURL fetches u and returns *GeminiResponse
|
||||
func GeminiParsedURL(u url.URL) (res *GeminiResponse, err error) {
|
||||
host := u.Host
|
||||
|
@ -67,7 +55,7 @@ func GeminiParsedURL(u url.URL) (res *GeminiResponse, err error) {
|
|||
status, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return res, errors.New("Invalid status code")
|
||||
return res, errors.New("invalid status code")
|
||||
}
|
||||
meta := strings.Join(parts[1:], " ")
|
||||
res = &GeminiResponse{status, meta, reader, false, conn, false}
|
||||
|
|
Loading…
Reference in New Issue