Skip to content
API Documentation
BastionGuard™
TerminalWindow Class Reference
Inheritance diagram for TerminalWindow:

Public Member Functions

TerminalWindow. with_parent (Gtk.Window? parent)
void init_window ()
void start_shell ()
void execute_script (string script_path, bool wait=false)
void script_exit (int status)

Public Attributes

bool is_running = false

Private Attributes

Gtk.Box vbox_main
Vte.Terminal term
int def_width = 800
int def_height = 600
Pid child_pid
Gtk.Window parent_win = null

Detailed Description

Definition at line 36 of file TerminalWindow.vala.

Member Function Documentation

◆ execute_script()

void TerminalWindow.execute_script ( string script_path,
bool wait = false )
inline

Definition at line 140 of file TerminalWindow.vala.

140 {
141
142 string[] argv = new string[1];
143 argv[0] = script_path;
144
145 string[] env = Environ.get();
146
147 try{
148
149 is_running = true;
150
151 term.spawn_sync(
152 Vte.PtyFlags.DEFAULT, //pty_flags
153 TEMP_DIR, //working_directory
154 argv, //argv
155 env, //env
156 GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
157 null, //child_setup
158 out child_pid,
159 null
160 );
161
162 term.watch_child(child_pid);
163
164 term.child_exited.connect(script_exit);
165
166 if (wait){
167 while (is_running){
168 sleep(200);
170 }
171 }
172 }
173 catch (Error e) {
174 log_error (e.message);
175 }
176 }
void script_exit(int status)
Vte.Terminal term
void log_error(string message, bool highlight=false, bool is_warning=false)
void sleep(int milliseconds)

References child_pid, Error, TeeJee.GtkHelper.gtk_do_events(), is_running, TeeJee.Logging.log_error(), script_exit(), TeeJee.System.sleep(), TeeJee.ProcessHelper.TEMP_DIR, and term.

Referenced by Main.restore_current_gui().

◆ init_window()

void TerminalWindow.init_window ( )
inline

Definition at line 68 of file TerminalWindow.vala.

68 {
69
70 this.title = "";
71 this.set_icon_name("bastionguard-backup");
72 this.resizable = true;
73 this.deletable = false;
74
75 // vbox_main ---------------
76
77 vbox_main = new Gtk.Box(Orientation.VERTICAL, 6);
78 vbox_main.set_size_request (def_width, def_height);
79 set_child(vbox_main);
80
81 // terminal ----------------------
82
83 term = new Vte.Terminal();
84 term.hexpand = true;
85 term.vexpand = true;
86 vbox_main.append(term);
87
88 term.input_enabled = true;
89 term.backspace_binding = Vte.EraseBinding.AUTO;
90 term.cursor_blink_mode = Vte.CursorBlinkMode.SYSTEM;
91 term.cursor_shape = Vte.CursorShape.UNDERLINE;
92 //term.rewrap_on_resize = true;
93
94 term.scroll_on_keystroke = true;
95 term.scroll_on_output = true;
96
97 // colors -----------------------------
98
99 var color = Gdk.RGBA();
100 color.parse("#FFFFFF");
101 term.set_color_foreground(color);
102
103 color.parse("#404040");
104 term.set_color_background(color);
105
106 // grab focus ----------------
107
108 term.grab_focus();
109
110 show();
111 }

References def_height, def_width, term, and vbox_main.

Referenced by with_parent().

◆ script_exit()

void TerminalWindow.script_exit ( int status)
inline

Definition at line 178 of file TerminalWindow.vala.

178 {
179
180 is_running = false;
181
182 this.hide();
183
184 //no need to check status again
185
186 //destroying parent will display main window
187 if (parent != null){
188 parent_win.destroy();
189 }
190 }
Gtk.Window parent_win

References is_running, and parent_win.

Referenced by execute_script().

◆ start_shell()

void TerminalWindow.start_shell ( )
inline

Definition at line 113 of file TerminalWindow.vala.

113 {
114
115 string[] argv = new string[1];
116 argv[0] = "/bin/sh";
117
118 string[] env = Environ.get();
119
120 try{
121
122 is_running = true;
123
124 term.spawn_sync(
125 Vte.PtyFlags.DEFAULT, //pty_flags
126 TEMP_DIR, //working_directory
127 argv, //argv
128 env, //env
129 GLib.SpawnFlags.SEARCH_PATH, //spawn_flags
130 null, //child_setup
131 out child_pid,
132 null
133 );
134 }
135 catch (Error e) {
136 log_error (e.message);
137 }
138 }

References child_pid, Error, is_running, TeeJee.Logging.log_error(), TeeJee.ProcessHelper.TEMP_DIR, and term.

◆ with_parent()

TerminalWindow. TerminalWindow.with_parent ( Gtk.Window? parent)
inline

Definition at line 50 of file TerminalWindow.vala.

50 {
51
52 if (parent != null){
53 set_transient_for(parent);
54 parent_win = parent;
55 }
56
57 set_modal(true);
58 fullscreen();
59
60 this.close_request.connect(() => {
61 // do not allow window to close
62 return true;
63 });
64
66 }

References init_window(), and parent_win.

Referenced by Main.restore_current_gui().

Member Data Documentation

◆ child_pid

Pid TerminalWindow.child_pid
private

Definition at line 44 of file TerminalWindow.vala.

Referenced by execute_script(), and start_shell().

◆ def_height

int TerminalWindow.def_height = 600
private

Definition at line 42 of file TerminalWindow.vala.

Referenced by init_window().

◆ def_width

int TerminalWindow.def_width = 800
private

Definition at line 41 of file TerminalWindow.vala.

Referenced by init_window().

◆ is_running

bool TerminalWindow.is_running = false

Definition at line 46 of file TerminalWindow.vala.

Referenced by execute_script(), script_exit(), and start_shell().

◆ parent_win

Gtk.Window TerminalWindow.parent_win = null
private

Definition at line 45 of file TerminalWindow.vala.

Referenced by script_exit(), and with_parent().

◆ term

Vte.Terminal TerminalWindow.term
private

Definition at line 39 of file TerminalWindow.vala.

Referenced by execute_script(), init_window(), and start_shell().

◆ vbox_main

Gtk.Box TerminalWindow.vbox_main
private

Definition at line 38 of file TerminalWindow.vala.

Referenced by init_window().


The documentation for this class was generated from the following file: