LocalProcess.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>LocalProcess Class Reference</title>
  5. <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
  6. <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
  7. <meta charset='utf-8'>
  8. <script src="../js/jquery.min.js" defer></script>
  9. <script src="../js/jazzy.js" defer></script>
  10. </head>
  11. <body>
  12. <a name="//apple_ref/swift/Class/LocalProcess" class="dashAnchor"></a>
  13. <a title="LocalProcess Class Reference"></a>
  14. <header>
  15. <div class="content-wrapper">
  16. <p><a href="../index.html">SwiftTerm 1.0 Docs</a> (65% documented)</p>
  17. <p class="header-right"><a href="https://github.com/migueldeicaza/SwiftTerm"><img src="../img/gh.png"/>View on GitHub</a></p>
  18. <p class="header-right"><a href="dash-feed://https%3A%2F%2Fmigueldeicaza%2Egithub%2Eio%2FSwiftTerm%2Fdocsets%2FSwiftTerm%2Exml"><img src="../img/dash.png"/>Install in Dash</a></p>
  19. </div>
  20. </header>
  21. <div class="content-wrapper">
  22. <p id="breadcrumbs">
  23. <a href="../index.html">SwiftTerm Reference</a>
  24. <img id="carat" src="../img/carat.png" />
  25. LocalProcess Class Reference
  26. </p>
  27. </div>
  28. <div class="content-wrapper">
  29. <nav class="sidebar">
  30. <ul class="nav-groups">
  31. <li class="nav-group-name">
  32. <a href="../Classes.html">Classes</a>
  33. <ul class="nav-group-tasks">
  34. <li class="nav-group-task">
  35. <a href="../Classes/Color.html">Color</a>
  36. </li>
  37. <li class="nav-group-task">
  38. <a href="../Classes/HeadlessTerminal.html">HeadlessTerminal</a>
  39. </li>
  40. <li class="nav-group-task">
  41. <a href="../Classes/LocalProcess.html">LocalProcess</a>
  42. </li>
  43. <li class="nav-group-task">
  44. <a href="../Classes/LocalProcessTerminalView.html">LocalProcessTerminalView</a>
  45. </li>
  46. <li class="nav-group-task">
  47. <a href="../Classes/PseudoTerminalHelpers.html">PseudoTerminalHelpers</a>
  48. </li>
  49. <li class="nav-group-task">
  50. <a href="../Classes/Terminal.html">Terminal</a>
  51. </li>
  52. <li class="nav-group-task">
  53. <a href="../Classes/Terminal/MouseMode.html">– MouseMode</a>
  54. </li>
  55. <li class="nav-group-task">
  56. <a href="../Classes/Terminal/WindowManipulationCommand.html">– WindowManipulationCommand</a>
  57. </li>
  58. <li class="nav-group-task">
  59. <a href="../Classes/TerminalAccessory.html">TerminalAccessory</a>
  60. </li>
  61. <li class="nav-group-task">
  62. <a href="../Classes/TerminalDebugView.html">TerminalDebugView</a>
  63. </li>
  64. <li class="nav-group-task">
  65. <a href="../Classes/TerminalView.html">TerminalView</a>
  66. </li>
  67. <li class="nav-group-task">
  68. <a href="../Classes/TerminalView/Font.html">– Font</a>
  69. </li>
  70. <li class="nav-group-task">
  71. <a href="../Classes/TerminalView.html">TerminalView</a>
  72. </li>
  73. <li class="nav-group-task">
  74. <a href="../Classes/TerminalView/Font.html">– Font</a>
  75. </li>
  76. </ul>
  77. </li>
  78. <li class="nav-group-name">
  79. <a href="../Enums.html">Enumerations</a>
  80. <ul class="nav-group-tasks">
  81. <li class="nav-group-task">
  82. <a href="../Enums/CursorStyle.html">CursorStyle</a>
  83. </li>
  84. </ul>
  85. </li>
  86. <li class="nav-group-name">
  87. <a href="../Extensions.html">Extensions</a>
  88. <ul class="nav-group-tasks">
  89. <li class="nav-group-task">
  90. <a href="../Extensions/TerminalViewDelegate.html">TerminalViewDelegate</a>
  91. </li>
  92. </ul>
  93. </li>
  94. <li class="nav-group-name">
  95. <a href="../Protocols.html">Protocols</a>
  96. <ul class="nav-group-tasks">
  97. <li class="nav-group-task">
  98. <a href="../Protocols/LocalProcessDelegate.html">LocalProcessDelegate</a>
  99. </li>
  100. <li class="nav-group-task">
  101. <a href="../Protocols/LocalProcessTerminalViewDelegate.html">LocalProcessTerminalViewDelegate</a>
  102. </li>
  103. <li class="nav-group-task">
  104. <a href="../Protocols/TerminalDelegate.html">TerminalDelegate</a>
  105. </li>
  106. <li class="nav-group-task">
  107. <a href="../Protocols/TerminalViewDelegate.html">TerminalViewDelegate</a>
  108. </li>
  109. </ul>
  110. </li>
  111. <li class="nav-group-name">
  112. <a href="../Structs.html">Structures</a>
  113. <ul class="nav-group-tasks">
  114. <li class="nav-group-task">
  115. <a href="../Structs/Attribute.html">Attribute</a>
  116. </li>
  117. <li class="nav-group-task">
  118. <a href="../Structs/Attribute/Color.html">– Color</a>
  119. </li>
  120. <li class="nav-group-task">
  121. <a href="../Structs/CharData.html">CharData</a>
  122. </li>
  123. <li class="nav-group-task">
  124. <a href="../Structs/CharacterStyle.html">CharacterStyle</a>
  125. </li>
  126. <li class="nav-group-task">
  127. <a href="../Structs/TerminalOptions.html">TerminalOptions</a>
  128. </li>
  129. <li class="nav-group-task">
  130. <a href="../Structs/TinyAtom.html">TinyAtom</a>
  131. </li>
  132. </ul>
  133. </li>
  134. <li class="nav-group-name">
  135. <a href="../Typealiases.html">Type Aliases</a>
  136. <ul class="nav-group-tasks">
  137. <li class="nav-group-task">
  138. <a href="../Typealiases.html#/s:9SwiftTerm7TTImagea">TTImage</a>
  139. </li>
  140. </ul>
  141. </li>
  142. </ul>
  143. </nav>
  144. <article class="main-content">
  145. <section>
  146. <section class="section">
  147. <h1>LocalProcess</h1>
  148. <div class="declaration">
  149. <div class="language">
  150. <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">LocalProcess</span></code></pre>
  151. </div>
  152. </div>
  153. <p>This class provides the capabilities to launch a local Unix process, and connect it to a <code><a href="../Classes/Terminal.html">Terminal</a></code>
  154. class or subclass.</p>
  155. <p>The <code>MacLocalTerminalView</code> is an example of this, it is a subclass of the
  156. <code>MacTerminalView</code> NSView, and it connects that view to the local system, providing a complete
  157. terminal emulator connected to running local commands.</p>
  158. <p>When you create an instance of <code>LocalProcess</code>, you provide a delegate that is used to notify
  159. your application when data is received from the lcoal process, to request the desired window size
  160. that you would like to give to the child process, and when the process terminates.</p>
  161. <p>Once you create this instance, you can start a child process by calling the <code>startProcess</code> method
  162. which will start the process. You can then send data to this underlying process using the
  163. <code>send(data:)</code> method, and you will receive the output on the provided delegate with the
  164. <code>dataReceived(slice:)</code> method.</p>
  165. <p>Received data is dispatched via the queue that you provide in the LocalProcess constructor, if none
  166. is provided, this will default to <code>DispatchQueue.main</code>. Generally, this is a good default, but if you
  167. have your own main loop or a different dispatching system, you will need to pass your own (for example,
  168. the <code><a href="../Classes/HeadlessTerminal.html">HeadlessTerminal</a></code> implementation in the test suite does this.</p>
  169. </section>
  170. <section class="section task-group-section">
  171. <div class="task-group">
  172. <ul>
  173. <li class="item">
  174. <div>
  175. <code>
  176. <a name="/s:9SwiftTerm12LocalProcessC8delegate13dispatchQueueAcA0cD8Delegate_p_So03OS_F6_queueCSgtcfc"></a>
  177. <a name="//apple_ref/swift/Method/init(delegate:dispatchQueue:)" class="dashAnchor"></a>
  178. <a class="token" href="#/s:9SwiftTerm12LocalProcessC8delegate13dispatchQueueAcA0cD8Delegate_p_So03OS_F6_queueCSgtcfc">init(delegate:<wbr>dispatchQueue:<wbr>)</a>
  179. </code>
  180. </div>
  181. <div class="height-container">
  182. <div class="pointer-container"></div>
  183. <section class="section">
  184. <div class="pointer"></div>
  185. <div class="abstract">
  186. <p>Initializes the LocalProcess runner and communication with the host happens via the provided
  187. <code><a href="../Protocols/LocalProcessDelegate.html">LocalProcessDelegate</a></code> instance.</p>
  188. </div>
  189. <div class="declaration">
  190. <h4>Declaration</h4>
  191. <div class="language">
  192. <p class="aside-title">Swift</p>
  193. <pre class="highlight swift"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(</span><span class="nv">delegate</span><span class="p">:</span> <span class="kt"><a href="../Protocols/LocalProcessDelegate.html">LocalProcessDelegate</a></span><span class="p">,</span> <span class="nv">dispatchQueue</span><span class="p">:</span> <span class="kt">DispatchQueue</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>
  194. </div>
  195. </div>
  196. <div>
  197. <h4>Parameters</h4>
  198. <table class="graybox">
  199. <tbody>
  200. <tr>
  201. <td>
  202. <code>
  203. <em>delegate</em>
  204. </code>
  205. </td>
  206. <td>
  207. <div>
  208. <p>the delegate that will receive events or request data from your application</p>
  209. </div>
  210. </td>
  211. </tr>
  212. <tr>
  213. <td>
  214. <code>
  215. <em>dispatchQueue</em>
  216. </code>
  217. </td>
  218. <td>
  219. <div>
  220. <p>this is the queue that will be used to post data received from the
  221. child process when calling the <code>send(dataReceived:)</code> delegate method. If the value provided is <code>nil</code>,
  222. then this will default to <code>DispatchQueue.main</code></p>
  223. </div>
  224. </td>
  225. </tr>
  226. </tbody>
  227. </table>
  228. </div>
  229. <div class="slightly-smaller">
  230. <a href="https://github.com/migueldeicaza/SwiftTerm/tree/master/Sources/SwiftTerm/LocalProcess.swift#L76-L80">Show on GitHub</a>
  231. </div>
  232. </section>
  233. </div>
  234. </li>
  235. <li class="item">
  236. <div>
  237. <code>
  238. <a name="/s:9SwiftTerm12LocalProcessC4send4datays10ArraySliceVys5UInt8VG_tF"></a>
  239. <a name="//apple_ref/swift/Method/send(data:)" class="dashAnchor"></a>
  240. <a class="token" href="#/s:9SwiftTerm12LocalProcessC4send4datays10ArraySliceVys5UInt8VG_tF">send(data:<wbr>)</a>
  241. </code>
  242. </div>
  243. <div class="height-container">
  244. <div class="pointer-container"></div>
  245. <section class="section">
  246. <div class="pointer"></div>
  247. <div class="abstract">
  248. <p>Sends the array slice to the local process using DispatchIO</p>
  249. </div>
  250. <div class="declaration">
  251. <h4>Declaration</h4>
  252. <div class="language">
  253. <p class="aside-title">Swift</p>
  254. <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">send</span><span class="p">(</span><span class="nv">data</span><span class="p">:</span> <span class="kt">ArraySlice</span><span class="o">&lt;</span><span class="kt">UInt8</span><span class="o">&gt;</span><span class="p">)</span></code></pre>
  255. </div>
  256. </div>
  257. <div>
  258. <h4>Parameters</h4>
  259. <table class="graybox">
  260. <tbody>
  261. <tr>
  262. <td>
  263. <code>
  264. <em>data</em>
  265. </code>
  266. </td>
  267. <td>
  268. <div>
  269. <p>The range of bytes to send to the child process</p>
  270. </div>
  271. </td>
  272. </tr>
  273. </tbody>
  274. </table>
  275. </div>
  276. <div class="slightly-smaller">
  277. <a href="https://github.com/migueldeicaza/SwiftTerm/tree/master/Sources/SwiftTerm/LocalProcess.swift#L86-L111">Show on GitHub</a>
  278. </div>
  279. </section>
  280. </div>
  281. </li>
  282. <li class="item">
  283. <div>
  284. <code>
  285. <a name="/s:9SwiftTerm12LocalProcessC05startD010executable4args11environmentySS_SaySSGAHSgtF"></a>
  286. <a name="//apple_ref/swift/Method/startProcess(executable:args:environment:)" class="dashAnchor"></a>
  287. <a class="token" href="#/s:9SwiftTerm12LocalProcessC05startD010executable4args11environmentySS_SaySSGAHSgtF">startProcess(executable:<wbr>args:<wbr>environment:<wbr>)</a>
  288. </code>
  289. </div>
  290. <div class="height-container">
  291. <div class="pointer-container"></div>
  292. <section class="section">
  293. <div class="pointer"></div>
  294. <div class="abstract">
  295. <p>Launches a child process inside a pseudo-terminal</p>
  296. </div>
  297. <div class="declaration">
  298. <h4>Declaration</h4>
  299. <div class="language">
  300. <p class="aside-title">Swift</p>
  301. <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">startProcess</span><span class="p">(</span><span class="nv">executable</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">"/bin/bash"</span><span class="p">,</span> <span class="nv">args</span><span class="p">:</span> <span class="p">[</span><span class="kt">String</span><span class="p">]</span> <span class="o">=</span> <span class="p">[],</span> <span class="nv">environment</span><span class="p">:</span> <span class="p">[</span><span class="kt">String</span><span class="p">]?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>
  302. </div>
  303. </div>
  304. <div>
  305. <h4>Parameters</h4>
  306. <table class="graybox">
  307. <tbody>
  308. <tr>
  309. <td>
  310. <code>
  311. <em>executable</em>
  312. </code>
  313. </td>
  314. <td>
  315. <div>
  316. <p>The executable to launch inside the pseudo terminal, defaults to /bin/bash</p>
  317. </div>
  318. </td>
  319. </tr>
  320. <tr>
  321. <td>
  322. <code>
  323. <em>args</em>
  324. </code>
  325. </td>
  326. <td>
  327. <div>
  328. <p>an array of strings that is passed as the arguments to the underlying process</p>
  329. </div>
  330. </td>
  331. </tr>
  332. <tr>
  333. <td>
  334. <code>
  335. <em>environment</em>
  336. </code>
  337. </td>
  338. <td>
  339. <div>
  340. <p>an array of environment variables to pass to the child process, if this is null, this picks a good set of defaults from <code>Terminal.getEnvironmentVariables</code>.</p>
  341. </div>
  342. </td>
  343. </tr>
  344. </tbody>
  345. </table>
  346. </div>
  347. <div class="slightly-smaller">
  348. <a href="https://github.com/migueldeicaza/SwiftTerm/tree/master/Sources/SwiftTerm/LocalProcess.swift#L170-L203">Show on GitHub</a>
  349. </div>
  350. </section>
  351. </div>
  352. </li>
  353. <li class="item">
  354. <div>
  355. <code>
  356. <a name="/s:9SwiftTerm12LocalProcessC14setHostLogging9directoryySSSg_tF"></a>
  357. <a name="//apple_ref/swift/Method/setHostLogging(directory:)" class="dashAnchor"></a>
  358. <a class="token" href="#/s:9SwiftTerm12LocalProcessC14setHostLogging9directoryySSSg_tF">setHostLogging(directory:<wbr>)</a>
  359. </code>
  360. </div>
  361. <div class="height-container">
  362. <div class="pointer-container"></div>
  363. <section class="section">
  364. <div class="pointer"></div>
  365. <div class="abstract">
  366. <p>Use this method to toggle the logging of data coming from the host, or pass nil to stop</p>
  367. </div>
  368. <div class="declaration">
  369. <h4>Declaration</h4>
  370. <div class="language">
  371. <p class="aside-title">Swift</p>
  372. <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">setHostLogging</span><span class="p">(</span><span class="nv">directory</span><span class="p">:</span> <span class="kt">String</span><span class="p">?)</span></code></pre>
  373. </div>
  374. </div>
  375. <div>
  376. <h4>Parameters</h4>
  377. <table class="graybox">
  378. <tbody>
  379. <tr>
  380. <td>
  381. <code>
  382. <em>directory</em>
  383. </code>
  384. </td>
  385. <td>
  386. <div>
  387. <p>location where the log files will be stored.</p>
  388. </div>
  389. </td>
  390. </tr>
  391. </tbody>
  392. </table>
  393. </div>
  394. <div class="slightly-smaller">
  395. <a href="https://github.com/migueldeicaza/SwiftTerm/tree/master/Sources/SwiftTerm/LocalProcess.swift#L211-L214">Show on GitHub</a>
  396. </div>
  397. </section>
  398. </div>
  399. </li>
  400. </ul>
  401. </div>
  402. </section>
  403. </section>
  404. <section id="footer">
  405. <p>&copy; 2020 <a class="link" href="https://tirania.org/" target="_blank" rel="external">Miguel de Icaza</a>. All rights reserved. (Last updated: 2020-05-30)</p>
  406. <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
  407. </section>
  408. </article>
  409. </div>
  410. </body>
  411. </div>
  412. </html>