Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit13d3a1d

Browse files
authored
progress: render never started trackers properly (#273)
1 parentf16973f commit13d3a1d

28 files changed

+221
-235
lines changed

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
-name:Checkout Code
2222
uses:actions/checkout@v2
2323

24-
# Set up the GoLangenviroment
24+
# Set up the GoLangenvironment
2525
-name:Set up Go
2626
uses:actions/setup-go@v2
2727
with:

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ the following from within your code folder to do the same:
111111
```
112112
find . -type f -name "*.go" | grep -v vendor | xargs sed -i 's/jedib0t\/go-pretty\//jedib0t\/go-pretty\/v6\//g'
113113
```
114-
If you are onMacOS, you'll have to use`sed -i ''` instead of`sed -i`.
114+
If you are onmacOS, you'll have to use`sed -i ''` instead of`sed -i`.

‎cmd/demo-progress/demo.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func trackSomething(pw progress.Writer, idx int64, updateMessage bool) {
9797
}
9898
pw.SetPinnedMessages(
9999
fmt.Sprintf(">> Current Time: %-32s",time.Now().Format(time.RFC3339)),
100-
fmt.Sprintf(">> Total Time: %-32s",time.Now().Sub(timeStart).Round(time.Millisecond)),
100+
fmt.Sprintf(">> Total Time: %-32s",time.Since(timeStart).Round(time.Millisecond)),
101101
)
102102
case<-updateTicker:
103103
ifupdateMessage {

‎list/list.go‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type listItem struct {
1919
Textstring
2020
}
2121

22-
// List helps print a 2-dimensional array in a humanreadable pretty-List.
22+
// List helps print a 2-dimensional array in a human-readable pretty-List.
2323
typeListstruct {
2424
// approxSize stores the approximate output length/size
2525
approxSizeint
@@ -71,7 +71,7 @@ func (l *List) Reset() {
7171
l.style=nil
7272
}
7373

74-
// SetHTMLCSSClass sets thetheHTML CSS Class to use on the <ul> node
74+
// SetHTMLCSSClass sets the HTML CSS Class to use on the <ul> node
7575
// when rendering the List in HTML format. Recursive lists would use a numbered
7676
// index suffix. For ex., if the cssClass is set as "foo"; the <ul> for level 0
7777
// would have the class set as "foo"; the <ul> for level 1 would have "foo-1".
@@ -101,12 +101,8 @@ func (l *List) Style() *Style {
101101

102102
func (l*List)analyzeAndStringify(iteminterface{})*listItem {
103103
itemStr:=fmt.Sprint(item)
104-
ifstrings.Contains(itemStr,"\t") {
105-
itemStr=strings.Replace(itemStr,"\t"," ",-1)
106-
}
107-
ifstrings.Contains(itemStr,"\r") {
108-
itemStr=strings.Replace(itemStr,"\r","",-1)
109-
}
104+
itemStr=strings.ReplaceAll(itemStr,"\t"," ")
105+
itemStr=strings.ReplaceAll(itemStr,"\r","")
110106
return&listItem{
111107
Level:l.level,
112108
Text:itemStr,

‎list/render.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ func (l *List) Render() string {
2222
out.Grow(l.approxSize)
2323
foridx,item:=rangel.items {
2424
hint:=renderHint{
25-
isTopItem:bool(idx==0),
26-
isFirstItem:bool(idx==0||item.Level>l.items[idx-1].Level),
25+
isTopItem:idx==0,
26+
isFirstItem:idx==0||item.Level>l.items[idx-1].Level,
2727
isLastItem:!l.hasMoreItemsInLevel(item.Level,idx),
28-
isBottomItem:bool(idx==len(l.items)-1),
28+
isBottomItem:idx==len(l.items)-1,
2929
}
3030
ifhint.isFirstItem&&hint.isLastItem {
3131
hint.isOnlyItem=true
@@ -56,7 +56,7 @@ func (l *List) renderItem(out *strings.Builder, idx int, item *listItem, hint re
5656
}
5757

5858
// render the prefix or the leading text before the actual item
59-
l.renderItemBulletPrefix(out,idx,item.Level,lineIdx,hint)
59+
l.renderItemBulletPrefix(out,idx,item.Level)
6060
l.renderItemBullet(out,lineIdx,hint)
6161

6262
// render the actual item
@@ -73,11 +73,11 @@ func (l *List) renderItemBullet(out *strings.Builder, lineIdx int, hint renderHi
7373
out.WriteString(l.style.CharItemVertical)
7474
}
7575
}else {
76-
l.renderItemBulletSingleLine(out,lineIdx,hint)
76+
l.renderItemBulletSingleLine(out,hint)
7777
}
7878
}
7979

80-
func (l*List)renderItemBulletSingleLine(out*strings.Builder,lineIdxint,hintrenderHint) {
80+
func (l*List)renderItemBulletSingleLine(out*strings.Builder,hintrenderHint) {
8181
// single-line item.Text (or first line of a multi-line item.Text)
8282
ifhint.isOnlyItem {
8383
ifhint.isTopItem {
@@ -97,7 +97,7 @@ func (l *List) renderItemBulletSingleLine(out *strings.Builder, lineIdx int, hin
9797
out.WriteRune(' ')
9898
}
9999

100-
func (l*List)renderItemBulletPrefix(out*strings.Builder,itemIdxint,itemLevelint,lineIdxint,hintrenderHint) {
100+
func (l*List)renderItemBulletPrefix(out*strings.Builder,itemIdxint,itemLevelint) {
101101
// write a prefix if one has been set in l.style
102102
ifl.style.LinePrefix!="" {
103103
out.WriteString(l.style.LinePrefix)

‎list/render_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,4 @@ func TestList_Render_UnindentAll(t *testing.T) {
331331
* Way
332332
* Right?`
333333
assert.Equal(t,expectedOut,lw.Render())
334-
335334
}

‎list/writer.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package list
22

33
import"io"
44

5-
// Writer declares the interfaces that can be used tosetup and render a list.
5+
// Writer declares the interfaces that can be used toset up and render a list.
66
typeWriterinterface {
77
AppendItem(iteminterface{})
88
AppendItems(items []interface{})

‎progress/progress.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (p *Progress) SetPinnedMessages(messages ...string) {
199199
}
200200

201201
// SetSortBy defines the sorting mechanism to use to sort the Active Trackers
202-
// before rendering the. Default: no-sorting == sort-by-insertion-order.
202+
// before rendering. Default: no-sorting == sort-by-insertion-order.
203203
func (p*Progress)SetSortBy(sortBySortBy) {
204204
p.sortBy=sortBy
205205
}
@@ -221,7 +221,7 @@ func (p *Progress) SetTrackerPosition(position Position) {
221221
}
222222

223223
// SetUpdateFrequency sets the update frequency while rendering the trackers.
224-
// the lower the value, the morenumber of times the Trackers get refreshed. A
224+
// the lower the value, the morefrequently the Trackers get refreshed. A
225225
// sane value would be 250ms.
226226
func (p*Progress)SetUpdateFrequency(frequency time.Duration) {
227227
p.updateFrequency=frequency

‎progress/progress_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ func TestProgress_SetUpdateFrequency(t *testing.T) {
169169
p.initForRender()
170170
assert.Equal(t,DefaultUpdateFrequency,p.updateFrequency)
171171

172-
p.SetUpdateFrequency(time.Duration(time.Second))
173-
assert.Equal(t,time.Duration(time.Second),p.updateFrequency)
172+
p.SetUpdateFrequency(time.Second)
173+
assert.Equal(t,time.Second,p.updateFrequency)
174174
}
175175

176176
funcTestProgress_ShowETA(t*testing.T) {

‎progress/render.go‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (p *Progress) generateTrackerStrIndeterminate(maxLen int) string {
149149
}
150150

151151
returnp.style.Colors.Tracker.Sprintf("%s%s%s",
152-
p.style.Chars.BoxLeft,string(pUnfinished),p.style.Chars.BoxRight,
152+
p.style.Chars.BoxLeft,pUnfinished,p.style.Chars.BoxRight,
153153
)
154154
}
155155

@@ -185,12 +185,8 @@ func (p *Progress) renderPinnedMessages(out *strings.Builder) {
185185

186186
func (p*Progress)renderTracker(out*strings.Builder,t*Tracker,hintrenderHint) {
187187
message:=t.message()
188-
ifstrings.Contains(message,"\t") {
189-
message=strings.Replace(message,"\t"," ",-1)
190-
}
191-
ifstrings.Contains(message,"\r") {
192-
message=strings.Replace(message,"\r","",-1)
193-
}
188+
message=strings.ReplaceAll(message,"\t"," ")
189+
message=strings.ReplaceAll(message,"\r","")
194190
ifp.messageWidth>0 {
195191
messageLen:=text.RuneWidthWithoutEscSequences(message)
196192
ifmessageLen<p.messageWidth {
@@ -412,10 +408,12 @@ func (p *Progress) renderTrackerStatsSpeedInternal(out *strings.Builder, speed s
412408

413409
func (p*Progress)renderTrackerStatsTime(outStats*strings.Builder,t*Tracker,hintrenderHint) {
414410
vartd,tp time.Duration
415-
ift.IsDone() {
416-
td=t.timeStop.Sub(t.timeStart)
417-
}elseif!t.timeStart.IsZero() {
418-
td=time.Since(t.timeStart)
411+
if!t.timeStart.IsZero() {
412+
ift.IsDone() {
413+
td=t.timeStop.Sub(t.timeStart)
414+
}else {
415+
td=time.Since(t.timeStart)
416+
}
419417
}
420418
ifhint.isOverallTracker {
421419
tp=p.style.Options.TimeOverallPrecision

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp