#!/usr/bin/perl

use strict;
use warnings;

use Glib qw(TRUE FALSE);
use Gtk2 qw(-init);

my $view = Gtk2::TextView->new();
my $buffer = $view->get_buffer();
$view->set_size_request(850,500);
$view->set_editable (FALSE);
our $textmark = $buffer->create_mark('end_mark',$buffer->get_end_iter,FALSE);
my $scrolls = Gtk2::ScrolledWindow->new();
$scrolls->set_policy('automatic','always');
$scrolls->set_shadow_type('in');
$scrolls->add ($view);


# Click me to add text
my $button = Gtk2::Button->new('Write');
$button->signal_connect(clicked => sub {
  my $text_tag = $buffer->create_tag(undef,'font',"Sans Italic 12",'foreground','#680000');
  $buffer->insert_with_tags($buffer->get_end_iter,"Styled sample\n", $text_tag);
  $buffer->insert($buffer->get_end_iter, "Plain sample\n");
  $view->scroll_mark_onscreen($textmark);
});


# Widget packing
my $vbox = Gtk2::VBox->new();
$vbox->pack_start($button, FALSE, FALSE, 0);
$vbox->pack_start($scrolls, TRUE, TRUE, 0);


my $window = Gtk2::Window->new();
$window->add($vbox);
$window->show_all();
$window->signal_connect(delete_event => sub {Gtk2->main_quit()});


Gtk2->main();
