github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/edit/completion/utils.go (about)

     1  package completion
     2  
     3  import (
     4  	"fmt"
     5  	"unicode"
     6  
     7  	"github.com/u-root/u-root/cmds/elvish/edit/ui"
     8  	"github.com/u-root/u-root/cmds/elvish/util"
     9  )
    10  
    11  func throw(e error) {
    12  	util.Throw(e)
    13  }
    14  
    15  func maybeThrow(e error) {
    16  	if e != nil {
    17  		util.Throw(e)
    18  	}
    19  }
    20  
    21  func throwf(format string, args ...interface{}) {
    22  	util.Throw(fmt.Errorf(format, args...))
    23  }
    24  
    25  func min(a, b int) int {
    26  	if a <= b {
    27  		return a
    28  	}
    29  	return b
    30  }
    31  
    32  func max(a, b int) int {
    33  	if a >= b {
    34  		return a
    35  	}
    36  	return b
    37  }
    38  
    39  // Styles for UI.
    40  var (
    41  	// Use default style for completion listing
    42  	styleForCompletion = ui.Styles{}
    43  	// Use inverse style for selected completion entry
    44  	styleForSelectedCompletion = ui.Styles{"inverse"}
    45  )
    46  
    47  // likeChar returns if a key looks like a character meant to be input (as
    48  // opposed to a function key).
    49  func likeChar(k ui.Key) bool {
    50  	return k.Mod == 0 && k.Rune > 0 && unicode.IsGraphic(k.Rune)
    51  }