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 	protected override void setStruct(GObject* obj)
62 	{
63 		vtePty = cast(VtePty*)obj;
64 		super.setStruct(obj);
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (VtePty* vtePty, bool ownedRef = false)
71 	{
72 		this.vtePty = vtePty;
73 		super(cast(GObject*)vtePty, ownedRef);
74 	}
75 
76 	// add the Initable capabilities
77 	mixin InitableT!(VtePty);
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return vte_pty_get_type();
84 	}
85 
86 	/**
87 	 * Creates a new #VtePty for the PTY master @fd.
88 	 *
89 	 * No entry will be made in the lastlog, utmp or wtmp system files.
90 	 *
91 	 * Note that the newly created #VtePty will take ownership of @fd
92 	 * and close it on finalize.
93 	 *
94 	 * Params:
95 	 *     fd = a file descriptor to the PTY
96 	 *     cancellable = a #GCancellable, or %NULL
97 	 *
98 	 * Returns: a new #VtePty for @fd, or %NULL on error with @error filled in
99 	 *
100 	 * Throws: GException on failure.
101 	 * Throws: ConstructionException GTK+ fails to create the object.
102 	 */
103 	public this(int fd, Cancellable cancellable)
104 	{
105 		GError* err = null;
106 
107 		auto p = vte_pty_new_foreign_sync(fd, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
108 
109 		if (err !is null)
110 		{
111 			throw new GException( new ErrorG(err) );
112 		}
113 
114 		if(p is null)
115 		{
116 			throw new ConstructionException("null returned by new_foreign_sync");
117 		}
118 
119 		this(cast(VtePty*) p, true);
120 	}
121 
122 	/**
123 	 * Allocates a new pseudo-terminal.
124 	 *
125 	 * You can later use fork() or the g_spawn_async() family of functions
126 	 * to start a process on the PTY.
127 	 *
128 	 * If using fork(), you MUST call vte_pty_child_setup() in the child.
129 	 *
130 	 * If using g_spawn_async() and friends, you MUST either use
131 	 * vte_pty_child_setup() directly as the child setup function, or call
132 	 * vte_pty_child_setup() from your own child setup function supplied.
133 	 *
134 	 * When using vte_terminal_spawn_sync() with a custom child setup
135 	 * function, vte_pty_child_setup() will be called before the supplied
136 	 * function; you must not call it again.
137 	 *
138 	 * Also, you MUST pass the %G_SPAWN_DO_NOT_REAP_CHILD flag.
139 	 *
140 	 * Params:
141 	 *     flags = flags from #VtePtyFlags
142 	 *     cancellable = a #GCancellable, or %NULL
143 	 *
144 	 * Returns: a new #VtePty, or %NULL on error with @error filled in
145 	 *
146 	 * Throws: GException on failure.
147 	 * Throws: ConstructionException GTK+ fails to create the object.
148 	 */
149 	public this(VtePtyFlags flags, Cancellable cancellable)
150 	{
151 		GError* err = null;
152 
153 		auto p = vte_pty_new_sync(flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
154 
155 		if (err !is null)
156 		{
157 			throw new GException( new ErrorG(err) );
158 		}
159 
160 		if(p is null)
161 		{
162 			throw new ConstructionException("null returned by new_sync");
163 		}
164 
165 		this(cast(VtePty*) p, true);
166 	}
167 
168 	/**
169 	 * FIXMEchpe
170 	 */
171 	public void childSetup()
172 	{
173 		vte_pty_child_setup(vtePty);
174 	}
175 
176 	/**
177 	 * Since 0.42 this is a no-op.
178 	 */
179 	public void close()
180 	{
181 		vte_pty_close(vtePty);
182 	}
183 
184 	/**
185 	 * Returns: the file descriptor of the PTY master in @pty. The
186 	 *     file descriptor belongs to @pty and must not be closed
187 	 */
188 	public int getFd()
189 	{
190 		return vte_pty_get_fd(vtePty);
191 	}
192 
193 	/**
194 	 * Reads the pseudo terminal's window size.
195 	 *
196 	 * If getting the window size failed, @error will be set to a #GIOError.
197 	 *
198 	 * Params:
199 	 *     rows = a location to store the number of rows, or %NULL
200 	 *     columns = a location to store the number of columns, or %NULL
201 	 *
202 	 * Returns: %TRUE on success, %FALSE on failure with @error filled in
203 	 *
204 	 * Throws: GException on failure.
205 	 */
206 	public bool getSize(out int rows, out int columns)
207 	{
208 		GError* err = null;
209 
210 		auto p = vte_pty_get_size(vtePty, &rows, &columns, &err) != 0;
211 
212 		if (err !is null)
213 		{
214 			throw new GException( new ErrorG(err) );
215 		}
216 
217 		return p;
218 	}
219 
220 	/**
221 	 * Attempts to resize the pseudo terminal's window size.  If successful, the
222 	 * OS kernel will send #SIGWINCH to the child process group.
223 	 *
224 	 * If setting the window size failed, @error will be set to a #GIOError.
225 	 *
226 	 * Params:
227 	 *     rows = the desired number of rows
228 	 *     columns = the desired number of columns
229 	 *
230 	 * Returns: %TRUE on success, %FALSE on failure with @error filled in
231 	 *
232 	 * Throws: GException on failure.
233 	 */
234 	public bool setSize(int rows, int columns)
235 	{
236 		GError* err = null;
237 
238 		auto p = vte_pty_set_size(vtePty, rows, columns, &err) != 0;
239 
240 		if (err !is null)
241 		{
242 			throw new GException( new ErrorG(err) );
243 		}
244 
245 		return p;
246 	}
247 
248 	/**
249 	 * Tells the kernel whether the terminal is UTF-8 or not, in case it can make
250 	 * use of the info.  Linux 2.6.5 or so defines IUTF8 to make the line
251 	 * discipline do multibyte backspace correctly.
252 	 *
253 	 * Params:
254 	 *     utf8 = whether or not the pty is in UTF-8 mode
255 	 *
256 	 * Returns: %TRUE on success, %FALSE on failure with @error filled in
257 	 *
258 	 * Throws: GException on failure.
259 	 */
260 	public bool setUtf8(bool utf8)
261 	{
262 		GError* err = null;
263 
264 		auto p = vte_pty_set_utf8(vtePty, utf8, &err) != 0;
265 
266 		if (err !is null)
267 		{
268 			throw new GException( new ErrorG(err) );
269 		}
270 
271 		return p;
272 	}
273 
274 	/**
275 	 * Starts the specified command under the pseudo-terminal @pty.
276 	 * The @argv and @envv lists should be %NULL-terminated.
277 	 * The "TERM" environment variable is automatically set to a default value,
278 	 * but can be overridden from @envv.
279 	 * @pty_flags controls logging the session to the specified system log files.
280 	 *
281 	 * Note that %G_SPAWN_DO_NOT_REAP_CHILD will always be added to @spawn_flags.
282 	 *
283 	 * Note that all open file descriptors will be closed in the child. If you want
284 	 * to keep some file descriptor open for use in the child process, you need to
285 	 * use a child setup function that unsets the FD_CLOEXEC flag on that file
286 	 * descriptor.
287 	 *
288 	 * See vte_pty_new(), g_spawn_async() and vte_terminal_watch_child() for more information.
289 	 *
290 	 * Params:
291 	 *     workingDirectory = the name of a directory the command should start
292 	 *         in, or %NULL to use the current working directory
293 	 *     argv = child's argument vector
294 	 *     envv = a list of environment
295 	 *         variables to be added to the environment before starting the process, or %NULL
296 	 *     spawnFlags = flags from #GSpawnFlags
297 	 *     childSetup = an extra child setup function to run in the child just before exec(), or %NULL
298 	 *     childSetupData = user data for @child_setup, or %NULL
299 	 *     childSetupDataDestroy = a #GDestroyNotify for @child_setup_data, or %NULL
300 	 *     timeout = a timeout value in ms, or -1 to wait indefinitely
301 	 *     cancellable = a #GCancellable, or %NULL
302 	 *
303 	 * Since: 0.48
304 	 */
305 	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)
306 	{
307 		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);
308 	}
309 
310 	/**
311 	 *
312 	 * Params:
313 	 *     result = a #GAsyncResult
314 	 *     childPid = a location to store the child PID, or %NULL
315 	 * Returns: %TRUE on success, or %FALSE on error with @error filled in
316 	 *
317 	 * Since: 0.48
318 	 *
319 	 * Throws: GException on failure.
320 	 */
321 	public bool spawnFinish(AsyncResultIF result, out GPid childPid)
322 	{
323 		GError* err = null;
324 
325 		auto p = vte_pty_spawn_finish(vtePty, (result is null) ? null : result.getAsyncResultStruct(), &childPid, &err) != 0;
326 
327 		if (err !is null)
328 		{
329 			throw new GException( new ErrorG(err) );
330 		}
331 
332 		return p;
333 	}
334 }