VDBWindowsDebuggerConsoleApplication.st
changeset 71 7329192efb9d
parent 70 66ae724f4269
child 94 e76206d071fc
--- a/VDBWindowsDebuggerConsoleApplication.st	Tue Mar 27 09:03:27 2018 +0100
+++ b/VDBWindowsDebuggerConsoleApplication.st	Wed Apr 04 23:16:30 2018 +0100
@@ -11,10 +11,13 @@
 "{ NameSpace: Smalltalk }"
 
 VDBAbstractApplication subclass:#VDBWindowsDebuggerConsoleApplication
-	instanceVariableNames:'consoleView commandView commandHolder commandHistory
-		pendingCommand'
+	instanceVariableNames:'consoleView consoleInput consoleOutput consoleOutputLock
+		consoleProcess consolePrompt consolePromptPrinted
+		outstandingCommand outstandingCommandToken
+		outstandingCommandBlocker ignoreNextLogStreamEvent completing
+		completions'
 	classVariableNames:''
-	poolDictionaries:''
+	poolDictionaries:'GDBCommandStatus'
 	category:'VDB-UI-Console-Windows'
 !
 
@@ -53,9 +56,9 @@
      the UIPainter may not be able to read the specification."
 
     "
-     UIPainter new openOnClass:VDBAbstractWindowsConsoleApplication andSelector:#windowSpec
-     VDBAbstractWindowsConsoleApplication new openInterface:#windowSpec
-     VDBAbstractWindowsConsoleApplication open
+     UIPainter new openOnClass:VDBConsoleApplication andSelector:#windowSpec
+     VDBConsoleApplication new openInterface:#windowSpec
+     VDBConsoleApplication open
     "
 
     <resource: #canvas>
@@ -63,45 +66,28 @@
     ^ 
     #(FullSpec
        name: windowSpec
-       uuid: 'f62f8c40-f4a2-11e7-be5c-606720e43e2c'
        window: 
       (WindowSpec
-         label: 'Console'
-         name: 'Console'
-         uuid: '574ffdd1-f484-11e7-be5c-606720e43e2c'
+         label: 'Debugger Console'
+         name: 'Debugger Console'
          min: (Point 10 10)
-         bounds: (Rectangle 0 0 769 300)
+         bounds: (Rectangle 0 0 782 332)
        )
        component: 
       (SpecCollection
          collection: (
-          (TextEditorSpec
-             name: 'ConsoleView'
-             layout: (LayoutFrame 0 0 0 0 0 1 -25 1)
-             uuid: '574ffdd2-f484-11e7-be5c-606720e43e2c'
-             hasHorizontalScrollBar: true
-             hasVerticalScrollBar: true
-             hasKeyboardFocusInitially: false
-             postBuildCallback: postBuildConsoleView:
-             viewClassName: 'TextCollector'
-           )
-          (ComboBoxSpec
-             name: 'COmmandBox'
-             layout: (LayoutFrame 0 0 -25 1 0 1 0 1)
-             uuid: '574ffdd3-f484-11e7-be5c-606720e43e2c'
-             model: commandHolder
-             acceptOnLeave: false
-             acceptOnTab: false
-             acceptOnLostFocus: false
-             acceptOnPointerLeave: false
-             acceptIfUnchanged: true
-             comboList: commandHistory
-             postBuildCallback: postBuildCommandView:
+          (ArbitraryComponentSpec
+             name: 'Console'
+             layout: (LayoutFrame 0 0 0 0 0 1 0 1)
+             hasBorder: false
+             component: consoleView
            )
           )
         
        )
      )
+
+    "Modified: / 09-06-2014 / 09:57:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !VDBWindowsDebuggerConsoleApplication class methodsFor:'plugIn spec'!
@@ -125,17 +111,6 @@
 
 !VDBWindowsDebuggerConsoleApplication methodsFor:'actions'!
 
-postBuildCommandView: aComboBox
-    commandView := aComboBox.
-    commandView font: CodeView defaultFont;
-                foregroundColor: Color white
-                backgroundColor: Color black;
-                cursorForegroundColor: Color white
-                      backgroundColor: Color white.
-
-    "Modified: / 08-01-2018 / 19:16:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 postBuildConsoleView: aTextCollector
     consoleView := aTextCollector scrolledView.
     consoleView readOnly: true;       
@@ -146,112 +121,163 @@
                       backgroundColor: Color white.
 
     "Modified: / 08-01-2018 / 19:16:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-send: aString
-    [ 
-        pendingCommand := GDBCommand parse: aString.
-        commandView readOnly: true.
-        debugger send: pendingCommand.            
-    ] on: GDBCommandFailedError do:[
-        "/ Really, we should ignore the error here.
-        1 + 1. "/ this is to trick the static analysis
-    ].
-
-    "Created: / 08-01-2018 / 18:42:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !VDBWindowsDebuggerConsoleApplication methodsFor:'aspects'!
 
-commandHistory
-    commandHistory isNil ifTrue:[
-        commandHistory := List new.
+consoleView
+    consoleView isNil ifTrue:[
+        consoleView := VDBWindowsDebuggerConsoleView new.
+        consoleView foregroundColor: Color white
+                    backgroundColor: Color black;
+                    cursorForegroundColor: Color white
+                          backgroundColor: Color white.     
+        consoleView localEcho:true.
+        consoleView inputTranslateCRToNL:true.
+        consoleView lineEditMode:true.
+        consoleView inStream:consoleInput.
+        consoleView outStream:consoleOutput.
+        consoleView startReaderProcessWhenVisible.
     ].
-    ^ commandHistory.
-
-    "Modified: / 08-01-2018 / 18:43:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-commandHolder
-    <resource: #uiAspect>
-    commandHolder isNil ifTrue:[
-        commandHolder := ValueHolder new.
-        commandHolder addDependent:self.
-    ].
-    ^ commandHolder.
-
-    "Modified: / 08-01-2018 / 18:37:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!VDBWindowsDebuggerConsoleApplication methodsFor:'change & update'!
+    ^ consoleView
 
-update:aspect with:param from:sender
-    "Invoked when an object that I depend upon sends a change notification."
-
-    "stub code automatically generated - please change as required"
-
-    sender == commandHolder ifTrue:[
-         self updateAfterCommandHolderChanged.
-         ^ self.
-    ].
-    super update:aspect with:param from:sender
-
-    "Modified: / 08-01-2018 / 18:39:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-updateAfterCommandHolderChanged
-    (pendingCommand isNil and:[commandHolder value notEmptyOrNil]) ifTrue:[
-        self send: commandHolder value.
-    ]
-
-    "Created: / 08-01-2018 / 18:39:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 26-03-2018 / 18:13:52 / jv"
+    "Created: / 09-06-2014 / 10:11:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 10-06-2014 / 17:40:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-04-2018 / 22:40:59 / jv"
 ! !
 
 !VDBWindowsDebuggerConsoleApplication methodsFor:'event handling'!
 
 onCommandEvent: event
-"/    event command == outstandingCommand ifTrue:[ 
-"/        outstandingCommandToken := event token.
-"/        ignoreNextLogStreamEvent := true.
-"/    ].
+    event command == outstandingCommand ifTrue:[ 
+        outstandingCommandToken := event token.
+        ignoreNextLogStreamEvent := true.
+    ].
 
-    "Created: / 08-01-2018 / 18:51:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 06-06-2014 / 22:43:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-06-2014 / 12:35:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 onCommandResultEvent: event
-    event result command == pendingCommand ifTrue:[            
-        commandHolder value: ''.
-        commandView  readOnly: false.
-        commandView takeFocus.
-        pendingCommand := nil.
+    outstandingCommandToken notNil ifTrue:[ 
+        event token == outstandingCommandToken ifTrue:[ 
+            "/ Check if command ended up with an error. If so,
+            "/ print the error message.
+            event result status == CommandStatusError ifTrue:[ 
+                self showCR: ('Error: %1 ' bindWith: (event result propertyAt: #msg)).
+            ] ifFalse:[
+                "/ Check if the command issues is actually a MI command,
+                "/ if so, print "Done" to the console since MI command don't
+                "/ provide user feedback.
+                outstandingCommand isMICommand ifTrue:[ 
+                    self showCR: ('Done ( %1 , see even log for result value)' bindWith: outstandingCommand value)
+                ].
+            ].
+            outstandingCommand := outstandingCommandToken := nil. 
+            outstandingCommandBlocker signalForAll.     
+        ].
     ].
 
-    "Created: / 08-01-2018 / 18:52:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 06-06-2014 / 22:44:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 27-02-2015 / 13:01:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+onEventSetProcessingFinished: event
+    self showPrompt.
+
+    "Created: / 18-09-2014 / 23:11:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 onLogOutputEvent: event
-"/    ignoreNextLogStreamEvent ifTrue:[ 
-"/        ignoreNextLogStreamEvent := false.
-"/    ] ifFalse:[
-        self onStreamOutputEvent: event  
-"/    ]
+    completing ifTrue:[
+        self halt.
+    ] ifFalse:[
+        ignoreNextLogStreamEvent ifTrue:[ 
+            ignoreNextLogStreamEvent := false.
+        ] ifFalse:[
+            self onStreamOutputEvent: event  
+        ]
+    ].
 
-    "Created: / 08-01-2018 / 18:52:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 11-06-2014 / 12:37:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 16-09-2016 / 01:12:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-04-2018 / 22:50:14 / jv"
 !
 
 onStreamOutputEvent: event
-    event value asStringCollection do:[:line |  
-        line notEmptyOrNil ifTrue:[ 
-            consoleView showCR: line.  
+    completing ifTrue:[
+        completions addAll: event value asStringCollection.
+    ] ifFalse:[
+        consolePromptPrinted ifTrue:[ self showCR:'' ].
+        consolePromptPrinted := false.
+        event value asStringCollection do:[:line |  
+            line notEmptyOrNil ifTrue:[ 
+                self showCR: line.  
+            ].
         ].
     ].
 
-    "Created: / 08-01-2018 / 18:52:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 11-06-2014 / 12:00:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 16-09-2016 / 01:11:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!VDBWindowsDebuggerConsoleApplication methodsFor:'hooks'!
+
+commonPostOpen
+    consoleProcess isNil ifTrue:[
+        consoleProcess := 
+            [
+                [
+                    | cmdLine cmd |
+                    self showPrompt.
+                    cmdLine := consoleInput nextLine asString.
+                    consolePromptPrinted := false.
+                    self showCR: cmdLine.
+                    cmdLine notEmptyOrNil ifTrue:[
+                        cmd := (GDBMIParser on:cmdLine) parseCommand.
+                        cmd isCLICommand ifTrue:[ 
+                            cmd runOnBackground: true.  
+                        ].
+                        outstandingCommand := cmd.
+                        debugger send:cmd andWait:false. 
+                        outstandingCommandBlocker wait.
+                    ]
+                ] loop. 
+            ] newProcess.
+        consoleProcess name: 'VDB Debugger Console REPL loop'.
+        consoleProcess resume.
+    ].
+
+    "Created: / 10-06-2014 / 01:25:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 16-09-2016 / 00:42:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !VDBWindowsDebuggerConsoleApplication methodsFor:'initialization & release'!
 
+initialize
+    super initialize.
+
+    consoleInput := GDBInternalPipeStream new.
+    consoleOutput := GDBInternalPipeStream new.
+    consoleOutputLock := RecursionLock new.
+    consolePrompt := '(gdb) '.
+    consolePromptPrinted := false.
+    outstandingCommandBlocker := Semaphore new.
+    ignoreNextLogStreamEvent := false.
+    completing := false.
+
+    "Created: / 10-06-2014 / 01:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 16-09-2016 / 00:33:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 07-04-2018 / 23:13:27 / jv"
+!
+
+release
+    super release.
+    consoleProcess terminate.
+
+    "Created: / 10-06-2014 / 01:34:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 subscribe   
     "Register for debugger events. To be overrided by subclasses"
 
@@ -261,9 +287,66 @@
 
         when: GDBConsoleOutputEvent      send: #onStreamOutputEvent:     to: self;
         when: GDBTargetOutputEvent       send: #onStreamOutputEvent:     to: self;
-        when: GDBLogOutputEvent          send: #onLogOutputEvent:        to: self.
+        when: GDBLogOutputEvent          send: #onLogOutputEvent:        to: self;
+
+        when: GDBEventSetProcessingFinished send: #onEventSetProcessingFinished: to: self.
+
+    "Created: / 06-06-2014 / 21:26:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 18-09-2014 / 23:11:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!VDBWindowsDebuggerConsoleApplication methodsFor:'private'!
+
+completeLine: aString
+    | result |
+
+    (debugger inferiors allSatisfy:[:inferior | inferior isRunning]) ifTrue:[ 
+        consoleView flash.
+        ^ #()
+    ].
+
+    completing := true.
+    completions := OrderedCollection new.
+    [
+        result := debugger send: 'complete ', aString.
+    ] ensure:[ 
+        completing := false.
+    ].
+    self halt.
+
+    "Created: / 16-09-2016 / 01:09:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
-    "Created: / 08-01-2018 / 18:50:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!VDBWindowsDebuggerConsoleApplication methodsFor:'private - writing'!
+
+show: aString
+    consoleOutputLock critical:[ 
+        consoleOutput nextPutAll: aString.
+    ].
+
+    "Created: / 11-06-2014 / 08:02:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-06-2014 / 11:53:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+showCR: aString
+    consoleOutputLock critical:[ 
+        consoleOutput nextPutAll: aString.
+        consoleOutput nextPut: Character nl.
+        consoleOutput nextPut: Character return.
+    ].
+
+    "Created: / 11-06-2014 / 08:02:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-06-2014 / 11:56:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+showPrompt
+    consolePromptPrinted ifFalse:[
+        self show: consolePrompt.
+        consolePromptPrinted := true.
+    ].
+
+    "Created: / 18-09-2014 / 23:18:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-04-2018 / 23:01:24 / jv"
 ! !
 
 !VDBWindowsDebuggerConsoleApplication class methodsFor:'documentation'!