github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/readline/tabfind.go (about)

     1  package readline
     2  
     3  import "strings"
     4  
     5  func (rl *Instance) backspaceTabFindStr() string {
     6  	if len(rl.tfLine) > 0 {
     7  		rl.tfLine = rl.tfLine[:len(rl.tfLine)-1]
     8  	}
     9  	return rl.updateTabFindStr([]rune{})
    10  }
    11  
    12  func _updateTabFindHelpersStr(rl *Instance) (output string) {
    13  	rl.tabMutex.Unlock()
    14  	output = rl.clearHelpersStr()
    15  	rl.initTabCompletion()
    16  	output += rl.renderHelpersStr()
    17  	return
    18  }
    19  
    20  func (rl *Instance) updateTabFindStr(r []rune) string {
    21  	rl.tfLine = append(rl.tfLine, r...)
    22  
    23  	rl.tabMutex.Lock()
    24  
    25  	if len(rl.tfLine) == 0 {
    26  		rl.hintText = rFindSearchPart
    27  		rl.tfSuggestions = append(rl.tcSuggestions, []string{}...)
    28  		return _updateTabFindHelpersStr(rl)
    29  	}
    30  
    31  	var (
    32  		find findT
    33  		err  error
    34  	)
    35  
    36  	find, rl.rFindSearch, rl.rFindCancel, err = newFuzzyFind(string(rl.tfLine))
    37  	if err != nil {
    38  		rl.tfSuggestions = []string{err.Error()}
    39  		return _updateTabFindHelpersStr(rl)
    40  	}
    41  
    42  	rl.hintText = append(rl.rFindSearch, rl.tfLine...)
    43  	rl.hintText = append(rl.hintText, []rune(seqReset+seqBlink+"_"+seqReset)...)
    44  
    45  	rl.tfSuggestions = make([]string, 0)
    46  	for i := range rl.tcSuggestions {
    47  		if find.MatchString(strings.TrimSpace(rl.tcSuggestions[i])) {
    48  			rl.tfSuggestions = append(rl.tfSuggestions, rl.tcSuggestions[i])
    49  
    50  		} else if rl.tcDisplayType == TabDisplayList && find.MatchString(rl.tcDescriptions[rl.tcSuggestions[i]]) {
    51  			// this is a list so lets also check the descriptions
    52  			rl.tfSuggestions = append(rl.tfSuggestions, rl.tcSuggestions[i])
    53  		}
    54  	}
    55  
    56  	return _updateTabFindHelpersStr(rl)
    57  }
    58  
    59  func (rl *Instance) resetTabFindStr() string {
    60  	rl.modeTabFind = false
    61  	rl.tfLine = []rune{}
    62  	if rl.modeAutoFind {
    63  		rl.hintText = []rune{}
    64  	} else {
    65  		rl.hintText = rl.rFindCancel
    66  	}
    67  	rl.modeAutoFind = false
    68  
    69  	output := rl.clearHelpersStr()
    70  	rl.initTabCompletion()
    71  	output += rl.renderHelpersStr()
    72  	return output
    73  }