Skip to content

Commit

Permalink
take width from opts
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Jul 27, 2022
1 parent b045b41 commit 908dabb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 1 addition & 4 deletions cmd/hackerview/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ func run(args []string, stdout io.Writer) error {
if err != nil {
return errors.New("could not fetch url")
}
fmt.Println(op)
for _, comment := range *comments {
fmt.Println(&comment)
}
hackernews.Format(opt.width, op, comments)
return nil
}

Expand Down
16 changes: 14 additions & 2 deletions internal/hackernews/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import (

const SPACES_PER_INDENT = 5

var max_width int

func Format(width int, op *Op, comments *[]Comment) {
max_width = width
fmt.Println(op)
for _, comment := range *comments {
fmt.Println(comment)
}
}

func printChilds(c []*Comment) {
for _, value := range c {
fmt.Println(value)
Expand All @@ -20,7 +30,9 @@ func printChilds(c []*Comment) {

func (o *Op) String() (ret string) {
ret += "title: " + o.title + "\n"
ret += "url: " + o.url + "\n"
if o.url != "" {
ret += "url: " + o.url + "\n"
}
ret += "self: " + o.selfUrl + "\n"
ret += fmt.Sprintf("%s(%d) - %s\n", o.user, o.score, humanize.Time(o.date))
return
Expand All @@ -35,7 +47,7 @@ func (c *Comment) String() (ret string) {
if err != nil {
panic(err)
}
wrapped, _ := text.WrapLeftPadded(msg, 120, indent+1)
wrapped, _ := text.WrapLeftPadded(msg, max_width, indent+1)
ret += "\n" + wrapped + "\n"
arrow := ">>> "
if c.indent > 0 {
Expand Down

0 comments on commit 908dabb

Please sign in to comment.