github.com/hoop33/elvish@v0.0.0-20160801152013-6d25485beab4/edit/styled.go (about)

     1  package edit
     2  
     3  import "sort"
     4  
     5  // styled is a piece of text with style.
     6  type styled struct {
     7  	text  string
     8  	style string
     9  }
    10  
    11  func unstyled(s string) styled {
    12  	return styled{s, ""}
    13  }
    14  
    15  func (s *styled) addStyle(st string) {
    16  	s.style = joinStyle(s.style, st)
    17  }
    18  
    19  type styleds []styled
    20  
    21  func (s styleds) Len() int           { return len(s) }
    22  func (s styleds) Less(i, j int) bool { return s[i].text < s[j].text }
    23  func (s styleds) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
    24  
    25  func sortStyleds(s []styled) {
    26  	sort.Sort(styleds(s))
    27  }