github.com/wtfutil/wtf@v0.43.0/modules/cryptocurrency/cryptolive/toplist/display.go (about)

     1  package toplist
     2  
     3  import "fmt"
     4  
     5  func (widget *Widget) display() {
     6  	str := ""
     7  	for _, fromCurrency := range widget.list.items {
     8  		str += fmt.Sprintf(
     9  			"[%s]%s [%s](%s)\n",
    10  			widget.settings.colors.from.displayName,
    11  			fromCurrency.displayName,
    12  			widget.settings.colors.from.name,
    13  			fromCurrency.name,
    14  		)
    15  		str += widget.makeToListText(fromCurrency.to)
    16  	}
    17  
    18  	widget.Result = str
    19  }
    20  
    21  func (widget *Widget) makeToListText(toList []*tCurrency) string {
    22  	str := ""
    23  	for _, toCurrency := range toList {
    24  		str += widget.makeToText(toCurrency)
    25  	}
    26  
    27  	return str
    28  }
    29  
    30  func (widget *Widget) makeToText(toCurrency *tCurrency) string {
    31  	str := ""
    32  	str += fmt.Sprintf(
    33  		"  [%s]%s\n",
    34  		widget.settings.colors.to.name,
    35  		toCurrency.name,
    36  	)
    37  
    38  	for _, info := range toCurrency.info {
    39  		str += widget.makeInfoText(info)
    40  		str += "\n\n"
    41  	}
    42  	return str
    43  }
    44  
    45  func (widget *Widget) makeInfoText(info tInfo) string {
    46  	return fmt.Sprintf(
    47  		"    [%s]Exchange: [%s]%s\n",
    48  		widget.settings.colors.top.to.field,
    49  		widget.settings.colors.top.to.value,
    50  		info.exchange,
    51  	) +
    52  		fmt.Sprintf(
    53  			"    [%s]Volume(24h): [%s]%f-[%s]%f",
    54  			widget.settings.colors.top.to.field,
    55  			widget.settings.colors.top.to.value,
    56  			info.volume24h,
    57  			widget.settings.colors.top.to.value,
    58  			info.volume24hTo,
    59  		)
    60  }