#include <gtk/gtk.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#include "support.h"

void InsertText(GtkWidget *output,char* text) {
    GtkTextIter *iter=malloc(sizeof(GtkTextIter));
    char *textln=malloc((strlen(text)+3)*sizeof(char));
    GtkTextMark *mark;

    strcpy(textln,text);
    strcat(textln,"\n\r\0");
    gtk_text_buffer_get_end_iter(gtk_text_view_get_buffer(GTK_TEXT_VIEW(output)),iter);
    gtk_text_buffer_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(output)),iter,textln,-1);

    mark=gtk_text_buffer_get_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(output)));
    gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(output),mark,0,FALSE,1,1);
    gtk_widget_queue_draw(output);

    free(textln);
    gtk_text_iter_free(iter);
}
