github.com/wtfutil/wtf@v0.43.0/modules/pivotal/display.go (about)

     1  package pivotal
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/rivo/tview"
     6  	"github.com/wtfutil/wtf/utils"
     7  	"regexp"
     8  )
     9  
    10  const (
    11  	hasPullFailIcon = '💥'
    12  	hasPullIcon     = "🌱"
    13  )
    14  
    15  var statusMapEmoji = map[string]string{
    16  	"started":     "🚧",
    17  	"unstarted":   "  ",
    18  	"finished":    "🚀",
    19  	"delivered":   "🚢",
    20  	"rejected":    "❌",
    21  	"accepted":    "✅",
    22  	"planned":     "📅",
    23  	"unscheduled": "❓",
    24  }
    25  
    26  func (widget *Widget) display() {
    27  	widget.SetItemCount(widget.CurrentSource().getItemCount())
    28  	widget.ScrollableWidget.Redraw(widget.content)
    29  }
    30  
    31  func (widget *Widget) content() (string, string, bool) {
    32  	proj := widget.CurrentSource()
    33  
    34  	if proj == nil {
    35  		return widget.CommonSettings().Title, "No sources", false
    36  	}
    37  
    38  	if proj.Err != nil {
    39  		return widget.CommonSettings().Title, proj.Err.Error(), true
    40  	}
    41  
    42  	title := fmt.Sprintf(
    43  		"[%s]%s[white] - %d ",
    44  		widget.settings.Colors.TextTheme.Title,
    45  		proj.name, proj.getItemCount())
    46  
    47  	str := ""
    48  	for idx, item := range proj.stories {
    49  		rowColor := widget.RowColor(idx)
    50  		displayText := getShowText(&item)
    51  
    52  		row := fmt.Sprintf(
    53  			`[%s]|%s%s| %s[%s]`,
    54  			widget.RowColor(idx),
    55  			getStatusIcon(&item),
    56  			getPullStatusIcon(&item),
    57  			tview.Escape(displayText),
    58  			rowColor,
    59  		)
    60  
    61  		str += utils.HighlightableHelper(widget.View, row, idx, len(item.Name))
    62  	}
    63  
    64  	return title, str, false
    65  }
    66  
    67  func getStatusIcon(story *Story) string {
    68  	state := story.CurrentState
    69  	val, ok := statusMapEmoji[state]
    70  	if ok {
    71  		state = val
    72  	}
    73  	return state
    74  }
    75  
    76  func getPullStatusIcon(story *Story) string {
    77  	//prs := len(story.PullRequests)
    78  	var prs string
    79  	prs = "  "
    80  	if len(story.PullRequests) > 0 {
    81  		prs = hasPullIcon
    82  	}
    83  	return prs
    84  }
    85  
    86  func getShowText(story *Story) string {
    87  	if story == nil {
    88  		return ""
    89  	}
    90  
    91  	space := regexp.MustCompile(`\s+`)
    92  	title := space.ReplaceAllString(story.Name, " ")
    93  	//html.UnescapeString("[" + rowColor + "]" + title)
    94  	return title
    95  }