DNS IP app - GTK+

source code

// dns.vala

public class DNSIPDisplay : Gtk.Application {
    private Gtk.TextView text_view;
    private Gtk.ApplicationWindow window;

    public DNSIPDisplay () {
        Object (application_id: "xyz.vorasilp.gtkdnsip");
    }

    public override void activate () {
        this.window = new Gtk.ApplicationWindow (this) {
            title = "DNS IP",
            default_width = 600,
            default_height = 300
        };

        this.text_view = new Gtk.TextView () {
            editable = false,
            cursor_visible = false,
        };

        var tag = this.text_view.buffer.create_tag("text");
        tag.font = "Sans 18";
        //  Gdk.RGBA red = {1.0f, 0.0f, 0.0f, 1.0f};
        //  tag.foreground_rgba =  red;
        
        
        var scroll_view = new Gtk.ScrolledWindow () {
            hscrollbar_policy = Gtk.PolicyType.AUTOMATIC,
            vscrollbar_policy = Gtk.PolicyType.AUTOMATIC,
            vexpand = true,
            valign = Gtk.Align.FILL,
            child = this.text_view,
            margin_top = 20,
            margin_bottom = 20,
            margin_start = 20,
            margin_end = 20,
        };
        
        var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
        vbox.append (scroll_view);
        
        Gtk.TextIter startIter;
        Gtk.TextIter endIter;

        open_file_and_display ();
        this.text_view.buffer.get_start_iter(out startIter);
        this.text_view.buffer.get_end_iter(out endIter);
        this.text_view.buffer.apply_tag_by_name("text", startIter, endIter);
        
        this.window.child = vbox;
        this.window.present ();
    }

    private void open_file_and_display () {
        try {
            var file = File.new_for_path ("/etc/resolv.conf");
            var dis = new DataInputStream (file.read ());
            string line;
            string output = "";
            // Read lines until end of file (null) is reached
            while ((line = dis.read_line (null)) != null) {
                if (line.get_char() != '#') {
                    output = output.concat(line,"\n");
                }
            }
            this.text_view.buffer.text = output;
        } catch (Error e) {
            stderr.printf ("Error: %s\n", e.message);
        }

    }

    public static int main (string[] args) {
        var app = new DNSIPDisplay ();
        return app.run (args);
    }
}

screenshot Screenshot