@@ -111,11 +111,27 @@ The next table demonstrates available API. Left column are `terminal` object pro
111111 the user after execution (prints "NAMESPACE > " as well).
112112 </td>
113113 </tr>
114+ <tr>
115+ <td>onOutput([ <b>options</b> ], <b>callback</b>)</td>
116+ <td>
117+ By default, <code>callback</code>(<u>strings</u>) will be called before the user is
118+ prompted for input, and <code>strings</code> array will always contain an array of
119+ chunks of all the text printed between the prompts. For example, if user writes
120+ <code>write 123</code> and presses "Enter", the <code>strings</code> will contain
121+ this array: <code>["\r\n", "1", "\r\n"]</code>. However, when user enters
122+ <code>write 1, 2, 3</code>, <code>strings</code> will result with
123+ <code>["\r\n", "1", "2", "3", "\r\n"]</code>. You can join this array with
124+ <code>join</code> array method to get the full output.<br/>
125+ Optional <code>options</code> object may include <code>stream</code> property, which
126+ is <code>false</code> by default. When set to <code>true</code>, callback will be
127+ fired any time any chunk is print to the terminal simultaneously.
128+ </td>
129+ </tr>
114130 <tr>
115- <td>onUserInput(<b>cb </b>)</td>
131+ <td>onUserInput(<b>callback </b>)</td>
116132 <td>
117- <b>cb </b>(<u>text</u>, <u>mode</u>) is fired right after user presses enter. Argument
118- <code>text</code> is a <code>String</code> of user input, and
133+ <b>callback </b>(<u>text</u>, <u>mode</u>) is fired right after user presses enter.
134+ Argument <code>text</code> is a <code>String</code> of user input, and
119135 <code>mode</code> is a <code>Number</code>, which can be compared
120136 with one of the terminal mode constants, such as <code>MODE_PROMPT</code>.
121137 </td>
@@ -153,11 +169,18 @@ function myInitHandler (terminal) {
153169 terminal .execute (" set hiddenVariable = 7" , {
154170 echo: false // the default is false, this is just a demo
155171 });
156- terminal .onUserInput (function (text , mode ) {
172+ terminal .onUserInput ((text , mode ) => {
157173 if (mode !== terminal .MODE_PROMPT )
158174 return ;
159175 terminal .print (" \r\n You've just entered the next command: " + text);
160176 });
177+ terminal .onOutput ((chunks ) => {
178+ // If you "write 12", chunks are ["\r\n", "12", "\r\n"].
179+ // If you "write 1, 2", chunks are ["\r\n", "1", "2", "\r\n"].
180+ if (chunks[1 ] === " duck" ) {
181+ alert (` You've found a secret phrase!` );
182+ }
183+ });
161184}
162185
163186// At first, handle iFrame load event. Note that the load handler won't work
0 commit comments