4
* Copyright 2015 Tony George <teejee2008@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
29
using TeeJee.FileSystem;
31
using TeeJee.ProcessManagement;
32
using TeeJee.GtkHelper;
33
using TeeJee.Multimedia;
37
public class TerminalWindow : Gtk.Window {
38
private Gtk.Box vbox_main;
39
private Vte.Terminal term;
41
private int def_width = 800;
42
private int def_height = 600;
44
private Pid child_pid;
45
private Gtk.Window parent_win = null;
46
public bool is_running = false;
50
public TerminalWindow.with_parent(Gtk.Window? parent) {
52
set_transient_for(parent);
56
window_position = WindowPosition.CENTER;
58
this.delete_event.connect(()=>{
59
// do not allow window to close
66
public void init_window () {
68
icon = get_app_icon(16);
72
// vbox_main ---------------
74
vbox_main = new Box (Orientation.VERTICAL, 6);
75
vbox_main.set_size_request (def_width, def_height);
78
// terminal ----------------------
80
term = new Vte.Terminal();
86
term.input_enabled = true;
87
term.backspace_binding = Vte.EraseBinding.AUTO;
88
term.cursor_blink_mode = Vte.CursorBlinkMode.SYSTEM;
89
term.cursor_shape = Vte.CursorShape.UNDERLINE;
90
term.rewrap_on_resize = true;
94
term.scroll_on_keystroke = true;
95
term.scroll_on_output = true;
97
// colors -----------------------------
101
var color = Gdk.RGBA();
102
color.parse("#FFFFFF");
103
term.set_color_foreground(color);
105
color.parse("#404040");
106
term.set_color_background(color);
111
Gdk.Color.parse("#FFFFFF", out color);
112
term.set_color_foreground(color);
114
Gdk.Color.parse("#404040", out color);
115
term.set_color_background(color);
119
// grab focus ----------------
126
public void start_shell(){
127
string[] argv = new string[1];
130
string[] env = Environ.get();
139
Vte.PtyFlags.DEFAULT, //pty_flags
140
TEMP_DIR, //working_directory
143
GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
151
term.fork_command_full(
152
Vte.PtyFlags.DEFAULT, //pty_flags
153
App.temp_dir, //working_directory
156
GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
164
log_error (e.message);
168
public void execute_command(string command){
169
term.feed_child("%s\n".printf(command), -1);
172
public void execute_script(string script_path, bool wait = false){
173
string[] argv = new string[1];
174
argv[0] = script_path;
176
string[] env = Environ.get();
185
Vte.PtyFlags.DEFAULT, //pty_flags
186
TEMP_DIR, //working_directory
189
GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
197
term.fork_command_full(
198
Vte.PtyFlags.DEFAULT, //pty_flags
199
TEMP_DIR, //working_directory
202
GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
209
term.watch_child(child_pid);
211
term.child_exited.connect(script_exit);
221
log_error (e.message);
226
public void script_exit(int status){
228
public void script_exit(){
235
//no need to check status again
237
//destroying parent will display main window
239
parent_win.destroy();