aboutsummaryrefslogtreecommitdiffstats
path: root/termui
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-11 22:04:16 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-11 22:14:46 +0200
commit3605887345792d2f981f971c6c4a2cb7f86a343e (patch)
treeafd525b6e3a638e4c619a5a986fcb2811c297444 /termui
parent7b05983c19af4da70f2a9a5062913f4e4f5d5faa (diff)
downloadgit-bug-3605887345792d2f981f971c6c4a2cb7f86a343e.tar.gz
reorganize package for a more idomatic go
Diffstat (limited to 'termui')
-rw-r--r--termui/bug_table.go35
-rw-r--r--termui/msg_popup.go4
-rw-r--r--termui/show_bug.go47
3 files changed, 44 insertions, 42 deletions
diff --git a/termui/bug_table.go b/termui/bug_table.go
index 59252b48..9ac04608 100644
--- a/termui/bug_table.go
+++ b/termui/bug_table.go
@@ -6,7 +6,8 @@ import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/util"
+ "github.com/MichaelMure/git-bug/util/colors"
+ "github.com/MichaelMure/git-bug/util/text"
"github.com/dustin/go-humanize"
"github.com/jroimartin/gocui"
)
@@ -296,18 +297,18 @@ func (bt *bugTable) render(v *gocui.View, maxX int) {
person = create.Author
}
- id := util.LeftPaddedString(snap.HumanId(), columnWidths["id"], 2)
- status := util.LeftPaddedString(snap.Status.String(), columnWidths["status"], 2)
- title := util.LeftPaddedString(snap.Title, columnWidths["title"], 2)
- author := util.LeftPaddedString(person.Name, columnWidths["author"], 2)
- summary := util.LeftPaddedString(snap.Summary(), columnWidths["summary"], 2)
- lastEdit := util.LeftPaddedString(humanize.Time(snap.LastEditTime()), columnWidths["lastEdit"], 2)
+ id := text.LeftPaddedString(snap.HumanId(), columnWidths["id"], 2)
+ status := text.LeftPaddedString(snap.Status.String(), columnWidths["status"], 2)
+ title := text.LeftPaddedString(snap.Title, columnWidths["title"], 2)
+ author := text.LeftPaddedString(person.Name, columnWidths["author"], 2)
+ summary := text.LeftPaddedString(snap.Summary(), columnWidths["summary"], 2)
+ lastEdit := text.LeftPaddedString(humanize.Time(snap.LastEditTime()), columnWidths["lastEdit"], 2)
fmt.Fprintf(v, "%s %s %s %s %s %s\n",
- util.Cyan(id),
- util.Yellow(status),
+ colors.Cyan(id),
+ colors.Yellow(status),
title,
- util.Magenta(author),
+ colors.Magenta(author),
summary,
lastEdit,
)
@@ -317,12 +318,12 @@ func (bt *bugTable) render(v *gocui.View, maxX int) {
func (bt *bugTable) renderHeader(v *gocui.View, maxX int) {
columnWidths := bt.getColumnWidths(maxX)
- id := util.LeftPaddedString("ID", columnWidths["id"], 2)
- status := util.LeftPaddedString("STATUS", columnWidths["status"], 2)
- title := util.LeftPaddedString("TITLE", columnWidths["title"], 2)
- author := util.LeftPaddedString("AUTHOR", columnWidths["author"], 2)
- summary := util.LeftPaddedString("SUMMARY", columnWidths["summary"], 2)
- lastEdit := util.LeftPaddedString("LAST EDIT", columnWidths["lastEdit"], 2)
+ id := text.LeftPaddedString("ID", columnWidths["id"], 2)
+ status := text.LeftPaddedString("STATUS", columnWidths["status"], 2)
+ title := text.LeftPaddedString("TITLE", columnWidths["title"], 2)
+ author := text.LeftPaddedString("AUTHOR", columnWidths["author"], 2)
+ summary := text.LeftPaddedString("SUMMARY", columnWidths["summary"], 2)
+ lastEdit := text.LeftPaddedString("LAST EDIT", columnWidths["lastEdit"], 2)
fmt.Fprintf(v, "\n")
fmt.Fprintf(v, "%s %s %s %s %s %s\n", id, status, title, author, summary, lastEdit)
@@ -433,7 +434,7 @@ func (bt *bugTable) pull(g *gocui.Gui, v *gocui.View) error {
})
} else {
fmt.Fprintf(&buffer, "%s%s: %s",
- beginLine, util.Cyan(merge.Bug.HumanId()), merge.Status,
+ beginLine, colors.Cyan(merge.Bug.HumanId()), merge.Status,
)
beginLine = "\n"
diff --git a/termui/msg_popup.go b/termui/msg_popup.go
index dea24fb4..0ce390dc 100644
--- a/termui/msg_popup.go
+++ b/termui/msg_popup.go
@@ -3,7 +3,7 @@ package termui
import (
"fmt"
- "github.com/MichaelMure/git-bug/util"
+ "github.com/MichaelMure/git-bug/util/text"
"github.com/jroimartin/gocui"
)
@@ -45,7 +45,7 @@ func (ep *msgPopup) layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
width := minInt(60, maxX)
- wrapped, lines := util.TextWrap(ep.message, width-2)
+ wrapped, lines := text.Wrap(ep.message, width-2)
height := minInt(lines+1, maxY-3)
x0 := (maxX - width) / 2
y0 := (maxY - height) / 2
diff --git a/termui/show_bug.go b/termui/show_bug.go
index dc661f0e..3d4b257f 100644
--- a/termui/show_bug.go
+++ b/termui/show_bug.go
@@ -5,9 +5,10 @@ import (
"fmt"
"strings"
- "github.com/MichaelMure/git-bug/bug/operations"
"github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/util"
+ "github.com/MichaelMure/git-bug/operations"
+ "github.com/MichaelMure/git-bug/util/colors"
+ "github.com/MichaelMure/git-bug/util/text"
"github.com/jroimartin/gocui"
)
@@ -209,13 +210,13 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
sb.mainSelectableView = nil
bugHeader := fmt.Sprintf("[%s] %s\n\n[%s] %s opened this bug on %s",
- util.Cyan(snap.HumanId()),
- util.Bold(snap.Title),
- util.Yellow(snap.Status),
- util.Magenta(snap.Author.Name),
+ colors.Cyan(snap.HumanId()),
+ colors.Bold(snap.Title),
+ colors.Yellow(snap.Status),
+ colors.Magenta(snap.Author.Name),
snap.CreatedAt.Format(timeLayout),
)
- bugHeader, lines := util.TextWrap(bugHeader, maxX)
+ bugHeader, lines := text.Wrap(bugHeader, maxX)
v, err := sb.createOpView(g, showBugHeaderView, x0, y0, maxX+1, lines, false)
if err != nil {
@@ -235,7 +236,7 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
case operations.CreateOperation:
create := op.(operations.CreateOperation)
- content, lines := util.TextWrapPadded(create.Message, maxX, 4)
+ content, lines := text.WrapLeftPadded(create.Message, maxX, 4)
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
if err != nil {
@@ -247,13 +248,13 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
case operations.AddCommentOperation:
comment := op.(operations.AddCommentOperation)
- message, _ := util.TextWrapPadded(comment.Message, maxX, 4)
+ message, _ := text.WrapLeftPadded(comment.Message, maxX, 4)
content := fmt.Sprintf("%s commented on %s\n\n%s",
- util.Magenta(comment.Author.Name),
+ colors.Magenta(comment.Author.Name),
comment.Time().Format(timeLayout),
message,
)
- content, lines = util.TextWrap(content, maxX)
+ content, lines = text.Wrap(content, maxX)
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
if err != nil {
@@ -266,11 +267,11 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
setTitle := op.(operations.SetTitleOperation)
content := fmt.Sprintf("%s changed the title to %s on %s",
- util.Magenta(setTitle.Author.Name),
- util.Bold(setTitle.Title),
+ colors.Magenta(setTitle.Author.Name),
+ colors.Bold(setTitle.Title),
setTitle.Time().Format(timeLayout),
)
- content, lines := util.TextWrap(content, maxX)
+ content, lines := text.Wrap(content, maxX)
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
if err != nil {
@@ -283,11 +284,11 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
setStatus := op.(operations.SetStatusOperation)
content := fmt.Sprintf("%s %s the bug on %s",
- util.Magenta(setStatus.Author.Name),
- util.Bold(setStatus.Status.Action()),
+ colors.Magenta(setStatus.Author.Name),
+ colors.Bold(setStatus.Status.Action()),
setStatus.Time().Format(timeLayout),
)
- content, lines := util.TextWrap(content, maxX)
+ content, lines := text.Wrap(content, maxX)
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
if err != nil {
@@ -301,12 +302,12 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
var added []string
for _, label := range labelChange.Added {
- added = append(added, util.Bold("\""+label+"\""))
+ added = append(added, colors.Bold("\""+label+"\""))
}
var removed []string
for _, label := range labelChange.Removed {
- removed = append(removed, util.Bold("\""+label+"\""))
+ removed = append(removed, colors.Bold("\""+label+"\""))
}
var action bytes.Buffer
@@ -332,11 +333,11 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
}
content := fmt.Sprintf("%s %s on %s",
- util.Magenta(labelChange.Author.Name),
+ colors.Magenta(labelChange.Author.Name),
action.String(),
labelChange.Time().Format(timeLayout),
)
- content, lines := util.TextWrap(content, maxX)
+ content, lines := text.Wrap(content, maxX)
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
if err != nil {
@@ -402,9 +403,9 @@ func (sb *showBug) renderSidebar(g *gocui.Gui, sideView *gocui.View) error {
}
labels := strings.Join(labelStr, "\n")
- labels, lines := util.TextWrapPadded(labels, maxX, 2)
+ labels, lines := text.WrapLeftPadded(labels, maxX, 2)
- content := fmt.Sprintf("%s\n\n%s", util.Bold("Labels"), labels)
+ content := fmt.Sprintf("%s\n\n%s", colors.Bold("Labels"), labels)
v, err := sb.createSideView(g, "sideLabels", x0, y0, maxX, lines+2)
if err != nil {