Skip to content

Commit

Permalink
vichan: added flags for customize what to show of the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Apr 24, 2023
1 parent 25407e0 commit 73b6a6c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
7 changes: 6 additions & 1 deletion internal/vichan/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func Fetch(
rawUrl, userAgent string,
width, leftPadding uint,
timeout time.Duration,
showAuthor, showDate, showId bool,
) (*Thread, error) {
effectiveUrl, err := parseUrl(rawUrl)
if err != nil {
Expand All @@ -36,8 +37,11 @@ func Fetch(

thread.op.thread = thread
thread.leftPadding = leftPadding
thread.width = width
thread.showAuthor = showAuthor
thread.showDate = showDate
thread.showId = showId
thread.url = rawUrl
thread.width = width

return thread, nil
}
Expand All @@ -50,6 +54,7 @@ func toThread(vichanThread jsonmodel.Thread) (*Thread, error) {
vichanOp := vichanThread.Posts[0]
op := Op{
attachments: getAttachments(vichanOp),
author: vichanOp.Author,
createdAt: time.Unix(int64(vichanOp.Time), 0),
id: vichanOp.No,
message: vichanOp.Comment,
Expand Down
24 changes: 21 additions & 3 deletions internal/vichan/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ func (op Op) String() (ret string) {
}
if op.message != "" {
ret += "\n" + formatText(op.message, int(op.thread.width), int(op.thread.leftPadding))
ret += "\n\n"
}
ret += fmt.Sprintf("\n\n%s\n\n\n", humanize.Time(op.createdAt))
ret += " " + humanize.Time(op.createdAt)
if op.thread.showAuthor {
ret += " by " + op.author
}
ret += "\n\n\n"
return
}

Expand All @@ -57,11 +62,24 @@ func (comment Comment) String() (ret string) {
int(comment.thread.width),
comment.depth*int(comment.thread.leftPadding)+1,
)
ret += "\n"
}
ret += "\n" + strings.Repeat(" ", comment.depth*3)
ret += fmt.Sprintf(">> %s\n", humanize.Time(comment.createdAt))

ret += strings.Repeat(" ", comment.depth*3)
ret += ">>"
if comment.thread.showDate {
ret += " " + humanize.Time(comment.createdAt)
}
if comment.thread.showAuthor {
ret += " " + comment.author
}
if comment.thread.showId {
ret += " " + fmt.Sprintf("%d", comment.id)
}
ret += "\n"

for _, attachment := range comment.attachments {
ret += strings.Repeat(" ", comment.depth*3)
ret += fmt.Sprintf(
">> %s \"%s\"\n",
path.Dir(path.Dir(comment.thread.url))+"/src/"+attachment.newFilename,
Expand Down
4 changes: 4 additions & 0 deletions internal/vichan/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type Thread struct {
leftPadding uint
width uint
url string
showAuthor bool
showDate bool
showId bool
}

type Attachment struct {
Expand All @@ -26,6 +29,7 @@ type Attachment struct {

type Op struct {
attachments []Attachment
author string
createdAt time.Time
id int
message string
Expand Down

0 comments on commit 73b6a6c

Please sign in to comment.