Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
git-bug
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
MichaelMure
git-bug
Commits
b76357a5
Unverified
Commit
b76357a5
authored
Apr 20, 2019
by
Michael Muré
Browse files
Options
Downloads
Patches
Plain Diff
termui: make bugTable only use the cache Easy pick
fix #127
parent
ae7cf0b9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
termui/bug_table.go
+35
-20
35 additions, 20 deletions
termui/bug_table.go
with
35 additions
and
20 deletions
termui/bug_table.go
+
35
−
20
View file @
b76357a5
...
@@ -3,6 +3,7 @@ package termui
...
@@ -3,6 +3,7 @@ package termui
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"time"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity"
...
@@ -25,7 +26,7 @@ type bugTable struct {
...
@@ -25,7 +26,7 @@ type bugTable struct {
queryStr
string
queryStr
string
query
*
cache
.
Query
query
*
cache
.
Query
allIds
[]
string
allIds
[]
string
bugs
[]
*
cache
.
Bug
Cache
excerpts
[]
*
cache
.
Bug
Excerpt
pageCursor
int
pageCursor
int
selectCursor
int
selectCursor
int
}
}
...
@@ -242,29 +243,29 @@ func (bt *bugTable) doPaginate(max int) error {
...
@@ -242,29 +243,29 @@ func (bt *bugTable) doPaginate(max int) error {
nb
:=
minInt
(
len
(
bt
.
allIds
)
-
bt
.
pageCursor
,
max
)
nb
:=
minInt
(
len
(
bt
.
allIds
)
-
bt
.
pageCursor
,
max
)
if
nb
<
0
{
if
nb
<
0
{
bt
.
bug
s
=
[]
*
cache
.
Bug
Cache
{}
bt
.
excerpt
s
=
[]
*
cache
.
Bug
Excerpt
{}
return
nil
return
nil
}
}
// slice the data
// slice the data
ids
:=
bt
.
allIds
[
bt
.
pageCursor
:
bt
.
pageCursor
+
nb
]
ids
:=
bt
.
allIds
[
bt
.
pageCursor
:
bt
.
pageCursor
+
nb
]
bt
.
bug
s
=
make
([]
*
cache
.
Bug
Cache
,
len
(
ids
))
bt
.
excerpt
s
=
make
([]
*
cache
.
Bug
Excerpt
,
len
(
ids
))
for
i
,
id
:=
range
ids
{
for
i
,
id
:=
range
ids
{
b
,
err
:=
bt
.
repo
.
ResolveBug
(
id
)
excerpt
,
err
:=
bt
.
repo
.
ResolveBug
Excerpt
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
bt
.
bugs
[
i
]
=
b
bt
.
excerpts
[
i
]
=
excerpt
}
}
return
nil
return
nil
}
}
func
(
bt
*
bugTable
)
getTableLength
()
int
{
func
(
bt
*
bugTable
)
getTableLength
()
int
{
return
len
(
bt
.
bug
s
)
return
len
(
bt
.
excerpt
s
)
}
}
func
(
bt
*
bugTable
)
getColumnWidths
(
maxX
int
)
map
[
string
]
int
{
func
(
bt
*
bugTable
)
getColumnWidths
(
maxX
int
)
map
[
string
]
int
{
...
@@ -288,22 +289,31 @@ func (bt *bugTable) getColumnWidths(maxX int) map[string]int {
...
@@ -288,22 +289,31 @@ func (bt *bugTable) getColumnWidths(maxX int) map[string]int {
func
(
bt
*
bugTable
)
render
(
v
*
gocui
.
View
,
maxX
int
)
{
func
(
bt
*
bugTable
)
render
(
v
*
gocui
.
View
,
maxX
int
)
{
columnWidths
:=
bt
.
getColumnWidths
(
maxX
)
columnWidths
:=
bt
.
getColumnWidths
(
maxX
)
for
_
,
b
:=
range
bt
.
bugs
{
for
_
,
excerpt
:=
range
bt
.
excerpts
{
snap
:=
b
.
Snapshot
()
create
:=
snap
.
Comments
[
0
]
authorIdentity
:=
create
.
Author
summaryTxt
:=
fmt
.
Sprintf
(
"C:%-2d L:%-2d"
,
summaryTxt
:=
fmt
.
Sprintf
(
"C:%-2d L:%-2d"
,
len
(
snap
.
Comments
)
-
1
,
excerpt
.
Len
Comments
,
len
(
snap
.
Labels
),
len
(
excerpt
.
Labels
),
)
)
id
:=
text
.
LeftPadMaxLine
(
snap
.
HumanId
(),
columnWidths
[
"id"
],
1
)
var
authorDisplayName
string
status
:=
text
.
LeftPadMaxLine
(
snap
.
Status
.
String
(),
columnWidths
[
"status"
],
1
)
if
excerpt
.
AuthorId
!=
""
{
title
:=
text
.
LeftPadMaxLine
(
snap
.
Title
,
columnWidths
[
"title"
],
1
)
author
,
err
:=
bt
.
repo
.
ResolveIdentityExcerpt
(
excerpt
.
AuthorId
)
author
:=
text
.
LeftPadMaxLine
(
authorIdentity
.
DisplayName
(),
columnWidths
[
"author"
],
1
)
if
err
!=
nil
{
panic
(
err
)
}
authorDisplayName
=
author
.
DisplayName
()
}
else
{
authorDisplayName
=
excerpt
.
LegacyAuthor
.
DisplayName
()
}
lastEditTime
:=
time
.
Unix
(
excerpt
.
EditUnixTime
,
0
)
id
:=
text
.
LeftPadMaxLine
(
excerpt
.
HumanId
(),
columnWidths
[
"id"
],
1
)
status
:=
text
.
LeftPadMaxLine
(
excerpt
.
Status
.
String
(),
columnWidths
[
"status"
],
1
)
title
:=
text
.
LeftPadMaxLine
(
excerpt
.
Title
,
columnWidths
[
"title"
],
1
)
author
:=
text
.
LeftPadMaxLine
(
authorDisplayName
,
columnWidths
[
"author"
],
1
)
summary
:=
text
.
LeftPadMaxLine
(
summaryTxt
,
columnWidths
[
"summary"
],
1
)
summary
:=
text
.
LeftPadMaxLine
(
summaryTxt
,
columnWidths
[
"summary"
],
1
)
lastEdit
:=
text
.
LeftPadMaxLine
(
humanize
.
Time
(
snap
.
L
astEditTime
()
),
columnWidths
[
"lastEdit"
],
1
)
lastEdit
:=
text
.
LeftPadMaxLine
(
humanize
.
Time
(
l
astEditTime
),
columnWidths
[
"lastEdit"
],
1
)
_
,
_
=
fmt
.
Fprintf
(
v
,
"%s %s %s %s %s %s
\n
"
,
_
,
_
=
fmt
.
Fprintf
(
v
,
"%s %s %s %s %s %s
\n
"
,
colors
.
Cyan
(
id
),
colors
.
Cyan
(
id
),
...
@@ -332,7 +342,7 @@ func (bt *bugTable) renderHeader(v *gocui.View, maxX int) {
...
@@ -332,7 +342,7 @@ func (bt *bugTable) renderHeader(v *gocui.View, maxX int) {
}
}
func
(
bt
*
bugTable
)
renderFooter
(
v
*
gocui
.
View
,
maxX
int
)
{
func
(
bt
*
bugTable
)
renderFooter
(
v
*
gocui
.
View
,
maxX
int
)
{
_
,
_
=
fmt
.
Fprintf
(
v
,
"
\n
Showing %d of %d bugs"
,
len
(
bt
.
bug
s
),
len
(
bt
.
allIds
))
_
,
_
=
fmt
.
Fprintf
(
v
,
"
\n
Showing %d of %d bugs"
,
len
(
bt
.
excerpt
s
),
len
(
bt
.
allIds
))
}
}
func
(
bt
*
bugTable
)
cursorDown
(
g
*
gocui
.
Gui
,
v
*
gocui
.
View
)
error
{
func
(
bt
*
bugTable
)
cursorDown
(
g
*
gocui
.
Gui
,
v
*
gocui
.
View
)
error
{
...
@@ -430,7 +440,12 @@ func (bt *bugTable) newBug(g *gocui.Gui, v *gocui.View) error {
...
@@ -430,7 +440,12 @@ func (bt *bugTable) newBug(g *gocui.Gui, v *gocui.View) error {
func
(
bt
*
bugTable
)
openBug
(
g
*
gocui
.
Gui
,
v
*
gocui
.
View
)
error
{
func
(
bt
*
bugTable
)
openBug
(
g
*
gocui
.
Gui
,
v
*
gocui
.
View
)
error
{
_
,
y
:=
v
.
Cursor
()
_
,
y
:=
v
.
Cursor
()
ui
.
showBug
.
SetBug
(
bt
.
bugs
[
y
])
id
:=
bt
.
excerpts
[
y
]
.
Id
b
,
err
:=
bt
.
repo
.
ResolveBug
(
id
)
if
err
!=
nil
{
return
err
}
ui
.
showBug
.
SetBug
(
b
)
return
ui
.
activateWindow
(
ui
.
showBug
)
return
ui
.
activateWindow
(
ui
.
showBug
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment