From: P. F. Chimento Date: Wed, 20 Apr 2011 15:22:38 +0000 (+0200) Subject: Implement line input echoing X-Git-Tag: v0.9~96 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=e61fa4c92aff9cfcf486308b95610d00754408cf;p=projects%2Fchimara%2Fchimara.git Implement line input echoing --- diff --git a/libchimara/gestalt.c b/libchimara/gestalt.c index 13193fc..22683df 100644 --- a/libchimara/gestalt.c +++ b/libchimara/gestalt.c @@ -116,6 +116,7 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen) case gestalt_GraphicsTransparency: case gestalt_DateTime: case gestalt_UnicodeNorm: + case gestalt_LineInputEcho: return 1; /* Capabilities supported if compiled with GStreamer */ @@ -130,7 +131,6 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen) #endif /* Unsupported capabilities */ - case gestalt_LineInputEcho: case gestalt_LineTerminatorKey: case gestalt_LineTerminators: /* Selector not supported */ diff --git a/libchimara/input.c b/libchimara/input.c index 7f8038c..ff3cfb8 100644 --- a/libchimara/input.c +++ b/libchimara/input.c @@ -624,21 +624,23 @@ finish_text_buffer_line_input(winid_t win, gboolean emit_signal) VALID_WINDOW(win, return 0); g_return_val_if_fail(win->type == wintype_TextBuffer, 0); - GtkTextIter start_iter, end_iter, last_character; + GtkTextIter start_iter, end_iter; GtkTextBuffer *window_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) ); GtkTextMark *input_position = gtk_text_buffer_get_mark(window_buffer, "input_position"); gtk_text_buffer_get_iter_at_mark(window_buffer, &start_iter, input_position); gtk_text_buffer_get_end_iter(window_buffer, &end_iter); - gtk_text_buffer_get_end_iter(window_buffer, &last_character); - gtk_text_iter_backward_cursor_position(&last_character); - gchar* last_char = gtk_text_buffer_get_text(window_buffer, &last_character, &end_iter, FALSE); + gchar *inserted_text = gtk_text_buffer_get_text(window_buffer, &start_iter, &end_iter, FALSE); - if( strchr(last_char, '\n') != NULL ) - gtk_text_iter_backward_cursor_position(&end_iter); + /* If echoing is turned off, remove the text from the window */ + if(!win->echo_line_input) + gtk_text_buffer_delete(window_buffer, &start_iter, &end_iter); - gchar* inserted_text = gtk_text_buffer_get_text(window_buffer, &start_iter, &end_iter, FALSE); + /* Don't include the newline in the input */ + char *last_char = inserted_text + strlen(inserted_text) - 1; + if(*last_char == '\n') + *last_char = '\0'; int chars_written = write_to_window_buffer(win, inserted_text); if(emit_signal) @@ -927,9 +929,13 @@ force_line_input_from_queue(winid_t win, event_t *event) gtk_text_view_set_editable(GTK_TEXT_VIEW(win->widget), FALSE); /* Insert the forced input into the window */ - gtk_text_buffer_get_end_iter(buffer, &end); - gchar *text_to_insert = g_strconcat(text, "\n", NULL); - gtk_text_buffer_insert_with_tags_by_name(buffer, &end, text_to_insert, -1, "default", "input", NULL); + if(win->echo_line_input) + { + gtk_text_buffer_get_end_iter(buffer, &end); + gchar *text_to_insert = g_strconcat(text, "\n", NULL); + gtk_text_buffer_insert_with_tags_by_name(buffer, &end, text_to_insert, -1, "default", "input", NULL); + } + chars_written = finish_text_buffer_line_input(win, TRUE); } else if(win->type == wintype_TextGrid) @@ -1008,6 +1014,11 @@ void glk_set_echo_line_event(winid_t win, glui32 val) { VALID_WINDOW(win, return); + + if(win->type != wintype_TextBuffer) + return; /* Quietly do nothing */ + + win->echo_line_input = val? TRUE : FALSE; } /** diff --git a/libchimara/window.c b/libchimara/window.c index c0b0a0c..25c06bc 100644 --- a/libchimara/window.c +++ b/libchimara/window.c @@ -33,6 +33,7 @@ window_new_common(glui32 rock) win->line_input_buffer = NULL; win->line_input_buffer_unicode = NULL; win->history = NULL; + win->echo_line_input = TRUE; /* Initialise the buffer */ win->buffer = g_string_sized_new(1024); diff --git a/libchimara/window.h b/libchimara/window.h index 1fecb5e..8cd6e7d 100644 --- a/libchimara/window.h +++ b/libchimara/window.h @@ -64,6 +64,7 @@ struct glk_window_struct gboolean mouse_input_requested; GList *history; GList *history_pos; + gboolean echo_line_input; /* Line input field (text grids only) */ glui32 input_length; GtkTextChildAnchor *input_anchor;