Skip to content

Commit

Permalink
Add fancy formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Umut Isik committed Jan 30, 2020
1 parent b9fca2a commit e6a99ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Binary file removed hacker-laws-cli
Binary file not shown.
36 changes: 26 additions & 10 deletions lib/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"time"
"strings"
"regexp"

"github.com/fatih/color"
)
Expand Down Expand Up @@ -67,28 +68,43 @@ func (r *Repo) DisplayContentList() {
func (c *Content) Display() {
fmt.Println("")

DisplayTitle(c.Title)
c.DisplayTitle(c.Title)

for _, line := range strings.Split(strings.TrimSuffix(c.Body, "\n"), "\n") {
DisplayLine(line)
c.DisplayLine(line)
}

c.DisplayFooter()
}

func DisplayTitle(title string) {
func (c *Content) DisplayTitle(title string) {
d := color.New(color.FgGreen, color.Bold)
d.Print(strings.Trim(title, "\n"))
d.Println("-----------------------------------------------------")
d.Println(strings.Trim(title, "\n"))
d.Println("-----------------------------------------------------")
}

func DisplayLine(line string) {
func (c *Content) DisplayLine(line string) {
if strings.HasPrefix(line, ">") {
color.Yellow(strings.Trim(line, "\n"))
return
}

// Skip Wikipedi links
if strings.HasPrefix(line, "[") {
return
}
//color.White(strings.Trim(line, "\n"))
color.White(strings.Trim(StripMDTags(line), "\n"))
}

color.White(strings.Trim(line, "\n"))
func (c *Content) DisplayFooter() {
d := color.New(color.FgGreen, color.Bold)
d.Println("-----------------------------------------------------")
d.Println(" github.com/dwmkerr/hacker-laws by Dave Kerr ")
d.Println("-----------------------------------------------------")
}

func StripMDTags(line string) string {
re := regexp.MustCompile(`\[(.*?)\]\((.*?)\)`)
line = re.ReplaceAllString(line, `$1`)

return line
}

0 comments on commit e6a99ea

Please sign in to comment.