@@ -43,8 +43,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4343- if these Ace enhancements look good, then I can also use them for
4444 Codeopticon as well!
4545
46- - get input/raw_input working
47-
4846- [later] add a codeopticon-style history slider of the user's past
4947 edits (but that might be confusing)
5048
@@ -143,7 +141,7 @@ function updateStepLabels() {
143141 var isLastInstr = myVisualizer . curInstr === ( totalInstrs - 1 ) ;
144142 if ( isLastInstr ) {
145143 if ( myVisualizer . promptForUserInput || myVisualizer . promptForMouseInput ) {
146- $ ( "#curInstr" ) . html ( '<font color="' + brightRed + '">input()/raw_input() not supported in live mode; use the <a href="visualize.html" target="_blank">regular visualizer</a ></font >' ) ;
144+ $ ( "#curInstr" ) . html ( '<b>< font color="' + brightRed + '">Enter user input below:</font ></b >' ) ;
147145 } else if ( myVisualizer . instrLimitReached ) {
148146 $ ( "#curInstr" ) . html ( "Instruction limit reached (" + String ( totalInstrs - 1 ) + " steps)" ) ;
149147 } else {
@@ -153,6 +151,27 @@ function updateStepLabels() {
153151 $ ( "#curInstr" ) . html ( "Step " + String ( myVisualizer . curInstr + 1 ) + " of " + String ( totalInstrs - 1 ) ) ;
154152 }
155153
154+ // handle raw user input
155+ // copied from pytutor.js -- TODO: integrate this code better
156+ var ruiDiv = $ ( '#rawUserInputDiv' ) ;
157+ if ( isLastInstr && myVisualizer . executeCodeWithRawInputFunc &&
158+ myVisualizer . promptForUserInput ) {
159+ ruiDiv . show ( ) ;
160+ ruiDiv . find ( '#userInputPromptStr' ) . html ( myVisualizer . userInputPromptStr ) ;
161+ ruiDiv . find ( '#raw_input_textbox' ) . val ( '' ) ;
162+
163+ // first UNBIND handler so that we don't build up multiple click events
164+ ruiDiv . find ( '#raw_input_submit_btn' )
165+ . unbind ( 'click' )
166+ . click ( function ( ) {
167+ var userInput = ruiDiv . find ( '#raw_input_textbox' ) . val ( ) ;
168+ // advance instruction count by 1 to get to the NEXT instruction
169+ myVisualizer . executeCodeWithRawInputFunc ( userInput , myVisualizer . curInstr + 1 ) ;
170+ } ) ;
171+ } else {
172+ ruiDiv . hide ( ) ; // hide by default
173+ }
174+
156175 // render error (if applicable):
157176 var curEntry = myVisualizer . curTrace [ myVisualizer . curInstr ] ;
158177 if ( curEntry . event == 'exception' ||
@@ -345,7 +364,7 @@ function initAceEditor(height) {
345364 $ . doTimeout ( 'pyInputAceEditorChange' ,
346365 500 , /* go a bit faster than CODE_SNAPSHOT_DEBOUNCE_MS to feel more snappy */
347366 //CODE_SNAPSHOT_DEBOUNCE_MS /* match the value in opt-frontend-common.js for consistency and easy apples-to-apples comparisons later on */,
348- executeCode ) ; // debounce
367+ executeCodeFromScratch ) ; // debounce
349368 clearFrontendError ( ) ;
350369 s . clearAnnotations ( ) ;
351370 } ) ;
@@ -559,8 +578,8 @@ $(document).ready(function() {
559578
560579 $ ( '#cumulativeModeSelector,#heapPrimitivesSelector,#textualMemoryLabelsSelector,#pythonVersionSelector' ) . change ( function ( ) {
561580 setAceMode ( ) ;
562- // force a recompile on a toggle switch
563- executeCode ( ) ;
581+ // force a re-execute on a toggle switch
582+ executeCodeFromScratch ( ) ;
564583 } ) ;
565584
566585 setAceMode ( ) ; // set syntax highlighting at the end
0 commit comments