Source File
iterations.go
Belonging Package
github.com/reeflective/readline/internal/core
package coreimport ()// Iterations manages iterations for commands.type Iterations struct {times string // Stores iteration valueactive bool // Are we currently setting the iterations.pending bool // Has the last command been an iteration one (vi-pending style)}// Add accepts a string to be converted as an integer representing// the number of times some action should be performed.// The times parameter can also be a negative sign, in which case// the iterations value will be negative until those are reset.func ( *Iterations) ( string) {if == "" {return}// Never accept non-digit values.if , := strconv.Atoi(); != nil && != "-" {return}.active = true.pending = trueswitch {case == "-":.times = + .timescase strings.HasPrefix(, "-"):.times = "-" + .times + strings.TrimPrefix(, "-")default:.times +=}}// Get returns the number of iterations (possibly// negative), and resets the iterations to 1.func ( *Iterations) () int {, := strconv.Atoi(.times)// Any invalid value is still one time.if != nil && strings.HasPrefix(.times, "-") {= -1} else if != nil && == 0 {= 1} else if == 0 && strings.HasPrefix(.times, "-") {= -1}// At least one iterationif == 0 {++}.times = ""return}// IsSet returns true if an iteration/numeric argument is active.func ( *Iterations) () bool {return .active}// IsPending returns true if the very last command executed was an// iteration one. This is only meant for the main readline loop/run.func ( *Iterations) () bool {return .pending}// Reset resets the iterations (drops them).func ( *Iterations) () {.times = "".active = false.pending = false}// ResetPostRunIterations resets the iterations if the last command didn't set them.// If the reset operated on active iterations, this function returns true.func ( *Iterations) ( string) {if .pending {= color.Dim + fmt.Sprintf("(arg: %s)", .times)}if .pending {.pending = falsereturn}.active = falsereturn}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |