/* gitg-result-dialog.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-result-dialog.vala, do not modify */

/*
 * This file is part of gitg
 *
 * Copyright (C) 2026 - Alberto Fanjul
 *
 * gitg is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * gitg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pango.h>
#include <gobject/gvaluecollector.h>
#include "config.h"
#include <gdk/gdk.h>
#include <gio/gio.h>
#include <stdio.h>

#define GITG_RESULT_DIALOG_version VERSION
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define GITG_TYPE_ANSI_RENDERER (gitg_ansi_renderer_get_type ())
#define GITG_ANSI_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_ANSI_RENDERER, GitgAnsiRenderer))
#define GITG_ANSI_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GITG_TYPE_ANSI_RENDERER, GitgAnsiRendererClass))
#define GITG_IS_ANSI_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GITG_TYPE_ANSI_RENDERER))
#define GITG_IS_ANSI_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GITG_TYPE_ANSI_RENDERER))
#define GITG_ANSI_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GITG_TYPE_ANSI_RENDERER, GitgAnsiRendererClass))

typedef struct _GitgAnsiRenderer GitgAnsiRenderer;
typedef struct _GitgAnsiRendererClass GitgAnsiRendererClass;
typedef struct _GitgAnsiRendererPrivate GitgAnsiRendererPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _GitgParamSpecAnsiRenderer GitgParamSpecAnsiRenderer;

#define GITG_TYPE_RESULT_DIALOG (gitg_result_dialog_get_type ())
#define GITG_RESULT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_RESULT_DIALOG, GitgResultDialog))
#define GITG_RESULT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GITG_TYPE_RESULT_DIALOG, GitgResultDialogClass))
#define GITG_IS_RESULT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GITG_TYPE_RESULT_DIALOG))
#define GITG_IS_RESULT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GITG_TYPE_RESULT_DIALOG))
#define GITG_RESULT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GITG_TYPE_RESULT_DIALOG, GitgResultDialogClass))

typedef struct _GitgResultDialog GitgResultDialog;
typedef struct _GitgResultDialogClass GitgResultDialogClass;
typedef struct _GitgResultDialogPrivate GitgResultDialogPrivate;
enum  {
	GITG_RESULT_DIALOG_0_PROPERTY,
	GITG_RESULT_DIALOG_NUM_PROPERTIES
};
static GParamSpec* gitg_result_dialog_properties[GITG_RESULT_DIALOG_NUM_PROPERTIES];
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _gitg_ansi_renderer_unref0(var) ((var == NULL) ? NULL : (var = (gitg_ansi_renderer_unref (var), NULL)))
#define __vala_PangoFontDescription_free0(var) ((var == NULL) ? NULL : (var = (_vala_PangoFontDescription_free (var), NULL)))
typedef struct _Block82Data Block82Data;
#define _g_match_info_unref0(var) ((var == NULL) ? NULL : (var = (g_match_info_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GitgAnsiRenderer {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GitgAnsiRendererPrivate * priv;
};

struct _GitgAnsiRendererClass {
	GTypeClass parent_class;
	void (*finalize) (GitgAnsiRenderer *self);
};

struct _GitgAnsiRendererPrivate {
	GtkTextBuffer* buf;
	GHashTable* tags;
};

struct _GitgParamSpecAnsiRenderer {
	GParamSpec parent_instance;
};

struct _GitgResultDialog {
	GtkDialog parent_instance;
	GitgResultDialogPrivate * priv;
};

struct _GitgResultDialogClass {
	GtkDialogClass parent_class;
};

struct _GitgResultDialogPrivate {
	GtkButton* d_button_close;
	GtkTextView* d_text_view_message;
	GtkLabel* d_label_result;
	GtkButton* d_button_copy;
	GtkSwitch* switch_remove_ansi;
	GtkTextBuffer* buf;
	GtkTextView* tv;
	GRegex* url_reg;
	guint timer_id;
	GitgAnsiRenderer* ansiRenderer;
	gchar* original_message;
	gboolean filter_ansi;
};

struct _Block82Data {
	int _ref_count_;
	GitgResultDialog* self;
	GList* to_remove;
};

static gint GitgAnsiRenderer_private_offset;
static gpointer gitg_ansi_renderer_parent_class = NULL;
static gint GitgResultDialog_private_offset;
static gpointer gitg_result_dialog_parent_class = NULL;
static GRegex* gitg_result_dialog_regex_remove_ansi;
static GRegex* gitg_result_dialog_regex_remove_ansi = NULL;

VALA_EXTERN gpointer gitg_ansi_renderer_ref (gpointer instance);
VALA_EXTERN void gitg_ansi_renderer_unref (gpointer instance);
VALA_EXTERN GParamSpec* gitg_param_spec_ansi_renderer (const gchar* name,
                                           const gchar* nick,
                                           const gchar* blurb,
                                           GType object_type,
                                           GParamFlags flags);
VALA_EXTERN void gitg_value_set_ansi_renderer (GValue* value,
                                   gpointer v_object);
VALA_EXTERN void gitg_value_take_ansi_renderer (GValue* value,
                                    gpointer v_object);
VALA_EXTERN gpointer gitg_value_get_ansi_renderer (const GValue* value);
VALA_EXTERN GType gitg_ansi_renderer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GitgAnsiRenderer, gitg_ansi_renderer_unref)
VALA_EXTERN GitgAnsiRenderer* gitg_ansi_renderer_new (GtkTextBuffer* buf);
VALA_EXTERN GitgAnsiRenderer* gitg_ansi_renderer_construct (GType object_type,
                                                GtkTextBuffer* buf);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
static GtkTextTag* gitg_ansi_renderer_get_tag (GitgAnsiRenderer* self,
                                        gboolean bold,
                                        gboolean underline,
                                        gint fg);
VALA_EXTERN void gitg_ansi_renderer_render_ansi (GitgAnsiRenderer* self,
                                     const gchar* s);
static void gitg_ansi_renderer_insert_with_tag (GitgAnsiRenderer* self,
                                         const gchar* text,
                                         gboolean bold,
                                         gboolean underline,
                                         gint fg);
static void gitg_ansi_renderer_finalize (GitgAnsiRenderer * obj);
static GType gitg_ansi_renderer_get_type_once (void);
VALA_EXTERN GType gitg_result_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GitgResultDialog, g_object_unref)
VALA_EXTERN GitgResultDialog* gitg_result_dialog_new (GtkWindow* parent,
                                          const gchar* title,
                                          const gchar* label_text);
VALA_EXTERN GitgResultDialog* gitg_result_dialog_construct (GType object_type,
                                                GtkWindow* parent,
                                                const gchar* title,
                                                const gchar* label_text);
static void __lambda111_ (GitgResultDialog* self);
static gboolean __lambda112_ (GitgResultDialog* self);
static void gitg_result_dialog_highlight_links (GitgResultDialog* self);
static gboolean ___lambda112__gsource_func (gpointer self);
static void ___lambda111__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                            gpointer self);
static gboolean gitg_result_dialog_on_hover_link (GitgResultDialog* self,
                                           GdkEventMotion* ev);
static gboolean _gitg_result_dialog_on_hover_link_gtk_widget_motion_notify_event (GtkWidget* _sender,
                                                                           GdkEventMotion* event,
                                                                           gpointer self);
static gboolean gitg_result_dialog_on_link_press (GitgResultDialog* self,
                                           GdkEventButton* ev);
static gboolean _gitg_result_dialog_on_link_press_gtk_widget_button_press_event (GtkWidget* _sender,
                                                                          GdkEventButton* event,
                                                                          gpointer self);
static gboolean gitg_result_dialog_on_key_press (GitgResultDialog* self,
                                          GdkEventKey* event);
static gboolean _gitg_result_dialog_on_key_press_gtk_widget_key_press_event (GtkWidget* _sender,
                                                                      GdkEventKey* event,
                                                                      gpointer self);
static void __lambda114_ (GitgResultDialog* self);
static void gitg_result_dialog_copy_all_text (GitgResultDialog* self);
static void ___lambda114__gtk_button_clicked (GtkButton* _sender,
                                       gpointer self);
static void __lambda115_ (GitgResultDialog* self);
VALA_EXTERN void gitg_result_dialog_render (GitgResultDialog* self);
static void ___lambda115__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
static void _vala_PangoFontDescription_free (PangoFontDescription* self);
VALA_EXTERN gchar* gitg_result_dialog_remove_ansi (const gchar* text);
VALA_EXTERN gint gitg_result_dialog_byte_to_char_offset (const gchar* str,
                                             gint byte_offset);
static Block82Data* block82_data_ref (Block82Data* _data82_);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void block82_data_unref (void * _userdata_);
static void __lambda113_ (Block82Data* _data82_,
                   GtkTextTag* t);
static void ___lambda113__gtk_text_tag_table_foreach (GtkTextTag* tag,
                                               gpointer self);
static gboolean gitg_result_dialog_get_iter_at_event (GitgResultDialog* self,
                                               gint ex,
                                               gint ey,
                                               GtkTextIter* iter);
VALA_EXTERN void gitg_result_dialog_append_message (GitgResultDialog* self,
                                        const gchar* message);
VALA_EXTERN void gitg_result_dialog_clear_messages (GitgResultDialog* self);
static void gitg_result_dialog_finalize (GObject * obj);
static GType gitg_result_dialog_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

static inline gpointer
gitg_ansi_renderer_get_instance_private (GitgAnsiRenderer* self)
{
	return G_STRUCT_MEMBER_P (self, GitgAnsiRenderer_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

GitgAnsiRenderer*
gitg_ansi_renderer_construct (GType object_type,
                              GtkTextBuffer* buf)
{
	GitgAnsiRenderer* self = NULL;
	GtkTextBuffer* _tmp0_;
	GHashFunc _tmp1_;
	GEqualFunc _tmp2_;
	GHashTable* _tmp3_;
	g_return_val_if_fail (buf != NULL, NULL);
	self = (GitgAnsiRenderer*) g_type_create_instance (object_type);
	_tmp0_ = _g_object_ref0 (buf);
	_g_object_unref0 (self->priv->buf);
	self->priv->buf = _tmp0_;
	_tmp1_ = g_str_hash;
	_tmp2_ = g_str_equal;
	_tmp3_ = g_hash_table_new_full (_tmp1_, _tmp2_, _g_free0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->tags);
	self->priv->tags = _tmp3_;
	return self;
}

GitgAnsiRenderer*
gitg_ansi_renderer_new (GtkTextBuffer* buf)
{
	return gitg_ansi_renderer_construct (GITG_TYPE_ANSI_RENDERER, buf);
}

static GtkTextTag*
gitg_ansi_renderer_get_tag (GitgAnsiRenderer* self,
                            gboolean bold,
                            gboolean underline,
                            gint fg)
{
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	gchar* key = NULL;
	gchar* _tmp2_;
	GtkTextTag* t = NULL;
	GHashTable* _tmp3_;
	const gchar* _tmp4_;
	gconstpointer _tmp5_;
	GtkTextTag* _tmp6_;
	GtkTextTag* _tmp7_;
	const gchar* _tmp8_;
	GtkTextTag* _tmp9_;
	GtkTextBuffer* _tmp21_;
	GtkTextTagTable* _tmp22_;
	GtkTextTag* _tmp23_;
	GHashTable* _tmp24_;
	const gchar* _tmp25_;
	gchar* _tmp26_;
	GtkTextTag* _tmp27_;
	GtkTextTag* _tmp28_;
	GtkTextTag* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (bold) {
		_tmp0_ = 1;
	} else {
		_tmp0_ = 0;
	}
	if (underline) {
		_tmp1_ = 1;
	} else {
		_tmp1_ = 0;
	}
	_tmp2_ = g_strdup_printf ("%d:%d:%d", _tmp0_, _tmp1_, fg);
	key = _tmp2_;
	_tmp3_ = self->priv->tags;
	_tmp4_ = key;
	_tmp5_ = g_hash_table_lookup (_tmp3_, _tmp4_);
	_tmp6_ = _g_object_ref0 ((GtkTextTag*) _tmp5_);
	t = _tmp6_;
	_tmp7_ = t;
	if (_tmp7_ != NULL) {
		result = t;
		_g_free0 (key);
		return result;
	}
	_tmp8_ = key;
	_tmp9_ = gtk_text_tag_new (_tmp8_);
	_g_object_unref0 (t);
	t = _tmp9_;
	if (bold) {
		GtkTextTag* _tmp10_;
		_tmp10_ = t;
		g_object_set (_tmp10_, "weight", (gint) PANGO_WEIGHT_BOLD, NULL);
	}
	if (underline) {
		GtkTextTag* _tmp11_;
		_tmp11_ = t;
		g_object_set (_tmp11_, "underline", PANGO_UNDERLINE_SINGLE, NULL);
	}
	if (fg != -1) {
		GtkTextTag* _tmp20_;
		switch (fg) {
			case 30:
			{
				GtkTextTag* _tmp12_;
				_tmp12_ = t;
				g_object_set (_tmp12_, "foreground", "black", NULL);
				break;
			}
			case 31:
			{
				GtkTextTag* _tmp13_;
				_tmp13_ = t;
				g_object_set (_tmp13_, "foreground", "red", NULL);
				break;
			}
			case 32:
			{
				GtkTextTag* _tmp14_;
				_tmp14_ = t;
				g_object_set (_tmp14_, "foreground", "green", NULL);
				break;
			}
			case 33:
			{
				GtkTextTag* _tmp15_;
				_tmp15_ = t;
				g_object_set (_tmp15_, "foreground", "yellow", NULL);
				break;
			}
			case 34:
			{
				GtkTextTag* _tmp16_;
				_tmp16_ = t;
				g_object_set (_tmp16_, "foreground", "blue", NULL);
				break;
			}
			case 35:
			{
				GtkTextTag* _tmp17_;
				_tmp17_ = t;
				g_object_set (_tmp17_, "foreground", "magenta", NULL);
				break;
			}
			case 36:
			{
				GtkTextTag* _tmp18_;
				_tmp18_ = t;
				g_object_set (_tmp18_, "foreground", "cyan", NULL);
				break;
			}
			case 37:
			{
				GtkTextTag* _tmp19_;
				_tmp19_ = t;
				g_object_set (_tmp19_, "foreground", "white", NULL);
				break;
			}
			default:
			{
				break;
			}
		}
		_tmp20_ = t;
		g_object_set (_tmp20_, "foreground-set", TRUE, NULL);
	}
	_tmp21_ = self->priv->buf;
	_tmp22_ = gtk_text_buffer_get_tag_table (_tmp21_);
	_tmp23_ = t;
	gtk_text_tag_table_add (_tmp22_, _tmp23_);
	_tmp24_ = self->priv->tags;
	_tmp25_ = key;
	_tmp26_ = g_strdup (_tmp25_);
	_tmp27_ = t;
	_tmp28_ = _g_object_ref0 (_tmp27_);
	g_hash_table_insert (_tmp24_, _tmp26_, _tmp28_);
	result = t;
	_g_free0 (key);
	return result;
}

static gint
string_index_of (const gchar* self,
                 const gchar* needle,
                 gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

void
gitg_ansi_renderer_render_ansi (GitgAnsiRenderer* self,
                                const gchar* s)
{
	GtkTextBuffer* _tmp0_;
	gint len = 0;
	gint _tmp1_;
	gint _tmp2_;
	gint p = 0;
	gboolean bold = FALSE;
	gboolean underline = FALSE;
	gint fg = 0;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (s != NULL);
	_tmp0_ = self->priv->buf;
	gtk_text_buffer_set_text (_tmp0_, "", -1);
	_tmp1_ = strlen (s);
	_tmp2_ = _tmp1_;
	len = _tmp2_;
	p = 0;
	bold = FALSE;
	underline = FALSE;
	fg = -1;
	while (TRUE) {
		gint escpos = 0;
		gboolean _tmp7_ = FALSE;
		if (!(p < len)) {
			break;
		}
		escpos = string_index_of (s, "\u001b", p);
		if (escpos < 0) {
			gchar* seg = NULL;
			gchar* _tmp3_;
			const gchar* _tmp4_;
			_tmp3_ = string_substring (s, (glong) p, (glong) (len - p));
			seg = _tmp3_;
			_tmp4_ = seg;
			gitg_ansi_renderer_insert_with_tag (self, _tmp4_, bold, underline, fg);
			_g_free0 (seg);
			break;
		}
		if (escpos > p) {
			gchar* seg = NULL;
			gchar* _tmp5_;
			const gchar* _tmp6_;
			_tmp5_ = string_substring (s, (glong) p, (glong) (escpos - p));
			seg = _tmp5_;
			_tmp6_ = seg;
			gitg_ansi_renderer_insert_with_tag (self, _tmp6_, bold, underline, fg);
			_g_free0 (seg);
		}
		if ((escpos + 1) < len) {
			_tmp7_ = string_get (s, (glong) (escpos + 1)) == '[';
		} else {
			_tmp7_ = FALSE;
		}
		if (_tmp7_) {
			gint mpos = 0;
			gchar* code = NULL;
			gchar* _tmp10_;
			const gchar* _tmp11_;
			gint _tmp12_;
			gint _tmp13_;
			gchar** parts = NULL;
			const gchar* _tmp15_;
			gchar** _tmp16_;
			gchar** _tmp17_;
			gint parts_length1;
			gint _parts_size_;
			gchar** _tmp18_;
			gint _tmp18__length1;
			mpos = string_index_of (s, "m", escpos + 2);
			if (mpos < 0) {
				gchar* seg = NULL;
				gchar* _tmp8_;
				const gchar* _tmp9_;
				_tmp8_ = string_substring (s, (glong) escpos, (glong) (len - escpos));
				seg = _tmp8_;
				_tmp9_ = seg;
				gitg_ansi_renderer_insert_with_tag (self, _tmp9_, bold, underline, fg);
				_g_free0 (seg);
				break;
			}
			_tmp10_ = string_substring (s, (glong) (escpos + 2), (glong) (mpos - (escpos + 2)));
			code = _tmp10_;
			_tmp11_ = code;
			_tmp12_ = strlen (_tmp11_);
			_tmp13_ = _tmp12_;
			if (_tmp13_ == 0) {
				gchar* _tmp14_;
				_tmp14_ = g_strdup ("0");
				_g_free0 (code);
				code = _tmp14_;
			}
			_tmp15_ = code;
			_tmp17_ = _tmp16_ = g_strsplit (_tmp15_, ";", 0);
			parts = _tmp17_;
			parts_length1 = _vala_array_length (_tmp16_);
			_parts_size_ = parts_length1;
			_tmp18_ = parts;
			_tmp18__length1 = parts_length1;
			{
				gchar** part_collection = NULL;
				gint part_collection_length1 = 0;
				gint _part_collection_size_ = 0;
				gint part_it = 0;
				part_collection = _tmp18_;
				part_collection_length1 = _tmp18__length1;
				for (part_it = 0; part_it < part_collection_length1; part_it = part_it + 1) {
					gchar* _tmp19_;
					gchar* part = NULL;
					_tmp19_ = g_strdup (part_collection[part_it]);
					part = _tmp19_;
					{
						gint v = 0;
						v = 0;
						{
							const gchar* _tmp20_;
							_tmp20_ = part;
							v = atoi (_tmp20_);
						}
						goto __finally0;
						__catch0_g_error:
						{
							g_clear_error (&_inner_error0_);
							v = -1;
						}
						__finally0:
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_free0 (part);
							parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
							_g_free0 (code);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (v == 0) {
							bold = FALSE;
							underline = FALSE;
							fg = -1;
						} else {
							if (v == 1) {
								bold = TRUE;
							} else {
								if (v == 4) {
									underline = TRUE;
								} else {
									gboolean _tmp21_ = FALSE;
									if (v >= 30) {
										_tmp21_ = v <= 37;
									} else {
										_tmp21_ = FALSE;
									}
									if (_tmp21_) {
										fg = v;
									} else {
										if (v == 39) {
											fg = -1;
										} else {
											if (v == 22) {
												bold = FALSE;
											} else {
												if (v == 24) {
													underline = FALSE;
												} else {
												}
											}
										}
									}
								}
							}
						}
						_g_free0 (part);
					}
				}
			}
			p = mpos + 1;
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (code);
			continue;
		} else {
			g_print ("unsupported ");
			gitg_ansi_renderer_insert_with_tag (self, "\u001b", bold, underline, fg);
			p = escpos + 1;
		}
	}
}

static void
gitg_ansi_renderer_insert_with_tag (GitgAnsiRenderer* self,
                                    const gchar* text,
                                    gboolean bold,
                                    gboolean underline,
                                    gint fg)
{
	gint _tmp0_;
	gint _tmp1_;
	GtkTextIter start = {0};
	GtkTextBuffer* _tmp2_;
	GtkTextIter _tmp3_ = {0};
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	_tmp0_ = strlen (text);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == 0) {
		return;
	}
	_tmp2_ = self->priv->buf;
	gtk_text_buffer_get_end_iter (_tmp2_, &_tmp3_);
	start = _tmp3_;
	if (bold) {
		_tmp5_ = TRUE;
	} else {
		_tmp5_ = underline;
	}
	if (_tmp5_) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = fg != -1;
	}
	if (_tmp4_) {
		GtkTextTag* t = NULL;
		GtkTextTag* _tmp6_;
		GtkTextBuffer* _tmp7_;
		GtkTextTag* _tmp8_;
		_tmp6_ = gitg_ansi_renderer_get_tag (self, bold, underline, fg);
		t = _tmp6_;
		_tmp7_ = self->priv->buf;
		_tmp8_ = t;
		gtk_text_buffer_insert_with_tags (_tmp7_, &start, text, -1, _tmp8_, NULL);
		_g_object_unref0 (t);
	} else {
		GtkTextBuffer* _tmp9_;
		_tmp9_ = self->priv->buf;
		gtk_text_buffer_insert (_tmp9_, &start, text, -1);
	}
}

static void
gitg_value_ansi_renderer_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
gitg_value_ansi_renderer_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		gitg_ansi_renderer_unref (value->data[0].v_pointer);
	}
}

static void
gitg_value_ansi_renderer_copy_value (const GValue* src_value,
                                     GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = gitg_ansi_renderer_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
gitg_value_ansi_renderer_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
gitg_value_ansi_renderer_collect_value (GValue* value,
                                        guint n_collect_values,
                                        GTypeCValue* collect_values,
                                        guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		GitgAnsiRenderer * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = gitg_ansi_renderer_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
gitg_value_ansi_renderer_lcopy_value (const GValue* value,
                                      guint n_collect_values,
                                      GTypeCValue* collect_values,
                                      guint collect_flags)
{
	GitgAnsiRenderer ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = gitg_ansi_renderer_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
gitg_param_spec_ansi_renderer (const gchar* name,
                               const gchar* nick,
                               const gchar* blurb,
                               GType object_type,
                               GParamFlags flags)
{
	GitgParamSpecAnsiRenderer* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GITG_TYPE_ANSI_RENDERER), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
gitg_value_get_ansi_renderer (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GITG_TYPE_ANSI_RENDERER), NULL);
	return value->data[0].v_pointer;
}

void
gitg_value_set_ansi_renderer (GValue* value,
                              gpointer v_object)
{
	GitgAnsiRenderer * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GITG_TYPE_ANSI_RENDERER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GITG_TYPE_ANSI_RENDERER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		gitg_ansi_renderer_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		gitg_ansi_renderer_unref (old);
	}
}

void
gitg_value_take_ansi_renderer (GValue* value,
                               gpointer v_object)
{
	GitgAnsiRenderer * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GITG_TYPE_ANSI_RENDERER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GITG_TYPE_ANSI_RENDERER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		gitg_ansi_renderer_unref (old);
	}
}

static void
gitg_ansi_renderer_class_init (GitgAnsiRendererClass * klass,
                               gpointer klass_data)
{
	gitg_ansi_renderer_parent_class = g_type_class_peek_parent (klass);
	((GitgAnsiRendererClass *) klass)->finalize = gitg_ansi_renderer_finalize;
	g_type_class_adjust_private_offset (klass, &GitgAnsiRenderer_private_offset);
}

static void
gitg_ansi_renderer_instance_init (GitgAnsiRenderer * self,
                                  gpointer klass)
{
	self->priv = gitg_ansi_renderer_get_instance_private (self);
	self->ref_count = 1;
}

static void
gitg_ansi_renderer_finalize (GitgAnsiRenderer * obj)
{
	GitgAnsiRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_ANSI_RENDERER, GitgAnsiRenderer);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->buf);
	_g_hash_table_unref0 (self->priv->tags);
}

 G_GNUC_NO_INLINE static GType
gitg_ansi_renderer_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { gitg_value_ansi_renderer_init, gitg_value_ansi_renderer_free_value, gitg_value_ansi_renderer_copy_value, gitg_value_ansi_renderer_peek_pointer, "p", gitg_value_ansi_renderer_collect_value, "p", gitg_value_ansi_renderer_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GitgAnsiRendererClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_ansi_renderer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgAnsiRenderer), 0, (GInstanceInitFunc) gitg_ansi_renderer_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType gitg_ansi_renderer_type_id;
	gitg_ansi_renderer_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GitgAnsiRenderer", &g_define_type_info, &g_define_type_fundamental_info, 0);
	GitgAnsiRenderer_private_offset = g_type_add_instance_private (gitg_ansi_renderer_type_id, sizeof (GitgAnsiRendererPrivate));
	return gitg_ansi_renderer_type_id;
}

GType
gitg_ansi_renderer_get_type (void)
{
	static gsize gitg_ansi_renderer_type_id__once = 0;
	if (g_once_init_enter (&gitg_ansi_renderer_type_id__once)) {
		GType gitg_ansi_renderer_type_id;
		gitg_ansi_renderer_type_id = gitg_ansi_renderer_get_type_once ();
		g_once_init_leave (&gitg_ansi_renderer_type_id__once, gitg_ansi_renderer_type_id);
	}
	return gitg_ansi_renderer_type_id__once;
}

gpointer
gitg_ansi_renderer_ref (gpointer instance)
{
	GitgAnsiRenderer * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
gitg_ansi_renderer_unref (gpointer instance)
{
	GitgAnsiRenderer * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GITG_ANSI_RENDERER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
gitg_result_dialog_get_instance_private (GitgResultDialog* self)
{
	return G_STRUCT_MEMBER_P (self, GitgResultDialog_private_offset);
}

static gboolean
__lambda112_ (GitgResultDialog* self)
{
	gboolean result;
	gitg_result_dialog_highlight_links (self);
	self->priv->timer_id = (guint) 0;
	result = FALSE;
	return result;
}

static gboolean
___lambda112__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda112_ ((GitgResultDialog*) self);
	return result;
}

static void
__lambda111_ (GitgResultDialog* self)
{
	if (self->priv->timer_id != ((guint) 0)) {
		g_source_remove (self->priv->timer_id);
		self->priv->timer_id = (guint) 0;
	}
	self->priv->timer_id = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 300, ___lambda112__gsource_func, g_object_ref (self), g_object_unref);
}

static void
___lambda111__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                       gpointer self)
{
	__lambda111_ ((GitgResultDialog*) self);
}

static gboolean
_gitg_result_dialog_on_hover_link_gtk_widget_motion_notify_event (GtkWidget* _sender,
                                                                  GdkEventMotion* event,
                                                                  gpointer self)
{
	gboolean result;
	result = gitg_result_dialog_on_hover_link ((GitgResultDialog*) self, event);
	return result;
}

static gboolean
_gitg_result_dialog_on_link_press_gtk_widget_button_press_event (GtkWidget* _sender,
                                                                 GdkEventButton* event,
                                                                 gpointer self)
{
	gboolean result;
	result = gitg_result_dialog_on_link_press ((GitgResultDialog*) self, event);
	return result;
}

static gboolean
_gitg_result_dialog_on_key_press_gtk_widget_key_press_event (GtkWidget* _sender,
                                                             GdkEventKey* event,
                                                             gpointer self)
{
	gboolean result;
	result = gitg_result_dialog_on_key_press ((GitgResultDialog*) self, event);
	return result;
}

static void
__lambda114_ (GitgResultDialog* self)
{
	gitg_result_dialog_copy_all_text (self);
}

static void
___lambda114__gtk_button_clicked (GtkButton* _sender,
                                  gpointer self)
{
	__lambda114_ ((GitgResultDialog*) self);
}

static void
__lambda115_ (GitgResultDialog* self)
{
	GtkSwitch* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	_tmp0_ = self->priv->switch_remove_ansi;
	_tmp1_ = gtk_switch_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	self->priv->filter_ansi = _tmp2_;
	gitg_result_dialog_render (self);
}

static void
___lambda115__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	__lambda115_ ((GitgResultDialog*) self);
}

static void
_vala_PangoFontDescription_free (PangoFontDescription* self)
{
	g_boxed_free (pango_font_description_get_type (), self);
}

GitgResultDialog*
gitg_result_dialog_construct (GType object_type,
                              GtkWindow* parent,
                              const gchar* title,
                              const gchar* label_text)
{
	GitgResultDialog * self = NULL;
	gchar* _tmp0_;
	GtkButton* _tmp2_;
	GtkStyleContext* _tmp3_;
	GRegex* _tmp4_ = NULL;
	GRegex* _tmp5_;
	GRegex* _tmp6_;
	GtkTextView* _tmp7_;
	GtkTextView* _tmp8_;
	PangoFontDescription* font_desc = NULL;
	PangoFontDescription* _tmp9_;
	GtkTextView* _tmp10_;
	PangoFontDescription* _tmp11_;
	GtkTextView* _tmp12_;
	GtkTextBuffer* _tmp13_;
	GtkTextBuffer* _tmp14_;
	GtkTextBuffer* _tmp15_;
	GitgAnsiRenderer* _tmp16_;
	GtkTextView* _tmp17_;
	GtkTextBuffer* _tmp18_;
	GtkTextView* _tmp19_;
	GtkTextView* _tmp20_;
	GtkButton* _tmp21_;
	GtkSwitch* _tmp22_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (title != NULL, NULL);
	self = (GitgResultDialog*) g_object_new (object_type, "use-header-bar", 1, NULL);
	_tmp0_ = g_strdup ("");
	_g_free0 (self->priv->original_message);
	self->priv->original_message = _tmp0_;
	self->priv->filter_ansi = FALSE;
	if (parent != NULL) {
		gtk_window_set_transient_for ((GtkWindow*) self, parent);
	}
	gtk_window_set_title ((GtkWindow*) self, title);
	if (label_text != NULL) {
		GtkLabel* _tmp1_;
		_tmp1_ = self->priv->d_label_result;
		gtk_label_set_text (_tmp1_, label_text);
	}
	_tmp2_ = self->priv->d_button_close;
	_tmp3_ = gtk_widget_get_style_context ((GtkWidget*) _tmp2_);
	gtk_style_context_add_class (_tmp3_, GTK_STYLE_CLASS_SUGGESTED_ACTION);
	_tmp5_ = g_regex_new ("https?://[^\\s'\"<>]+", 0, 0, &_inner_error0_);
	_tmp4_ = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	_tmp6_ = _tmp4_;
	_tmp4_ = NULL;
	_g_regex_unref0 (self->priv->url_reg);
	self->priv->url_reg = _tmp6_;
	_tmp7_ = self->priv->d_text_view_message;
	_tmp8_ = _g_object_ref0 (_tmp7_);
	_g_object_unref0 (self->priv->tv);
	self->priv->tv = _tmp8_;
	_tmp9_ = pango_font_description_from_string ("Monospace 11");
	font_desc = _tmp9_;
	_tmp10_ = self->priv->tv;
	_tmp11_ = font_desc;
	gtk_widget_override_font ((GtkWidget*) _tmp10_, _tmp11_);
	_tmp12_ = self->priv->tv;
	_tmp13_ = gtk_text_view_get_buffer (_tmp12_);
	_tmp14_ = _g_object_ref0 (_tmp13_);
	_g_object_unref0 (self->priv->buf);
	self->priv->buf = _tmp14_;
	_tmp15_ = self->priv->buf;
	_tmp16_ = gitg_ansi_renderer_new (_tmp15_);
	_gitg_ansi_renderer_unref0 (self->priv->ansiRenderer);
	self->priv->ansiRenderer = _tmp16_;
	_tmp17_ = self->priv->tv;
	gtk_widget_add_events ((GtkWidget*) _tmp17_, (gint) (GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK));
	_tmp18_ = self->priv->buf;
	g_signal_connect_object (_tmp18_, "changed", (GCallback) ___lambda111__gtk_text_buffer_changed, self, 0);
	_tmp19_ = self->priv->tv;
	g_signal_connect_object ((GtkWidget*) _tmp19_, "motion-notify-event", (GCallback) _gitg_result_dialog_on_hover_link_gtk_widget_motion_notify_event, self, 0);
	_tmp20_ = self->priv->tv;
	g_signal_connect_object ((GtkWidget*) _tmp20_, "button-press-event", (GCallback) _gitg_result_dialog_on_link_press_gtk_widget_button_press_event, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "key-press-event", (GCallback) _gitg_result_dialog_on_key_press_gtk_widget_key_press_event, self, 0);
	_tmp21_ = self->priv->d_button_copy;
	g_signal_connect_object (_tmp21_, "clicked", (GCallback) ___lambda114__gtk_button_clicked, self, 0);
	_tmp22_ = self->priv->switch_remove_ansi;
	g_signal_connect_object ((GObject*) _tmp22_, "notify::active", (GCallback) ___lambda115__g_object_notify, self, 0);
	__vala_PangoFontDescription_free0 (font_desc);
	_g_regex_unref0 (_tmp4_);
	return self;
}

GitgResultDialog*
gitg_result_dialog_new (GtkWindow* parent,
                        const gchar* title,
                        const gchar* label_text)
{
	return gitg_result_dialog_construct (GITG_TYPE_RESULT_DIALOG, parent, title, label_text);
}

static gboolean
gitg_result_dialog_on_key_press (GitgResultDialog* self,
                                 GdkEventKey* event)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	if ((event->state & GDK_CONTROL_MASK) != 0) {
		_tmp1_ = (event->state & GDK_SHIFT_MASK) != 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		_tmp0_ = event->keyval == GDK_KEY_c;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gitg_result_dialog_copy_all_text (self);
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static void
gitg_result_dialog_copy_all_text (GitgResultDialog* self)
{
	GtkClipboard* clipboard = NULL;
	GdkDisplay* _tmp0_;
	GtkClipboard* _tmp1_;
	GtkClipboard* _tmp2_;
	gchar* message = NULL;
	GtkClipboard* _tmp7_;
	const gchar* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_display ((GtkWidget*) self);
	_tmp1_ = gtk_clipboard_get_default (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	clipboard = _tmp2_;
	if (self->priv->filter_ansi) {
		const gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = self->priv->original_message;
		_tmp4_ = gitg_result_dialog_remove_ansi (_tmp3_);
		_g_free0 (message);
		message = _tmp4_;
	} else {
		const gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp5_ = self->priv->original_message;
		_tmp6_ = g_strdup (_tmp5_);
		_g_free0 (message);
		message = _tmp6_;
	}
	_tmp7_ = clipboard;
	_tmp8_ = message;
	gtk_clipboard_set_text (_tmp7_, _tmp8_, -1);
	_g_free0 (message);
	_g_object_unref0 (clipboard);
}

static gboolean
string_get_next_char (const gchar* self,
                      gint* index,
                      gunichar* c)
{
	gunichar _vala_c = 0U;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_vala_c = g_utf8_get_char (((gchar*) self) + (*index));
	if (_vala_c != ((gunichar) 0)) {
		gchar* _tmp0_;
		_tmp0_ = g_utf8_next_char (((gchar*) self) + (*index));
		*index = (gint) (_tmp0_ - ((gchar*) self));
		result = TRUE;
		if (c) {
			*c = _vala_c;
		}
		return result;
	} else {
		result = FALSE;
		if (c) {
			*c = _vala_c;
		}
		return result;
	}
}

gint
gitg_result_dialog_byte_to_char_offset (const gchar* str,
                                        gint byte_offset)
{
	gint _tmp0_;
	gint _tmp1_;
	gint char_count = 0;
	gint current_byte = 0;
	gunichar c = 0U;
	gint result;
	g_return_val_if_fail (str != NULL, -1);
	if (byte_offset <= 0) {
		result = 0;
		return result;
	}
	_tmp0_ = strlen (str);
	_tmp1_ = _tmp0_;
	if (byte_offset >= _tmp1_) {
		result = g_utf8_strlen (str, (gssize) -1);
		return result;
	}
	char_count = 0;
	current_byte = 0;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				gunichar _tmp3_ = 0U;
				gboolean _tmp4_;
				gint _tmp5_;
				if (!_tmp2_) {
				}
				_tmp2_ = FALSE;
				_tmp4_ = string_get_next_char (str, &i, &_tmp3_);
				c = _tmp3_;
				if (!_tmp4_) {
					break;
				}
				if (i > byte_offset) {
					break;
				}
				_tmp5_ = char_count;
				char_count = _tmp5_ + 1;
				current_byte = i;
			}
		}
	}
	result = char_count;
	return result;
}

static Block82Data*
block82_data_ref (Block82Data* _data82_)
{
	g_atomic_int_inc (&_data82_->_ref_count_);
	return _data82_;
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static void
block82_data_unref (void * _userdata_)
{
	Block82Data* _data82_;
	_data82_ = (Block82Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data82_->_ref_count_)) {
		GitgResultDialog* self;
		self = _data82_->self;
		(_data82_->to_remove == NULL) ? NULL : (_data82_->to_remove = (_g_list_free__g_object_unref0_ (_data82_->to_remove), NULL));
		_g_object_unref0 (self);
		g_slice_free (Block82Data, _data82_);
	}
}

static void
__lambda113_ (Block82Data* _data82_,
              GtkTextTag* t)
{
	GitgResultDialog* self;
	gchar* name = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	self = _data82_->self;
	g_return_if_fail (t != NULL);
	g_object_get (t, "name", &_tmp0_, NULL);
	_tmp1_ = _tmp0_;
	name = _tmp1_;
	_tmp3_ = name;
	if (_tmp3_ != NULL) {
		const gchar* _tmp4_;
		_tmp4_ = name;
		_tmp2_ = g_str_has_prefix (_tmp4_, "link-");
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		GtkTextTag* _tmp5_;
		_tmp5_ = _g_object_ref0 (t);
		_data82_->to_remove = g_list_append (_data82_->to_remove, _tmp5_);
	}
	_g_free0 (name);
}

static void
___lambda113__gtk_text_tag_table_foreach (GtkTextTag* tag,
                                          gpointer self)
{
	__lambda113_ (self, tag);
}

static void
gitg_result_dialog_highlight_links (GitgResultDialog* self)
{
	Block82Data* _data82_;
	GtkTextTagTable* tt = NULL;
	GtkTextBuffer* _tmp0_;
	GtkTextTagTable* _tmp1_;
	GtkTextTagTable* _tmp2_;
	GtkTextTagTable* _tmp3_;
	GtkTextIter whole_start = {0};
	GtkTextIter whole_end = {0};
	GtkTextBuffer* _tmp4_;
	GtkTextIter _tmp5_ = {0};
	GtkTextBuffer* _tmp6_;
	GtkTextIter _tmp7_ = {0};
	GList* _tmp8_;
	GtkTextIter start = {0};
	GtkTextBuffer* _tmp16_;
	GtkTextIter _tmp17_ = {0};
	GtkTextIter end = {0};
	GtkTextBuffer* _tmp18_;
	GtkTextIter _tmp19_ = {0};
	gchar* text = NULL;
	GtkTextBuffer* _tmp20_;
	GtkTextIter _tmp21_;
	GtkTextIter _tmp22_;
	gchar* _tmp23_;
	GMatchInfo* info = NULL;
	GRegex* _tmp24_;
	const gchar* _tmp25_;
	GMatchInfo* _tmp26_ = NULL;
	gint match_index = 0;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_data82_ = g_slice_new0 (Block82Data);
	_data82_->_ref_count_ = 1;
	_data82_->self = g_object_ref (self);
	_data82_->to_remove = NULL;
	_tmp0_ = self->priv->buf;
	_tmp1_ = gtk_text_buffer_get_tag_table (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	tt = _tmp2_;
	_tmp3_ = tt;
	gtk_text_tag_table_foreach (_tmp3_, ___lambda113__gtk_text_tag_table_foreach, _data82_);
	_tmp4_ = self->priv->buf;
	gtk_text_buffer_get_start_iter (_tmp4_, &_tmp5_);
	whole_start = _tmp5_;
	_tmp6_ = self->priv->buf;
	gtk_text_buffer_get_end_iter (_tmp6_, &_tmp7_);
	whole_end = _tmp7_;
	_tmp8_ = _data82_->to_remove;
	{
		GList* t_collection = NULL;
		GList* t_it = NULL;
		t_collection = _tmp8_;
		for (t_it = t_collection; t_it != NULL; t_it = t_it->next) {
			GtkTextTag* _tmp9_;
			GtkTextTag* t = NULL;
			_tmp9_ = _g_object_ref0 ((GtkTextTag*) t_it->data);
			t = _tmp9_;
			{
				GtkTextBuffer* _tmp10_;
				GtkTextTag* _tmp11_;
				GtkTextIter _tmp12_;
				GtkTextIter _tmp13_;
				GtkTextTagTable* _tmp14_;
				GtkTextTag* _tmp15_;
				_tmp10_ = self->priv->buf;
				_tmp11_ = t;
				_tmp12_ = whole_start;
				_tmp13_ = whole_end;
				gtk_text_buffer_remove_tag (_tmp10_, _tmp11_, &_tmp12_, &_tmp13_);
				_tmp14_ = tt;
				_tmp15_ = t;
				gtk_text_tag_table_remove (_tmp14_, _tmp15_);
				_g_object_unref0 (t);
			}
		}
	}
	_tmp16_ = self->priv->buf;
	gtk_text_buffer_get_start_iter (_tmp16_, &_tmp17_);
	start = _tmp17_;
	_tmp18_ = self->priv->buf;
	gtk_text_buffer_get_end_iter (_tmp18_, &_tmp19_);
	end = _tmp19_;
	_tmp20_ = self->priv->buf;
	_tmp21_ = start;
	_tmp22_ = end;
	_tmp23_ = gtk_text_buffer_get_text (_tmp20_, &_tmp21_, &_tmp22_, FALSE);
	text = _tmp23_;
	info = NULL;
	_tmp24_ = self->priv->url_reg;
	_tmp25_ = text;
	g_regex_match (_tmp24_, _tmp25_, 0, &_tmp26_);
	_g_match_info_unref0 (info);
	info = _tmp26_;
	match_index = 0;
	while (TRUE) {
		GMatchInfo* _tmp27_;
		gchar* matched = NULL;
		GMatchInfo* _tmp28_;
		gchar* _tmp29_;
		gint byte_start = 0;
		gint byte_end = 0;
		GMatchInfo* _tmp30_;
		gint _tmp31_ = 0;
		gint _tmp32_ = 0;
		gint st_off = 0;
		const gchar* _tmp33_;
		gint en_off = 0;
		const gchar* _tmp34_;
		GtkTextIter it_start = {0};
		GtkTextBuffer* _tmp35_;
		GtkTextIter _tmp36_ = {0};
		GtkTextIter it_end = {0};
		GtkTextBuffer* _tmp37_;
		GtkTextIter _tmp38_ = {0};
		gchar* tag_name = NULL;
		gchar* _tmp39_;
		gchar* _tmp40_;
		gchar* _tmp41_;
		gchar* _tmp42_;
		GtkTextTag* tag = NULL;
		GtkTextBuffer* _tmp43_;
		const gchar* _tmp44_;
		GtkTextTag* _tmp45_;
		GtkTextTag* _tmp46_;
		GtkTextTag* _tmp47_;
		const gchar* _tmp48_;
		gchar* _tmp49_;
		GtkTextBuffer* _tmp50_;
		GtkTextTag* _tmp51_;
		GtkTextIter _tmp52_;
		GtkTextIter _tmp53_;
		gint _tmp54_;
		GMatchInfo* _tmp55_;
		_tmp27_ = info;
		if (!g_match_info_matches (_tmp27_)) {
			break;
		}
		_tmp28_ = info;
		_tmp29_ = g_match_info_fetch (_tmp28_, 0);
		matched = _tmp29_;
		_tmp30_ = info;
		g_match_info_fetch_pos (_tmp30_, 0, &_tmp31_, &_tmp32_);
		byte_start = _tmp31_;
		byte_end = _tmp32_;
		_tmp33_ = text;
		st_off = gitg_result_dialog_byte_to_char_offset (_tmp33_, byte_start);
		_tmp34_ = text;
		en_off = gitg_result_dialog_byte_to_char_offset (_tmp34_, byte_end);
		_tmp35_ = self->priv->buf;
		gtk_text_buffer_get_iter_at_offset (_tmp35_, &_tmp36_, st_off);
		it_start = _tmp36_;
		_tmp37_ = self->priv->buf;
		gtk_text_buffer_get_iter_at_offset (_tmp37_, &_tmp38_, en_off);
		it_end = _tmp38_;
		_tmp39_ = g_strdup_printf ("%i", match_index);
		_tmp40_ = _tmp39_;
		_tmp41_ = g_strconcat ("link-", _tmp40_, NULL);
		_tmp42_ = _tmp41_;
		_g_free0 (_tmp40_);
		tag_name = _tmp42_;
		_tmp43_ = self->priv->buf;
		_tmp44_ = tag_name;
		_tmp45_ = gtk_text_buffer_create_tag (_tmp43_, _tmp44_, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, "editable", TRUE, NULL);
		_tmp46_ = _g_object_ref0 (_tmp45_);
		tag = _tmp46_;
		_tmp47_ = tag;
		_tmp48_ = matched;
		_tmp49_ = g_strdup (_tmp48_);
		g_object_set_data_full ((GObject*) _tmp47_, "href", _tmp49_, g_free);
		_tmp50_ = self->priv->buf;
		_tmp51_ = tag;
		_tmp52_ = it_start;
		_tmp53_ = it_end;
		gtk_text_buffer_apply_tag (_tmp50_, _tmp51_, &_tmp52_, &_tmp53_);
		_tmp54_ = match_index;
		match_index = _tmp54_ + 1;
		_tmp55_ = info;
		g_match_info_next (_tmp55_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (tag);
			_g_free0 (tag_name);
			_g_free0 (matched);
			_g_match_info_unref0 (info);
			_g_free0 (text);
			_g_object_unref0 (tt);
			block82_data_unref (_data82_);
			_data82_ = NULL;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_g_object_unref0 (tag);
		_g_free0 (tag_name);
		_g_free0 (matched);
	}
	_g_match_info_unref0 (info);
	_g_free0 (text);
	_g_object_unref0 (tt);
	block82_data_unref (_data82_);
	_data82_ = NULL;
}

static gboolean
gitg_result_dialog_get_iter_at_event (GitgResultDialog* self,
                                      gint ex,
                                      gint ey,
                                      GtkTextIter* iter)
{
	GtkTextIter _vala_iter = {0};
	gint bx = 0;
	gint by = 0;
	GtkTextView* _tmp0_;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	GtkTextView* _tmp3_;
	GtkTextIter _tmp4_ = {0};
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	bx = 0;
	by = 0;
	_tmp0_ = self->priv->tv;
	gtk_text_view_window_to_buffer_coords (_tmp0_, GTK_TEXT_WINDOW_WIDGET, ex, ey, &_tmp1_, &_tmp2_);
	bx = _tmp1_;
	by = _tmp2_;
	_tmp3_ = self->priv->tv;
	gtk_text_view_get_iter_at_location (_tmp3_, &_tmp4_, bx, by);
	_vala_iter = _tmp4_;
	result = TRUE;
	if (iter) {
		*iter = _vala_iter;
	}
	return result;
}

static gboolean
gitg_result_dialog_on_hover_link (GitgResultDialog* self,
                                  GdkEventMotion* ev)
{
	GtkTextIter iter = {0};
	GtkTextIter _tmp0_ = {0};
	gboolean _tmp1_;
	GSList* tags = NULL;
	GSList* _tmp2_;
	gboolean over_link = FALSE;
	GSList* _tmp3_;
	GdkWindow* gdk_window = NULL;
	GtkTextView* _tmp8_;
	GdkWindow* _tmp9_;
	GdkWindow* _tmp10_;
	GdkWindow* _tmp11_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (ev != NULL, FALSE);
	_tmp1_ = gitg_result_dialog_get_iter_at_event (self, (gint) ev->x, (gint) ev->y, &_tmp0_);
	iter = _tmp0_;
	if (!_tmp1_) {
		result = FALSE;
		return result;
	}
	_tmp2_ = gtk_text_iter_get_tags (&iter);
	tags = _tmp2_;
	over_link = FALSE;
	_tmp3_ = tags;
	{
		GSList* t_collection = NULL;
		GSList* t_it = NULL;
		t_collection = _tmp3_;
		for (t_it = t_collection; t_it != NULL; t_it = t_it->next) {
			GtkTextTag* t = NULL;
			t = (GtkTextTag*) t_it->data;
			{
				gchar* href = NULL;
				GtkTextTag* _tmp4_;
				gconstpointer _tmp5_;
				gchar* _tmp6_;
				const gchar* _tmp7_;
				_tmp4_ = t;
				_tmp5_ = g_object_get_data ((GObject*) _tmp4_, "href");
				_tmp6_ = g_strdup ((const gchar*) _tmp5_);
				href = _tmp6_;
				_tmp7_ = href;
				if (_tmp7_ != NULL) {
					over_link = TRUE;
					_g_free0 (href);
					break;
				}
				_g_free0 (href);
			}
		}
	}
	_tmp8_ = self->priv->tv;
	_tmp9_ = gtk_text_view_get_window (_tmp8_, GTK_TEXT_WINDOW_TEXT);
	_tmp10_ = _g_object_ref0 (_tmp9_);
	gdk_window = _tmp10_;
	_tmp11_ = gdk_window;
	if (_tmp11_ != NULL) {
		if (over_link) {
			GdkCursor* cursor = NULL;
			GdkCursor* _tmp12_;
			GdkWindow* _tmp13_;
			GdkCursor* _tmp14_;
			_tmp12_ = gdk_cursor_new (GDK_HAND2);
			cursor = _tmp12_;
			_tmp13_ = gdk_window;
			_tmp14_ = cursor;
			gdk_window_set_cursor (_tmp13_, _tmp14_);
			_g_object_unref0 (cursor);
		} else {
			GdkWindow* _tmp15_;
			_tmp15_ = gdk_window;
			gdk_window_set_cursor (_tmp15_, NULL);
		}
	}
	result = FALSE;
	_g_object_unref0 (gdk_window);
	(tags == NULL) ? NULL : (tags = (g_slist_free (tags), NULL));
	return result;
}

static gboolean
gitg_result_dialog_on_link_press (GitgResultDialog* self,
                                  GdkEventButton* ev)
{
	gboolean _tmp0_ = FALSE;
	GtkTextIter iter = {0};
	GtkTextIter _tmp1_ = {0};
	gboolean _tmp2_;
	GSList* tags = NULL;
	GSList* _tmp3_;
	GSList* _tmp4_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (ev != NULL, FALSE);
	if (ev->type != GDK_BUTTON_PRESS) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = ev->button != ((guint) GDK_BUTTON_PRIMARY);
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp2_ = gitg_result_dialog_get_iter_at_event (self, (gint) ev->x, (gint) ev->y, &_tmp1_);
	iter = _tmp1_;
	if (!_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp3_ = gtk_text_iter_get_tags (&iter);
	tags = _tmp3_;
	_tmp4_ = tags;
	{
		GSList* t_collection = NULL;
		GSList* t_it = NULL;
		t_collection = _tmp4_;
		for (t_it = t_collection; t_it != NULL; t_it = t_it->next) {
			GtkTextTag* t = NULL;
			t = (GtkTextTag*) t_it->data;
			{
				gchar* href = NULL;
				GtkTextTag* _tmp5_;
				gconstpointer _tmp6_;
				gchar* _tmp7_;
				const gchar* _tmp8_;
				_tmp5_ = t;
				_tmp6_ = g_object_get_data ((GObject*) _tmp5_, "href");
				_tmp7_ = g_strdup ((const gchar*) _tmp6_);
				href = _tmp7_;
				_tmp8_ = href;
				if (_tmp8_ != NULL) {
					GtkTextTag* visited = NULL;
					gboolean is_visited = FALSE;
					GtkTextTag* _tmp9_;
					gchar* _tmp10_;
					gchar* _tmp11_;
					gchar* _tmp12_;
					gboolean _tmp13_;
					visited = NULL;
					_tmp9_ = t;
					g_object_get (_tmp9_, "name", &_tmp10_, NULL);
					_tmp11_ = _tmp10_;
					_tmp12_ = _tmp11_;
					_tmp13_ = g_str_has_suffix (_tmp12_, "-visited");
					_g_free0 (_tmp12_);
					is_visited = _tmp13_;
					if (!is_visited) {
						GtkTextBuffer* _tmp14_;
						GtkTextTag* _tmp15_;
						gchar* _tmp16_;
						gchar* _tmp17_;
						gchar* _tmp18_;
						gchar* _tmp19_;
						gchar* _tmp20_;
						GtkTextTag* _tmp21_;
						GtkTextTag* _tmp22_;
						GtkTextTag* _tmp23_;
						const gchar* _tmp24_;
						gchar* _tmp25_;
						_tmp14_ = self->priv->buf;
						_tmp15_ = t;
						g_object_get (_tmp15_, "name", &_tmp16_, NULL);
						_tmp17_ = _tmp16_;
						_tmp18_ = _tmp17_;
						_tmp19_ = g_strconcat (_tmp18_, "-visited", NULL);
						_tmp20_ = _tmp19_;
						_tmp21_ = gtk_text_buffer_create_tag (_tmp14_, _tmp20_, "foreground", "magenta", "underline", PANGO_UNDERLINE_SINGLE, NULL);
						_tmp22_ = _g_object_ref0 (_tmp21_);
						_g_object_unref0 (visited);
						visited = _tmp22_;
						_g_free0 (_tmp20_);
						_g_free0 (_tmp18_);
						_tmp23_ = visited;
						_tmp24_ = href;
						_tmp25_ = g_strdup (_tmp24_);
						g_object_set_data_full ((GObject*) _tmp23_, "href", _tmp25_, g_free);
					}
					{
						const gchar* _tmp26_;
						_tmp26_ = href;
						g_app_info_launch_default_for_uri (_tmp26_, NULL, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							goto __catch0_g_error;
						}
						if (!is_visited) {
							GtkTextIter range_start = {0};
							GtkTextIter _tmp27_;
							GtkTextIter range_end = {0};
							GtkTextIter _tmp28_;
							gboolean has_backward = FALSE;
							GtkTextTag* _tmp29_;
							gboolean has_forward = FALSE;
							GtkTextTag* _tmp30_;
							GtkTextBuffer* _tmp31_;
							GtkTextTag* _tmp32_;
							GtkTextIter _tmp33_;
							GtkTextIter _tmp34_;
							GtkTextBuffer* _tmp35_;
							GtkTextTag* _tmp36_;
							GtkTextIter _tmp37_;
							GtkTextIter _tmp38_;
							_tmp27_ = iter;
							range_start = _tmp27_;
							_tmp28_ = iter;
							range_end = _tmp28_;
							_tmp29_ = t;
							has_backward = gtk_text_iter_backward_to_tag_toggle (&range_start, _tmp29_);
							_tmp30_ = t;
							has_forward = gtk_text_iter_forward_to_tag_toggle (&range_end, _tmp30_);
							_tmp31_ = self->priv->buf;
							_tmp32_ = t;
							_tmp33_ = range_start;
							_tmp34_ = range_end;
							gtk_text_buffer_remove_tag (_tmp31_, _tmp32_, &_tmp33_, &_tmp34_);
							_tmp35_ = self->priv->buf;
							_tmp36_ = visited;
							_tmp37_ = range_start;
							_tmp38_ = range_end;
							gtk_text_buffer_apply_tag (_tmp35_, _tmp36_, &_tmp37_, &_tmp38_);
						}
					}
					goto __finally0;
					__catch0_g_error:
					{
						GError* e = NULL;
						FILE* _tmp39_;
						const gchar* _tmp40_;
						GError* _tmp41_;
						const gchar* _tmp42_;
						e = _inner_error0_;
						_inner_error0_ = NULL;
						_tmp39_ = stderr;
						_tmp40_ = href;
						_tmp41_ = e;
						_tmp42_ = _tmp41_->message;
						fprintf (_tmp39_, "Failed to open %s: %s\n", _tmp40_, _tmp42_);
						_g_error_free0 (e);
					}
					__finally0:
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						gboolean _tmp43_ = FALSE;
						_g_object_unref0 (visited);
						_g_free0 (href);
						(tags == NULL) ? NULL : (tags = (g_slist_free (tags), NULL));
						g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
						g_clear_error (&_inner_error0_);
						return _tmp43_;
					}
					result = TRUE;
					_g_object_unref0 (visited);
					_g_free0 (href);
					(tags == NULL) ? NULL : (tags = (g_slist_free (tags), NULL));
					return result;
				}
				_g_free0 (href);
			}
		}
	}
	result = FALSE;
	(tags == NULL) ? NULL : (tags = (g_slist_free (tags), NULL));
	return result;
}

void
gitg_result_dialog_append_message (GitgResultDialog* self,
                                   const gchar* message)
{
	g_return_if_fail (self != NULL);
	if (message != NULL) {
		const gchar* _tmp0_;
		gchar* _tmp1_;
		_tmp0_ = self->priv->original_message;
		_tmp1_ = g_strconcat (_tmp0_, message, NULL);
		_g_free0 (self->priv->original_message);
		self->priv->original_message = _tmp1_;
		gitg_result_dialog_render (self);
	}
}

void
gitg_result_dialog_clear_messages (GitgResultDialog* self)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup ("");
	_g_free0 (self->priv->original_message);
	self->priv->original_message = _tmp0_;
	gitg_result_dialog_render (self);
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

gchar*
gitg_result_dialog_remove_ansi (const gchar* text)
{
	GRegex* _tmp1_;
	GRegex* _tmp8_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (text != NULL, NULL);
	if (!string_contains (text, "\x1b")) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (text);
		result = _tmp0_;
		return result;
	}
	_tmp1_ = gitg_result_dialog_regex_remove_ansi;
	if (_tmp1_ == NULL) {
		{
			GRegex* _tmp2_ = NULL;
			GRegex* _tmp3_;
			GRegex* _tmp4_;
			_tmp3_ = g_regex_new ("\x1b" "(?:" "\\[[0-9;?]*[a-zA-Z]" "|" "\\].*?(?:\x07|\x1b\\\\)" "|" "\\((?:[0-2B])" "|" "\\)(?:[0-2B])" "|" "[=>]" "|" "[78DMHEFcZ]" "|" "." ")", 0, 0, &_inner_error0_);
			_tmp2_ = _tmp3_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == G_REGEX_ERROR) {
					goto __catch0_g_regex_error;
				}
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return NULL;
			}
			_tmp4_ = _tmp2_;
			_tmp2_ = NULL;
			_g_regex_unref0 (gitg_result_dialog_regex_remove_ansi);
			gitg_result_dialog_regex_remove_ansi = _tmp4_;
			_g_regex_unref0 (_tmp2_);
		}
		goto __finally0;
		__catch0_g_regex_error:
		{
			GError* e = NULL;
			FILE* _tmp5_;
			GError* _tmp6_;
			const gchar* _tmp7_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp5_ = stderr;
			_tmp6_ = e;
			_tmp7_ = _tmp6_->message;
			fprintf (_tmp5_, "Error: %s\n", _tmp7_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	_tmp8_ = gitg_result_dialog_regex_remove_ansi;
	if (_tmp8_ == NULL) {
		gchar* _tmp9_;
		_tmp9_ = g_strdup (text);
		result = _tmp9_;
		return result;
	}
	{
		gchar* _tmp10_ = NULL;
		GRegex* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp11_ = gitg_result_dialog_regex_remove_ansi;
		_tmp12_ = g_regex_replace (_tmp11_, text, (gssize) -1, 0, "", 0, &_inner_error0_);
		_tmp10_ = _tmp12_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch1_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp13_ = _tmp10_;
		_tmp10_ = NULL;
		result = _tmp13_;
		_g_free0 (_tmp10_);
		return result;
	}
	goto __finally1;
	__catch1_g_regex_error:
	{
		gchar* _tmp14_;
		g_clear_error (&_inner_error0_);
		_tmp14_ = g_strdup (text);
		result = _tmp14_;
		return result;
	}
	__finally1:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

void
gitg_result_dialog_render (GitgResultDialog* self)
{
	gchar* message = NULL;
	GitgAnsiRenderer* _tmp4_;
	const gchar* _tmp5_;
	g_return_if_fail (self != NULL);
	if (self->priv->filter_ansi) {
		const gchar* _tmp0_;
		gchar* _tmp1_;
		_tmp0_ = self->priv->original_message;
		_tmp1_ = gitg_result_dialog_remove_ansi (_tmp0_);
		_g_free0 (message);
		message = _tmp1_;
	} else {
		const gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = self->priv->original_message;
		_tmp3_ = g_strdup (_tmp2_);
		_g_free0 (message);
		message = _tmp3_;
	}
	_tmp4_ = self->priv->ansiRenderer;
	_tmp5_ = message;
	gitg_ansi_renderer_render_ansi (_tmp4_, _tmp5_);
	_g_free0 (message);
}

static void
gitg_result_dialog_class_init (GitgResultDialogClass * klass,
                               gpointer klass_data)
{
	gitg_result_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GitgResultDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = gitg_result_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/gitg/ui/gitg-result-dialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "d_button_close", FALSE, GitgResultDialog_private_offset + G_STRUCT_OFFSET (GitgResultDialogPrivate, d_button_close));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "d_text_view_message", FALSE, GitgResultDialog_private_offset + G_STRUCT_OFFSET (GitgResultDialogPrivate, d_text_view_message));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "d_label_result", FALSE, GitgResultDialog_private_offset + G_STRUCT_OFFSET (GitgResultDialogPrivate, d_label_result));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "d_button_copy", FALSE, GitgResultDialog_private_offset + G_STRUCT_OFFSET (GitgResultDialogPrivate, d_button_copy));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "switch_remove_ansi", FALSE, GitgResultDialog_private_offset + G_STRUCT_OFFSET (GitgResultDialogPrivate, switch_remove_ansi));
}

static void
gitg_result_dialog_instance_init (GitgResultDialog * self,
                                  gpointer klass)
{
	self->priv = gitg_result_dialog_get_instance_private (self);
	self->priv->timer_id = (guint) 0;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
gitg_result_dialog_finalize (GObject * obj)
{
	GitgResultDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_RESULT_DIALOG, GitgResultDialog);
	_g_object_unref0 (self->priv->buf);
	_g_object_unref0 (self->priv->tv);
	_g_regex_unref0 (self->priv->url_reg);
	_gitg_ansi_renderer_unref0 (self->priv->ansiRenderer);
	_g_free0 (self->priv->original_message);
	G_OBJECT_CLASS (gitg_result_dialog_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_result_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgResultDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_result_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgResultDialog), 0, (GInstanceInitFunc) gitg_result_dialog_instance_init, NULL };
	GType gitg_result_dialog_type_id;
	gitg_result_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "GitgResultDialog", &g_define_type_info, 0);
	GitgResultDialog_private_offset = g_type_add_instance_private (gitg_result_dialog_type_id, sizeof (GitgResultDialogPrivate));
	return gitg_result_dialog_type_id;
}

GType
gitg_result_dialog_get_type (void)
{
	static gsize gitg_result_dialog_type_id__once = 0;
	if (g_once_init_enter (&gitg_result_dialog_type_id__once)) {
		GType gitg_result_dialog_type_id;
		gitg_result_dialog_type_id = gitg_result_dialog_get_type_once ();
		g_once_init_leave (&gitg_result_dialog_type_id__once, gitg_result_dialog_type_id);
	}
	return gitg_result_dialog_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

