Skip to content

Commit

Permalink
fix loop
Browse files Browse the repository at this point in the history
  • Loading branch information
daanx committed Jul 28, 2021
1 parent f055dc8 commit 6dce537
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions include/repline.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ void rp_enable_highlight(bool enable);
//
// - info: for example, numbers in the completion menu (`RP_DARKGRAY` by default)
// - diminish: for example, non matching parts in a history search (`RP_LIGHTGRAY` by default)
// - highlight: for example, the matching part in a history search (`RP_WHITE` by default)
// - emphasis: for example, the matching part in a history search (`RP_WHITE` by default)
// - hint: for hints.
//
// Use `RP_COLOR_NONE` to use the default color. (but `RP_COLOR_DEFAULT` for the default terminal text color!)

void rp_set_iface_colors( rp_color_t color_info, rp_color_t color_diminish, rp_color_t color_highlight, rp_color_t color_hint );
void rp_set_iface_colors( rp_color_t color_info, rp_color_t color_diminish, rp_color_t color_emphasis, rp_color_t color_hint );

//--------------------------------------------------------------
// Advanced Completion
Expand Down
2 changes: 1 addition & 1 deletion src/editline.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ static void edit_refresh_hint(rp_env_t* env, editor_t* eb) {
const char* extra_hint = hint;
do {
ssize_t newpos = sbuf_insert_at( sb, extra_hint, pos );
if (newpos <= 0) break;
if (newpos <= pos) break;
pos = newpos;
count = completions_generate(env, env->completions, sbuf_string(sb), pos, 2);
if (count == 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/editline_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void edit_history_search(rp_env_t* env, editor_t* eb, char* initial ) {
sbuf_appendf(eb->extra, 128, "\x1B[%dm%zd. ", env->color_info, hidx);
sbuf_appendf(eb->extra, 128, "\x1B[%dm", env->color_diminish );
sbuf_append_n( eb->extra, hentry, match_pos );
sbuf_appendf(eb->extra, 128, "\x1B[%dm\x1B[4m\x1B[1m", env->color_highlight ); // highlight, underline, bold
sbuf_appendf(eb->extra, 128, "\x1B[%dm\x1B[4m\x1B[1m", env->color_emphasis ); // highlight, underline, bold
sbuf_append_n( eb->extra, hentry + match_pos, match_len );
sbuf_appendf(eb->extra, 128, "\x1B[22m\x1B[24m\x1B[%dm", env->color_diminish ); // normal, no underline, diminish
sbuf_append(eb->extra, hentry + match_pos + match_len );
Expand Down
14 changes: 7 additions & 7 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ struct rp_env_s {
const char* prompt_marker; // the prompt marker (defaults to "> ")
const char* cprompt_marker; // prompt marker for continuation lines (defaults to `prompt_marker`)
rp_color_t prompt_color; // color used to display the prompt
char multiline_eol; // character used for multiline input ("\")
rp_highlight_fun_t* highlighter; // highlight callback
void* highlighter_arg; // user state for the highlighter.
rp_color_t color_info; // information color, for example numbers in the completion menu. (=RP_DARKGRAY)
rp_color_t color_diminish; // diminish color, for example the non-highlighted part in a history search (=RP_DARKGRAY)
rp_color_t color_emphasis; // highlighted color, for example, the current match in a history search (=RP_DEFAULT_COLOR)
rp_color_t color_hint; // hint color.
char multiline_eol; // character used for multiline input ("\") (set to 0 to disable)
bool initialized; // are we initialized?
bool noedit; // is rich editing possible (tty != NULL)
bool singleline_only; // allow only single line editing?
Expand All @@ -43,12 +49,6 @@ struct rp_env_s {
bool no_help; // show short help line for history search etc.
bool no_hint; // allow hinting?
bool no_highlight; // enable highlighting?
rp_highlight_fun_t* highlighter; // highlight callback
void* highlighter_arg; // user state for the highlighter.
rp_color_t color_info; // information color, for example numbers in the completion menu. (=RP_DARKGRAY)
rp_color_t color_diminish; // diminish color, for example the non-highlighted part in a history search (=RP_DARKGRAY)
rp_color_t color_highlight; // highlighted color, for example, the current match in a history search (=RP_DEFAULT_COLOR)
rp_color_t color_hint; // hint color.
};

rp_private char* rp_editline(rp_env_t* env, const char* prompt_text);
Expand Down
8 changes: 4 additions & 4 deletions src/repline.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ rp_public void rp_set_highlighter(rp_highlight_fun_t* highlighter, void* arg) {
env->highlighter_arg = arg;
}

static void set_iface_colors(rp_env_t* env, rp_color_t color_info, rp_color_t color_diminish, rp_color_t color_highlight, rp_color_t color_hint) {
static void set_iface_colors(rp_env_t* env, rp_color_t color_info, rp_color_t color_diminish, rp_color_t color_emphasis, rp_color_t color_hint) {
env->color_info = (color_info == RP_COLOR_NONE ? RP_DARKGRAY : color_info);
env->color_diminish = (color_diminish == RP_COLOR_NONE ? RP_LIGHTGRAY : color_diminish);
env->color_highlight = (color_highlight == RP_COLOR_NONE ? RP_WHITE : color_highlight);
env->color_emphasis = (color_emphasis == RP_COLOR_NONE ? RP_WHITE : color_emphasis);
env->color_hint = (color_hint == RP_COLOR_NONE ? RP_DARKGRAY : color_hint);
}

rp_public void rp_set_iface_colors( rp_color_t color_info, rp_color_t color_diminish, rp_color_t color_highlight, rp_color_t color_hint ) {
rp_public void rp_set_iface_colors( rp_color_t color_info, rp_color_t color_diminish, rp_color_t color_emphasis, rp_color_t color_hint ) {
rp_env_t* env = rp_get_env(); if (env==NULL) return;
set_iface_colors(env, color_info, color_diminish, color_highlight, color_hint);
set_iface_colors(env, color_info, color_diminish, color_emphasis, color_hint);
}

rp_public void rp_free( void* p ) {
Expand Down
5 changes: 3 additions & 2 deletions test/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ int main()
// try to auto complete after a completion as long as the completion is unique
rp_enable_auto_tab(true );

rp_set_iface_colors( RP_MAROON, RP_DARKGRAY, RP_YELLOW, RP_TEAL );
// change interface colors (info, diminish, emphasis, hint)
// rp_set_iface_colors( RP_YELLOW, RP_DARKGRAY, RP_WHITE, RP_GREEN );

// run until empty input
char* input;
Expand Down Expand Up @@ -140,7 +141,7 @@ static void highlighter(rp_highlight_env_t* henv, const char* input, void* arg)
}
else if (rp_starts_with(input + i,"//")) { // line comment
rp_highlight_color(henv, i, RP_DARKGRAY);
while (i < len && input[i] != '\n') i++;
while (i < len && input[i] != '\n') { i++; }
}
else {
rp_highlight_color(henv, i, RP_COLOR_DEFAULT); // anything else (including utf8 continuation bytes)
Expand Down

0 comments on commit 6dce537

Please sign in to comment.