terminal_bind_arrow(): * Bind the arrow keys */
| 1150 | * Bind the arrow keys |
| 1151 | */ |
| 1152 | protected void |
| 1153 | terminal_bind_arrow(EditLine *el) |
| 1154 | { |
| 1155 | el_action_t *map; |
| 1156 | const el_action_t *dmap; |
| 1157 | int i, j; |
| 1158 | char *p; |
| 1159 | funckey_t *arrow = el->el_terminal.t_fkey; |
| 1160 | |
| 1161 | /* Check if the components needed are initialized */ |
| 1162 | if (el->el_terminal.t_buf == NULL || el->el_map.key == NULL) |
| 1163 | return; |
| 1164 | |
| 1165 | map = el->el_map.type == MAP_VI ? el->el_map.alt : el->el_map.key; |
| 1166 | dmap = el->el_map.type == MAP_VI ? el->el_map.vic : el->el_map.emacs; |
| 1167 | |
| 1168 | terminal_reset_arrow(el); |
| 1169 | |
| 1170 | for (i = 0; i < A_K_NKEYS; i++) { |
| 1171 | Char wt_str[VISUAL_WIDTH_MAX]; |
| 1172 | Char *px; |
| 1173 | size_t n; |
| 1174 | |
| 1175 | p = el->el_terminal.t_str[arrow[i].key]; |
| 1176 | if (!p || !*p) |
| 1177 | continue; |
| 1178 | for (n = 0; n < VISUAL_WIDTH_MAX && p[n]; ++n) |
| 1179 | wt_str[n] = p[n]; |
| 1180 | while (n < VISUAL_WIDTH_MAX) |
| 1181 | wt_str[n++] = '\0'; |
| 1182 | px = wt_str; |
| 1183 | j = (unsigned char) *p; |
| 1184 | /* |
| 1185 | * Assign the arrow keys only if: |
| 1186 | * |
| 1187 | * 1. They are multi-character arrow keys and the user |
| 1188 | * has not re-assigned the leading character, or |
| 1189 | * has re-assigned the leading character to be |
| 1190 | * ED_SEQUENCE_LEAD_IN |
| 1191 | * 2. They are single arrow keys pointing to an |
| 1192 | * unassigned key. |
| 1193 | */ |
| 1194 | if (arrow[i].type == XK_NOD) |
| 1195 | keymacro_clear(el, map, px); |
| 1196 | else { |
| 1197 | if (p[1] && (dmap[j] == map[j] || |
| 1198 | map[j] == ED_SEQUENCE_LEAD_IN)) { |
| 1199 | keymacro_add(el, px, &arrow[i].fun, |
| 1200 | arrow[i].type); |
| 1201 | map[j] = ED_SEQUENCE_LEAD_IN; |
| 1202 | } else if (map[j] == ED_UNASSIGNED) { |
| 1203 | keymacro_clear(el, map, px); |
| 1204 | if (arrow[i].type == XK_CMD) |
| 1205 | map[j] = arrow[i].fun.cmd; |
| 1206 | else |
| 1207 | keymacro_add(el, px, &arrow[i].fun, |
| 1208 | arrow[i].type); |
| 1209 | } |
no test coverage detected