MCPcopy
hub / github.com/mmulet/term.everything / ConvertKeycodeToXbdCode

Function ConvertKeycodeToXbdCode

termeverything/ConvertKeycodeToXbdCode.go:89–183  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

87}
88
89func ConvertKeycodeToXbdCode(data []byte) []XkbdCode {
90 if len(data) == 1 {
91 if out := KeycodeSingleCodes(int(data[0])); out != nil {
92 return []XkbdCode{out}
93 }
94 return nil
95 }
96 if len(data) == 2 {
97 return parse_length_2(data)
98 }
99 if len(data) == 3 {
100 return parse_length_3(data)
101 }
102 if data[0] == 27 && data[1] == 91 && data[2] == 60 {
103 return ParseSGRMouseSequences(data)
104 }
105
106 if len(data) == 4 {
107 return parse_length_4(data)
108 }
109 if len(data) == 5 {
110 if data[0] == 27 && data[1] == 91 && data[4] == 126 {
111 if data[2] == 49 {
112 if keyCode, ok := f5_through_8_codes[data[3]]; ok {
113 return []XkbdCode{&KeyCode{KeyCode: keyCode, Modifiers: 0}}
114 }
115 }
116 if data[2] == 50 {
117 if keyCode, ok := f9_through_12_codes[data[3]]; ok {
118 return []XkbdCode{&KeyCode{KeyCode: keyCode, Modifiers: 0}}
119 }
120 }
121 }
122 }
123
124 if len(data)%6 == 0 {
125 out := make([]XkbdCode, 0)
126 numEvents := len(data) / 6
127 for i := range numEvents {
128 slice := data[i*6 : (i+1)*6]
129 if slice[0] == 27 && slice[1] == 91 && slice[3] == 59 {
130 switch slice[2] {
131 case 49: // '1'
132 if modifiers := modifiers_for_arrow_and_page_up_etc(slice[4]); modifiers > 0 {
133 eventOut := parse_length_3([]byte{27, 91, slice[5]})
134 if len(eventOut) > 0 {
135 for _, e := range eventOut {
136 e.OrModifiers(modifiers)
137 }
138 out = append(out, eventOut...)
139 continue
140 }
141 }
142 case 50, 51, 52, 53, 54: // '2'..'6'
143 if modifiers := modifiers_for_arrow_and_page_up_etc(slice[4]); slice[5] == 126 && modifiers > 0 {
144 eventOut := parse_length_4([]byte{27, 91, slice[2], 126})
145 if len(eventOut) > 0 {
146 for _, e := range eventOut {

Callers 1

InputLoopMethod · 0.85

Calls 7

KeycodeSingleCodesFunction · 0.85
parse_length_2Function · 0.85
parse_length_3Function · 0.85
ParseSGRMouseSequencesFunction · 0.85
parse_length_4Function · 0.85
OrModifiersMethod · 0.65

Tested by

no test coverage detected