parseInput parses char by char the input written to the View. It returns nil while processing ESC sequences. Otherwise, it returns a cell slice that contains the processed data.
(ch []byte, width int, x int, _ int)
| 937 | // while processing ESC sequences. Otherwise, it returns a cell slice that |
| 938 | // contains the processed data. |
| 939 | func (v *View) parseInput(ch []byte, width int, x int, _ int) (bool, []cell) { |
| 940 | cells := []cell{} |
| 941 | truncateLine := false |
| 942 | |
| 943 | isEscape, err := v.ei.parseOne(ch) |
| 944 | if err != nil { |
| 945 | for _, chr := range v.ei.characters() { |
| 946 | c := cell{ |
| 947 | fgColor: v.FgColor, |
| 948 | bgColor: v.BgColor, |
| 949 | chr: chr, |
| 950 | width: uniseg.StringWidth(chr), |
| 951 | } |
| 952 | cells = append(cells, c) |
| 953 | } |
| 954 | v.ei.reset() |
| 955 | } else { |
| 956 | repeatCount := 1 |
| 957 | if _, ok := v.ei.instruction.(eraseInLineFromCursor); ok { |
| 958 | // fill rest of line |
| 959 | v.ei.instructionRead() |
| 960 | cx := 0 |
| 961 | for _, cell := range v.lines[v.wy][0:v.wx] { |
| 962 | cx += cell.width |
| 963 | } |
| 964 | repeatCount = v.InnerWidth() - cx |
| 965 | ch = []byte{' '} |
| 966 | width = 1 |
| 967 | truncateLine = true |
| 968 | } else if isEscape { |
| 969 | // do not output anything |
| 970 | return truncateLine, nil |
| 971 | } else if characterEquals(ch, '\t') { |
| 972 | // fill tab-sized space |
| 973 | tabWidth := v.TabWidth |
| 974 | if tabWidth < 1 { |
| 975 | tabWidth = 4 |
| 976 | } |
| 977 | ch = []byte{' '} |
| 978 | width = 1 |
| 979 | repeatCount = tabWidth - (x % tabWidth) |
| 980 | } |
| 981 | c := cell{ |
| 982 | fgColor: v.ei.curFgColor, |
| 983 | bgColor: v.ei.curBgColor, |
| 984 | hyperlink: v.ei.hyperlink.String(), |
| 985 | chr: string(ch), |
| 986 | width: width, |
| 987 | } |
| 988 | for range repeatCount { |
| 989 | cells = append(cells, c) |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | return truncateLine, cells |
| 994 | } |
| 995 | |
| 996 | // Read reads data into p from the current reading position set by SetReadPos. |
no test coverage detected