...

Source file src/github.com/Azure/go-ansiterm/parser_action_helpers.go

Documentation: github.com/Azure/go-ansiterm

     1  package ansiterm
     2  
     3  import (
     4  	"strconv"
     5  )
     6  
     7  func parseParams(bytes []byte) ([]string, error) {
     8  	paramBuff := make([]byte, 0, 0)
     9  	params := []string{}
    10  
    11  	for _, v := range bytes {
    12  		if v == ';' {
    13  			if len(paramBuff) > 0 {
    14  				// Completed parameter, append it to the list
    15  				s := string(paramBuff)
    16  				params = append(params, s)
    17  				paramBuff = make([]byte, 0, 0)
    18  			}
    19  		} else {
    20  			paramBuff = append(paramBuff, v)
    21  		}
    22  	}
    23  
    24  	// Last parameter may not be terminated with ';'
    25  	if len(paramBuff) > 0 {
    26  		s := string(paramBuff)
    27  		params = append(params, s)
    28  	}
    29  
    30  	return params, nil
    31  }
    32  
    33  func parseCmd(context ansiContext) (string, error) {
    34  	return string(context.currentChar), nil
    35  }
    36  
    37  func getInt(params []string, dflt int) int {
    38  	i := getInts(params, 1, dflt)[0]
    39  	return i
    40  }
    41  
    42  func getInts(params []string, minCount int, dflt int) []int {
    43  	ints := []int{}
    44  
    45  	for _, v := range params {
    46  		i, _ := strconv.Atoi(v)
    47  		// Zero is mapped to the default value in VT100.
    48  		if i == 0 {
    49  			i = dflt
    50  		}
    51  		ints = append(ints, i)
    52  	}
    53  
    54  	if len(ints) < minCount {
    55  		remaining := minCount - len(ints)
    56  		for i := 0; i < remaining; i++ {
    57  			ints = append(ints, dflt)
    58  		}
    59  	}
    60  
    61  	return ints
    62  }
    63  
    64  func (ap *AnsiParser) modeDispatch(param string, set bool) error {
    65  	switch param {
    66  	case "?3":
    67  		return ap.eventHandler.DECCOLM(set)
    68  	case "?6":
    69  		return ap.eventHandler.DECOM(set)
    70  	case "?25":
    71  		return ap.eventHandler.DECTCEM(set)
    72  	}
    73  	return nil
    74  }
    75  
    76  func (ap *AnsiParser) hDispatch(params []string) error {
    77  	if len(params) == 1 {
    78  		return ap.modeDispatch(params[0], true)
    79  	}
    80  
    81  	return nil
    82  }
    83  
    84  func (ap *AnsiParser) lDispatch(params []string) error {
    85  	if len(params) == 1 {
    86  		return ap.modeDispatch(params[0], false)
    87  	}
    88  
    89  	return nil
    90  }
    91  
    92  func getEraseParam(params []string) int {
    93  	param := getInt(params, 0)
    94  	if param < 0 || 3 < param {
    95  		param = 0
    96  	}
    97  
    98  	return param
    99  }
   100  

View as plain text