Getting GtkSourceBuffer * as string

Hello guys,

I am trying to print GtkSourceBuffer to console. Snippet of the code is as following ;

GtkSourceView *view;
GtkSourceBuffer *buffer;

view = GTK_SOURCE_VIEW (gtk_source_view_new());
buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));	

What I really trying to implement is to printf("%s\n", buffer); or a similar action. What is being written to sourceview text input region should be printed to console in real-time. I went through documentation and could not find any useful directive to achieve this kind of task. What should I add or do to do this can anyone provide insight ?

Thank you,

Check the documentation for Gtk.TextBuffer, which is the widget from which Gtk.SourceBuffer is derived. More specifically the get_text method. Follow the link:

To achieve what you want, you must create a function that obtains the text from the buffer via get_text and prints it to the console, then you must connect this function to the buffer’s insert-text signal.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.