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