Skip to content

Commit a8d032f

Browse files
committed
render info box but buggy
1 parent 934a33a commit a8d032f

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

pkg/cmd/project/http.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ func getProject(client *api.Client, baseRepo ghrepo.Interface, projectID int) (*
3030
return nil, err
3131
}
3232

33-
titled := struct {
34-
Title string
35-
}{}
36-
3733
for _, column := range project.Columns {
3834
data, err := client.GetProjectCards(baseRepo, column.ID)
3935
if err != nil {
@@ -53,11 +49,10 @@ func getProject(client *api.Client, baseRepo ghrepo.Interface, projectID int) (*
5349
return nil, err
5450
}
5551

56-
err = json.Unmarshal(data, &titled)
52+
err = json.Unmarshal(data, &card.Content)
5753
if err != nil {
5854
return nil, err
5955
}
60-
card.Note = titled.Title
6156
}
6257
}
6358
}

pkg/cmd/project/project.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package project
22

33
import (
44
"net/http"
5+
"strings"
56
"time"
67

78
"github.com/cli/cli/api"
@@ -48,10 +49,16 @@ func NewCmdProject(f *cmdutil.Factory, runF func(*ProjectOptions) error) *cobra.
4849
return cmd
4950
}
5051

52+
type Content struct {
53+
Title string
54+
Body string
55+
}
56+
5157
type Card struct {
5258
Note string
5359
ID int
5460
ContentURL string `json:"content_url"`
61+
Content *Content
5562
}
5663

5764
type Column struct {
@@ -185,7 +192,10 @@ loop:
185192
}
186193
drawRect(s, cardStyle, colX+1, (ic*cardHeight)+colY+2, cardWidth, cardHeight, bold)
187194
cardNote := card.Note
188-
if len(card.Note) > cardWidth-2 {
195+
if cardNote == "" {
196+
cardNote = card.Content.Title
197+
}
198+
if len(cardNote) > cardWidth-2 {
189199
cardNote = cardNote[0 : cardWidth-2]
190200
} else if cardNote == "" {
191201
cardNote = `¯\_(ツ)_/¯`
@@ -200,7 +210,29 @@ loop:
200210
infoWidth := colWidth * 2
201211
infoHeight := colHeight
202212
drawRect(s, style, infoX, infoY, infoWidth, infoHeight, true)
203-
drawStr(s, infoX+1, infoY+1, style, cardInfo.Note)
213+
if cardInfo.Content != nil {
214+
title := cardInfo.Content.Title
215+
if len(title) > infoWidth-2 {
216+
title = title[0 : infoWidth-2]
217+
}
218+
drawStr(s, infoX+1, infoY+1, style, title)
219+
220+
// TODO markdown rendering did _not_ output correctly; lots of escaped ANSI
221+
222+
bodyLines := strings.Split(cardInfo.Content.Body, "\n")
223+
for i, line := range bodyLines {
224+
if infoY+2+i > infoHeight-2 {
225+
break
226+
}
227+
outLine := line
228+
if len(outLine) > infoWidth-2 {
229+
outLine = outLine[0 : infoWidth-2]
230+
}
231+
drawStr(s, infoX+1, infoY+2+i, style, outLine)
232+
}
233+
} else {
234+
drawStr(s, infoX+1, infoY+1, style, cardInfo.Note)
235+
}
204236

205237
s.Show()
206238
}

0 commit comments

Comments
 (0)