void highlight(const char *buf, int pos) { char current = buf[pos]; if (current == ']' || current == '}' || current == ')') { int num_lines_up = -1; int highlight_pos = 0; char *buf_copy = malloc((pos + 1) * sizeof(char)); strncpy(buf_copy, buf, pos); buf_copy[pos + 1] = '\0'; cljs_highlight_coords_for_pos(global_ctx, pos, (char*)buf, num_previous_lines, previous_lines, &num_lines_up, &highlight_pos); free(buf_copy); int current_pos = pos + 1; if (num_lines_up != -1) { int relative_horiz = highlight_pos - current_pos; if (num_lines_up != 0) { fprintf(stdout,"\x1b[%dA", num_lines_up); } if (relative_horiz < 0) { fprintf(stdout,"\x1b[%dD", -relative_horiz); } else if (relative_horiz > 0){ fprintf(stdout,"\x1b[%dC", relative_horiz); } fflush(stdout); // struct hl_restore *hl_restore = malloc(sizeof(struct hl_restore)); hl_restore.should_restore = true; hl_restore.num_lines_up = num_lines_up; hl_restore.relative_horiz = relative_horiz; int timeout = 500 * 1000 * 1000; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_t thread; pthread_create(&thread, &attr, do_highlight_restore, (void*)&timeout); } } }
void highlight(const char *buf, int pos) { char current = buf[pos]; if (current == ']' || current == '}' || current == ')') { int num_lines_up = -1; int highlight_pos = 0; cljs_highlight_coords_for_pos(pos, buf, s_repl->num_previous_lines, s_repl->previous_lines, &num_lines_up, &highlight_pos); int current_pos = pos + 1; if (num_lines_up != -1) { int relative_horiz = highlight_pos - current_pos; if (num_lines_up != 0) { fprintf(stdout, "\x1b[%dA", num_lines_up); } if (relative_horiz < 0) { fprintf(stdout, "\x1b[%dD", -relative_horiz); } else if (relative_horiz > 0) { fprintf(stdout, "\x1b[%dC", relative_horiz); } fflush(stdout); struct hl_restore *hl_restore_local = malloc(sizeof(struct hl_restore)); pthread_mutex_lock(&highlight_restore_sequence_mutex); hl_restore_local->id = ++highlight_restore_sequence; pthread_mutex_unlock(&highlight_restore_sequence_mutex); hl_restore_local->num_lines_up = num_lines_up; hl_restore_local->relative_horiz = relative_horiz; hl_restore = *hl_restore_local; start_timer(500, do_highlight_restore, (void *) hl_restore_local); } } }