Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9e40f167e2
Fetching contributors…

Cannot retrieve contributors at this time

file 142 lines (119 sloc) 3.063 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
using Gtk;
using Gdk;
using Vte;

namespace MultiTerm
{
public class Terminal : Frame
{
public Vte.Terminal terminal;
private ShellConfig sh;

public signal bool right_click_event(EventButton event);

private void on_window_title_changed()
{
tab_label_text = terminal.window_title;
}

public string tab_label_text
{
get
{
TabLabel label = this.get_data<TabLabel>("label");
return label.text;
}
set
{
TabLabel label = this.get_data<TabLabel>("label");
label.text = value;
}
}

public string background_color
{
set
{
Gdk.Color color = Gdk.Color();
Gdk.Colormap.get_system().alloc_color(color, true, true);
Gdk.Color.parse(value, out color);
terminal.set_color_background(color);
}
}

public string foreground_color
{
set
{
Gdk.Color color = Gdk.Color();
Gdk.Colormap.get_system().alloc_color(color, true, true);
Gdk.Color.parse(value, out color);
terminal.set_color_foreground(color);
}
}

public void run_command(string command)
{
Pid pid;
string[] argv = { command, null };
try
{
terminal.fork_command_full(PtyFlags.DEFAULT, null, argv, null,
SpawnFlags.SEARCH_PATH, null, out pid);
//debug("Started terminal with pid of '%d'", pid);
}
catch (Error err)
{
warning("Unable to run command: %s", err.message);
}
}

private void on_vte_realize()
{
if (sh.cfg != null)
{
background_color = sh.background_color;
foreground_color = sh.foreground_color;
}
else
{
background_color = "#ffffff";
foreground_color = "#000000";
}

/* Start receiving events for mouse clicks */
terminal.add_events(EventMask.BUTTON_PRESS_MASK);
terminal.button_press_event.connect(on_button_press);
}

private void on_child_exited()
{
run_command(this.sh.command);
}

private bool on_button_press(EventButton event)
{
if (event.button == 3)
return right_click_event(event);
return false;
}

public void send_command(string command)
{
terminal.feed_child("%s\n".printf(command), -1);
}

public Terminal(ShellConfig sh)
{
VScrollbar vsb;
HBox hbox;

this.sh = sh;
            if (this.sh.command.strip() == "")
this.sh.command = "sh";

terminal = new Vte.Terminal();
terminal.set_size_request(100, 100); // stupid
terminal.show_all();

vsb = new VScrollbar(terminal.get_adjustment());
hbox = new HBox(false, 0);

hbox.pack_start(terminal, true, true, 0);
hbox.pack_start(vsb, false, false, 0);

this.add(hbox);

if (this.sh.track_title)
terminal.window_title_changed.connect(on_window_title_changed);

terminal.child_exited.connect(on_child_exited);

if (this.sh.cfg != null)
terminal.set_font_from_string_full(this.sh.font, TerminalAntiAlias.FORCE_ENABLE);
else
terminal.set_font_from_string_full("Monospace 9", TerminalAntiAlias.FORCE_ENABLE);

terminal.realize.connect(on_vte_realize); /* colors can only be set on realize (lame) */
run_command(this.sh.command);
}

}
}
Something went wrong with that request. Please try again.