1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module vte.Pty;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.InitableIF;
30 private import gio.InitableT;
31 private import glib.ConstructionException;
32 private import glib.ErrorG;
33 private import glib.GException;
34 private import glib.Str;
35 private import gobject.ObjectG;
36 private import vte.c.functions;
37 public  import vte.c.types;
38 public  import vtec.vtetypes;
39 
40 
41 /** */
42 public class Pty : ObjectG, InitableIF
43 {
44 	/** the main Gtk struct */
45 	protected VtePty* vtePty;
46 
47 	/** Get the main Gtk struct */
48 	public VtePty* getPtyStruct(bool transferOwnership = false)
49 	{
50 		if (transferOwnership)
51 			ownedRef = false;
52 		return vtePty;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)vtePty;
59 	}
60 
61 	/**
62 	 * Sets our main struct and passes it to the parent class.
63 	 */
64 	public this (VtePty* vtePty, bool ownedRef = false)
65 	{
66 		this.vtePty = vtePty;
67 		super(cast(GObject*)vtePty, ownedRef);
68 	}
69 
70 	// add the Initable capabilities
71 	mixin InitableT!(VtePty);
72 
73 
74 	/** */
75 	public static GType getType()
76 	{
77 		return vte_pty_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new #VtePty for the PTY master @fd.
82 	 *
83 	 * No entry will be made in the lastlog, utmp or wtmp system files.
84 	 *
85 	 * Note that the newly created #VtePty will take ownership of @fd
86 	 * and close it on finalize.
87 	 *
88 	 * Params:
89 	 *     fd = a file descriptor to the PTY
90 	 *     cancellable = a #GCancellable, or %NULL
91 	 *
92 	 * Returns: a new #VtePty for @fd, or %NULL on error with @error filled in
93 	 *
94 	 * Throws: GException on failure.
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this(int fd, Cancellable cancellable)
98 	{
99 		GError* err = null;
100 
101 		auto p = vte_pty_new_foreign_sync(fd, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
102 
103 		if (err !is null)
104 		{
105 			throw new GException( new ErrorG(err) );
106 		}
107 
108 		if(p is null)
109 		{
110 			throw new ConstructionException("null returned by new_foreign_sync");
111 		}
112 
113 		this(cast(VtePty*) p, true);
114 	}
115 
116 	/**
117 	 * Allocates a new pseudo-terminal.
118 	 *
119 	 * You can later use fork() or the g_spawn_async() family of functions
120 	 * to start a process on the PTY.
121 	 *
122 	 * If using fork(), you MUST call vte_pty_child_setup() in the child.
123 	 *
124 	 * If using g_spawn_async() and friends, you MUST either use
125 	 * vte_pty_child_setup() directly as the child setup function, or call
126 	 * vte_pty_child_setup() from your own child setup function supplied.
127 	 *
128 	 * When using vte_terminal_spawn_sync() with a custom child setup
129 	 * function, vte_pty_child_setup() will be called before the supplied
130 	 * function; you must not call it again.
131 	 *
132 	 * Also, you MUST pass the %G_SPAWN_DO_NOT_REAP_CHILD flag.
133 	 *
134 	 * Params:
135 	 *     flags = flags from #VtePtyFlags
136 	 *     cancellable = a #GCancellable, or %NULL
137 	 *
138 	 * Returns: a new #VtePty, or %NULL on error with @error filled in
139 	 *
140 	 * Throws: GException on failure.
141 	 * Throws: ConstructionException GTK+ fails to create the object.
142 	 */
143 	public this(VtePtyFlags flags, Cancellable cancellable)
144 	{
145 		GError* err = null;
146 
147 		auto p = vte_pty_new_sync(flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
148 
149 		if (err !is null)
150 		{
151 			throw new GException( new ErrorG(err) );
152 		}
153 
154 		if(p is null)
155 		{
156 			throw new ConstructionException("null returned by new_sync");
157 		}
158 
159 		this(cast(VtePty*) p, true);
160 	}
161 
162 	/**
163 	 * FIXMEchpe
164 	 */
165 	public void childSetup()
166 	{
167 		vte_pty_child_setup(vtePty);
168 	}
169 
170 	/**
171 	 * Since 0.42 this is a no-op.
172 	 */
173 	public void close()
174 	{
175 		vte_pty_close(vtePty);
176 	}
177 
178 	/**
179 	 * Returns: the file descriptor of the PTY master in @pty. The
180 	 *     file descriptor belongs to @pty and must not be closed
181 	 */
182 	public int getFd()
183 	{
184 		return vte_pty_get_fd(vtePty);
185 	}
186 
187 	/**
188 	 * Reads the pseudo terminal's window size.
189 	 *
190 	 * If getting the window size failed, @error will be set to a #GIOError.
191 	 *
192 	 * Params:
193 	 *     rows = a location to store the number of rows, or %NULL
194 	 *     columns = a location to store the number of columns, or %NULL
195 	 *
196 	 * Returns: %TRUE on success, %FALSE on failure with @error filled in
197 	 *
198 	 * Throws: GException on failure.
199 	 */
200 	public bool getSize(out int rows, out int columns)
201 	{
202 		GError* err = null;
203 
204 		auto p = vte_pty_get_size(vtePty, &rows, &columns, &err) != 0;
205 
206 		if (err !is null)
207 		{
208 			throw new GException( new ErrorG(err) );
209 		}
210 
211 		return p;
212 	}
213 
214 	/**
215 	 * Attempts to resize the pseudo terminal's window size.  If successful, the
216 	 * OS kernel will send #SIGWINCH to the child process group.
217 	 *
218 	 * If setting the window size failed, @error will be set to a #GIOError.
219 	 *
220 	 * Params:
221 	 *     rows = the desired number of rows
222 	 *     columns = the desired number of columns
223 	 *
224 	 * Returns: %TRUE on success, %FALSE on failure with @error filled in
225 	 *
226 	 * Throws: GException on failure.
227 	 */
228 	public bool setSize(int rows, int columns)
229 	{
230 		GError* err = null;
231 
232 		auto p = vte_pty_set_size(vtePty, rows, columns, &err) != 0;
233 
234 		if (err !is null)
235 		{
236 			throw new GException( new ErrorG(err) );
237 		}
238 
239 		return p;
240 	}
241 
242 	/**
243 	 * Tells the kernel whether the terminal is UTF-8 or not, in case it can make
244 	 * use of the info.  Linux 2.6.5 or so defines IUTF8 to make the line
245 	 * discipline do multibyte backspace correctly.
246 	 *
247 	 * Params:
248 	 *     utf8 = whether or not the pty is in UTF-8 mode
249 	 *
250 	 * Returns: %TRUE on success, %FALSE on failure with @error filled in
251 	 *
252 	 * Throws: GException on failure.
253 	 */
254 	public bool setUtf8(bool utf8)
255 	{
256 		GError* err = null;
257 
258 		auto p = vte_pty_set_utf8(vtePty, utf8, &err) != 0;
259 
260 		if (err !is null)
261 		{
262 			throw new GException( new ErrorG(err) );
263 		}
264 
265 		return p;
266 	}
267 
268 	/**
269 	 * Starts the specified command under the pseudo-terminal @pty.
270 	 * The @argv and @envv lists should be %NULL-terminated.
271 	 * The "TERM" environment variable is automatically set to a default value,
272 	 * but can be overridden from @envv.
273 	 * @pty_flags controls logging the session to the specified system log files.
274 	 *
275 	 * Note that %G_SPAWN_DO_NOT_REAP_CHILD will always be added to @spawn_flags.
276 	 *
277 	 * Note that all open file descriptors will be closed in the child. If you want
278 	 * to keep some file descriptor open for use in the child process, you need to
279 	 * use a child setup function that unsets the FD_CLOEXEC flag on that file
280 	 * descriptor.
281 	 *
282 	 * See vte_pty_new(), g_spawn_async() and vte_terminal_watch_child() for more information.
283 	 *
284 	 * Params:
285 	 *     workingDirectory = the name of a directory the command should start
286 	 *         in, or %NULL to use the current working directory
287 	 *     argv = child's argument vector
288 	 *     envv = a list of environment
289 	 *         variables to be added to the environment before starting the process, or %NULL
290 	 *     spawnFlags = flags from #GSpawnFlags
291 	 *     childSetup = an extra child setup function to run in the child just before exec(), or %NULL
292 	 *     childSetupData = user data for @child_setup, or %NULL
293 	 *     childSetupDataDestroy = a #GDestroyNotify for @child_setup_data, or %NULL
294 	 *     timeout = a timeout value in ms, or -1 to wait indefinitely
295 	 *     cancellable = a #GCancellable, or %NULL
296 	 *
297 	 * Since: 0.48
298 	 */
299 	public void spawnAsync(string workingDirectory, string[] argv, string[] envv, GSpawnFlags spawnFlags, GSpawnChildSetupFunc childSetup, void* childSetupData, GDestroyNotify childSetupDataDestroy, int timeout, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
300 	{
301 		vte_pty_spawn_async(vtePty, Str.toStringz(workingDirectory), Str.toStringzArray(argv), Str.toStringzArray(envv), spawnFlags, childSetup, childSetupData, childSetupDataDestroy, timeout, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
302 	}
303 
304 	/**
305 	 *
306 	 * Params:
307 	 *     result = a #GAsyncResult
308 	 *     childPid = a location to store the child PID, or %NULL
309 	 * Returns: %TRUE on success, or %FALSE on error with @error filled in
310 	 *
311 	 * Since: 0.48
312 	 *
313 	 * Throws: GException on failure.
314 	 */
315 	public bool spawnFinish(AsyncResultIF result, out GPid childPid)
316 	{
317 		GError* err = null;
318 
319 		auto p = vte_pty_spawn_finish(vtePty, (result is null) ? null : result.getAsyncResultStruct(), &childPid, &err) != 0;
320 
321 		if (err !is null)
322 		{
323 			throw new GException( new ErrorG(err) );
324 		}
325 
326 		return p;
327 	}
328 }