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