gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/elvish/edit/history/list.go (about)

     1  package history
     2  
     3  import (
     4  	"sync"
     5  
     6  	//	"github.com/u-root/u-root/cmds/core/elvish/eval/vals"
     7  	"github.com/u-root/u-root/cmds/core/elvish/util"
     8  )
     9  
    10  // List is a list-like value that provides access to history in the API
    11  // backend. It is used in the $edit:history variable.
    12  type List struct {
    13  	*sync.RWMutex
    14  }
    15  
    16  func (hv List) Kind() string {
    17  	return "list"
    18  }
    19  
    20  // Equal returns true as long as the rhs is also of type History.
    21  func (hv List) Equal(a interface{}) bool {
    22  	_, ok := a.(List)
    23  	return ok
    24  }
    25  
    26  func (hv List) Hash() uint32 {
    27  	// TODO(xiaq): Make a global registry of singleton hashes to avoid
    28  	// collision.
    29  	return 100
    30  }
    31  
    32  func (hv List) Repr(int) string {
    33  	return "$edit:history"
    34  }
    35  
    36  func (hv List) Len() int {
    37  	hv.RLock()
    38  	defer hv.RUnlock()
    39  
    40  	//	nextseq, err = -1, nil
    41  	maybeThrow(nil)
    42  	return -1
    43  
    44  }
    45  
    46  func (hv List) Iterate(f func(interface{}) bool) {
    47  	hv.RLock()
    48  	defer hv.RUnlock()
    49  	/*
    50  		n := hv.Len()
    51  		cmds, err := hv.Daemon.Cmds(1, n+1)
    52  		maybeThrow(err)
    53  
    54  		for _, cmd := range cmds {
    55  			if !f(string(cmd)) {
    56  				break
    57  			}
    58  		}
    59  	*/
    60  }
    61  
    62  func (hv List) Index(rawIndex interface{}) (interface{}, error) {
    63  	hv.RLock()
    64  	defer hv.RUnlock()
    65  	return nil, nil
    66  	/*
    67  		index, err := vals.ConvertListIndex(rawIndex, hv.Len())
    68  		if err != nil {
    69  			return nil, err
    70  		}
    71  		return nil, nil
    72  
    73  		if index.Slice {
    74  			cmds, err := hv.Daemon.Cmds(index.Lower+1, index.Upper+1)
    75  			if err != nil {
    76  				return nil, err
    77  			}
    78  			l := vals.EmptyList
    79  			for _, cmd := range cmds {
    80  				l = l.Cons(cmd)
    81  			}
    82  			return l, nil
    83  		}
    84  		s, err := hv.Daemon.Cmd(index.Lower + 1)
    85  		return string(s), err
    86  	*/
    87  }
    88  
    89  func maybeThrow(e error) {
    90  	if e != nil {
    91  		util.Throw(e)
    92  	}
    93  }