#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 03 Nov 2016 19:22:42 +0100
changeset 20757 b41faaeaf46e
parent 20756 14201f1661e9
child 20758 212ca877b8af
#FEATURE by cg class: Smalltalk added: #providingDisplayDo: changed: #start provide a display if needed for command line scripts
Smalltalk.st
--- a/Smalltalk.st	Thu Nov 03 18:52:17 2016 +0100
+++ b/Smalltalk.st	Thu Nov 03 19:22:42 2016 +0100
@@ -4060,6 +4060,14 @@
     "Created: / 06-12-2006 / 15:38:17 / cg"
 !
 
+providingDisplayDo:aBlock
+    "/ provide a Display, if needed
+    (Smalltalk at:#Screen) currentScreenQuerySignal handle:[:ex |
+        Display isNil ifTrue:[ self lateOpenDisplay ].
+        ex proceedWith:Display.    
+    ] do:aBlock    
+!
+
 readEvalPrint
     "{ Pragma: +optSpace }"
 
@@ -4334,7 +4342,7 @@
 
         StandAlone ifFalse:[
             self initializeVerboseFlags.
-            
+
             "/
             "/ look for any '-q', '-e', '-l' or '-f' command line arguments
             "/ and handle them;
@@ -4394,31 +4402,35 @@
                 Initializing := false.
 
                 process := [
-                    VerboseStartup == true ifTrue:[
-                        ('Smalltalk [info]: reading script from: "', arg, '".') infoPrintCR.
-                    ].
-                    UserInterrupt handle:[:ex |
-                        Debugging == true ifTrue:[
-                            'user interrupt (type "c" to continue; "x" to exit; "?" for help).' errorPrintCR.
-                            "/ thisContext fullPrintAll.
-                            MiniDebugger enter.
-                            ex proceed.
-                        ].    
-                        self exit:128+(OperatingSystem sigINT).
-                    ] do:[
-                        arg = '-' ifTrue:[
-                            self fileInStream:Stdin
-                                   lazy:nil
-                                   silent:nil
-                                   logged:false
-                                   addPath:nil
-                        ] ifFalse:[
-                            IsSTScript := true.
-                            Smalltalk silentlyLoadingDo:[
-                                self fileIn:arg.
+                    "/ provide a Display, if needed
+                    self providingDisplayDo:[
+                        VerboseStartup == true ifTrue:[
+                            ('Smalltalk [info]: reading script from: "', arg, '".') infoPrintCR.
+                        ].
+                        UserInterrupt handle:[:ex |
+                            Debugging == true ifTrue:[
+                                'user interrupt (type "c" to continue; "x" to exit; "?" for help).' errorPrintCR.
+                                "/ thisContext fullPrintAll.
+                                MiniDebugger enter.
+                                ex proceed.
+                            ].    
+                            self exit:128+(OperatingSystem sigINT).
+                        ] do:[
+                            arg = '-' ifTrue:[
+                                self fileInStream:Stdin
+                                       lazy:nil
+                                       silent:nil
+                                       logged:false
+                                       addPath:nil
+                            ] ifFalse:[
+                                IsSTScript := true.
+                                Smalltalk silentlyLoadingDo:[
+                                    self fileIn:arg.
+                                ].
                             ].
                         ].
                     ].
+                    
                     "/ after the script, if Screen has been opened and there are any open windows,
                     "/ then do not exit
                     Display notNil ifTrue:[
@@ -4509,77 +4521,81 @@
                 ].
 
                 isRepl ifTrue:[
-                    self readEvalPrint.
+                    self providingDisplayDo:[
+                        self readEvalPrint.
+                    ].    
                     self exit.
                 ].
                 
                 process := [
-                    VerboseStartup == true ifTrue:[
-                        ('Smalltalk [info]: executing expression: "', arg, '".') infoPrintCR.
-                    ].
-                    UserInterrupt handle:[:ex |
-                        Debugging == true ifTrue:[
-                            'user interrupt (type "c" to continue; "x" to exit; "?" for help).' errorPrintCR.
-                            "/ thisContext fullPrintAll.
-                            MiniDebugger enter.
-                            ex proceed.
-                        ].    
-                        self exit:128+(OperatingSystem sigINT).
-                    ] do:[
-                        isFilter ifTrue:[
-                            "/ --filter - apply code to each input line.
-                            "/ compile code only once
-                            Compiler
-                                compile:'doIt:line ',arg
-                                forClass:String
-                                notifying:(EvalScriptingErrorHandler new source:arg).
-
-                            [Stdin atEnd] whileFalse:[
-                                |line|
-
-                                line := Stdin nextLine.
-                                line doIt:line.
-                            ].
-                        ] ifFalse:[
-                            (isPrint | isEval) ifTrue:[
-                                "/ --print or --eval
-                                |rslt|
-
-                                rslt := Parser new
-                                            evaluate:arg
-                                            notifying:(EvalScriptingErrorHandler new source:arg)
-                                            compile:true.
-                                isPrint ifTrue:[
-                                    rslt printCR.
+                    self providingDisplayDo:[
+                        VerboseStartup == true ifTrue:[
+                            ('Smalltalk [info]: executing expression: "', arg, '".') infoPrintCR.
+                        ].
+                        UserInterrupt handle:[:ex |
+                            Debugging == true ifTrue:[
+                                'user interrupt (type "c" to continue; "x" to exit; "?" for help).' errorPrintCR.
+                                "/ thisContext fullPrintAll.
+                                MiniDebugger enter.
+                                ex proceed.
+                            ].    
+                            self exit:128+(OperatingSystem sigINT).
+                        ] do:[
+                            isFilter ifTrue:[
+                                "/ --filter - apply code to each input line.
+                                "/ compile code only once
+                                Compiler
+                                    compile:'doIt:line ',arg
+                                    forClass:String
+                                    notifying:(EvalScriptingErrorHandler new source:arg).
+
+                                [Stdin atEnd] whileFalse:[
+                                    |line|
+
+                                    line := Stdin nextLine.
+                                    line doIt:line.
                                 ].
                             ] ifFalse:[
-                                "/ --run <className>
-                                |className class|
-
-                                className := arg.
-                                class := Smalltalk classNamed:className.
-                                class isNil ifTrue:[
-                                    StandAlone := true.
-                                    self exitWithErrorMessage:'no such class: "', className, '".'
-                                ].
-                                (class respondsTo:#main:) ifTrue:[
-                                    class main:CommandLineArguments.
-                                ] ifFalse:[    
-                                    (class respondsTo:#main) ifTrue:[
-                                        class main.
+                                (isPrint | isEval) ifTrue:[
+                                    "/ --print or --eval
+                                    |rslt|
+
+                                    rslt := Parser new
+                                                evaluate:arg
+                                                notifying:(EvalScriptingErrorHandler new source:arg)
+                                                compile:true.
+                                    isPrint ifTrue:[
+                                        rslt printCR.
+                                    ].
+                                ] ifFalse:[
+                                    "/ --run <className>
+                                    |className class|
+
+                                    className := arg.
+                                    class := Smalltalk classNamed:className.
+                                    class isNil ifTrue:[
+                                        StandAlone := true.
+                                        self exitWithErrorMessage:'no such class: "', className, '".'
+                                    ].
+                                    (class respondsTo:#main:) ifTrue:[
+                                        class main:CommandLineArguments.
                                     ] ifFalse:[    
-                                        (class respondsTo:#start) ifTrue:[
-                                            class start.
+                                        (class respondsTo:#main) ifTrue:[
+                                            class main.
                                         ] ifFalse:[    
-                                            StandAlone := true.
-                                            self exitWithErrorMessage:'class has no "main:", "main" or "start" method.'
+                                            (class respondsTo:#start) ifTrue:[
+                                                class start.
+                                            ] ifFalse:[    
+                                                StandAlone := true.
+                                                self exitWithErrorMessage:'class has no "main:", "main" or "start" method.'
+                                            ].    
                                         ].    
                                     ].    
                                 ].    
-                            ].    
+                            ].
                         ].
                     ].
-
+                    
                     "/ after the script, if Screen has been opened and there are any open windows,
                     "/ then do not exit
                     Display notNil ifTrue:[