From: Marijn van Vliet Date: Mon, 7 Feb 2011 14:55:37 +0000 (+0100) Subject: Fixing #15: handling newlines in textgrids X-Git-Tag: v0.9~140 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=d46503e2c419d4c1235f76d98b889fc1cad2d856;p=projects%2Fchimara%2Fchimara.git Fixing #15: handling newlines in textgrids --- diff --git a/libchimara/strio.c b/libchimara/strio.c index d440832..ab8443f 100644 --- a/libchimara/strio.c +++ b/libchimara/strio.c @@ -220,6 +220,44 @@ write_buffer_to_stream(strid_t str, gchar *buf, glui32 len) /* Text grid/buffer windows */ case wintype_TextGrid: + { + gchar *utf8 = convert_latin1_to_utf8(buf, len); + if(utf8 != NULL) { + /* Deal with newlines */ + int i; + gchar *line = utf8; + for(i=0; iwindow, line); + flush_window_buffer(str->window); + + /* Move cursor position forward to the next line */ + gdk_threads_enter(); + GtkTextIter cursor_pos; + GtkTextView *textview = GTK_TEXT_VIEW(str->window->widget); + GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview); + GtkTextMark *cursor_mark = gtk_text_buffer_get_mark(buffer, "cursor_position"); + + gtk_text_buffer_get_iter_at_mark( buffer, &cursor_pos, cursor_mark); + gtk_text_view_forward_display_line(textview, &cursor_pos); + gtk_text_view_backward_display_line_start(textview, &cursor_pos); + gtk_text_buffer_move_mark(buffer, cursor_mark, &cursor_pos); + gdk_threads_leave(); + + line = utf8 + (i < len-1 ? (i+1):(len-1)); + } + } + + /* No more newlines left. */ + write_utf8_to_window_buffer(str->window, line); + g_free(utf8); + } + + str->write_count += len; + } + break; + case wintype_TextBuffer: { gchar *utf8 = convert_latin1_to_utf8(buf, len); diff --git a/tests/gridtest.c b/tests/gridtest.c index 5980494..7f25db1 100644 --- a/tests/gridtest.c +++ b/tests/gridtest.c @@ -3,6 +3,7 @@ #include #include #include +#include void glk_main(void) { @@ -19,12 +20,37 @@ void glk_main(void) glk_put_string("Window not big enough"); glk_exit(); } - x = width / 2 - 10; - y = height / 2; - + char *buffer = calloc(256, sizeof(char)); assert(buffer); + garglk_set_reversevideo(1); + for(y=0; y