4
* Copyright 2016 Tony George <teejeetech@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;
30
using TeeJee.JsonHelper;
31
using TeeJee.ProcessHelper;
32
using TeeJee.GtkHelper;
36
public class TerminalWindow : Gtk.Window {
37
private Gtk.Box vbox_main;
38
private Vte.Terminal term;
40
private int def_width = 800;
41
private int def_height = 600;
43
private Pid child_pid;
44
private Gtk.Window parent_win = null;
45
public bool is_running = false;
49
public TerminalWindow.with_parent(Gtk.Window? parent) {
51
set_transient_for(parent);
57
this.delete_event.connect(()=>{
58
// do not allow window to close
65
public void init_window () {
67
icon = get_app_icon(16);
71
// vbox_main ---------------
73
vbox_main = new Box (Orientation.VERTICAL, 6);
74
vbox_main.set_size_request (def_width, def_height);
77
// terminal ----------------------
79
term = new Vte.Terminal();
85
term.input_enabled = true;
86
term.backspace_binding = Vte.EraseBinding.AUTO;
87
term.cursor_blink_mode = Vte.CursorBlinkMode.SYSTEM;
88
term.cursor_shape = Vte.CursorShape.UNDERLINE;
89
term.rewrap_on_resize = true;
93
term.scroll_on_keystroke = true;
94
term.scroll_on_output = true;
96
// colors -----------------------------
100
var color = Gdk.RGBA();
101
color.parse("#FFFFFF");
102
term.set_color_foreground(color);
104
color.parse("#404040");
105
term.set_color_background(color);
110
Gdk.Color.parse("#FFFFFF", out color);
111
term.set_color_foreground(color);
113
Gdk.Color.parse("#404040", out color);
114
term.set_color_background(color);
118
// grab focus ----------------
125
public void start_shell(){
126
string[] argv = new string[1];
129
string[] env = Environ.get();
138
Vte.PtyFlags.DEFAULT, //pty_flags
139
TEMP_DIR, //working_directory
142
GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
150
term.fork_command_full(
151
Vte.PtyFlags.DEFAULT, //pty_flags
152
TEMP_DIR, //working_directory
155
GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
163
log_error (e.message);
167
public void execute_command(string command){
168
term.feed_child("%s\n".printf(command), -1);
171
public void execute_script(string script_path, bool wait = false){
172
string[] argv = new string[1];
173
argv[0] = script_path;
175
string[] env = Environ.get();
184
Vte.PtyFlags.DEFAULT, //pty_flags
185
TEMP_DIR, //working_directory
188
GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
196
term.fork_command_full(
197
Vte.PtyFlags.DEFAULT, //pty_flags
198
TEMP_DIR, //working_directory
201
GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
208
term.watch_child(child_pid);
210
term.child_exited.connect(script_exit);
220
log_error (e.message);
225
public void script_exit(int status){
227
public void script_exit(){
234
//no need to check status again
236
//destroying parent will display main window
238
parent_win.destroy();