version 1.4.6 jv
authorPatrik Svestka <patrik.svestka@gmail.com>
Tue, 18 Jul 2017 14:00:22 +0200
branchjv
changeset 1515 919fad4de40f
parent 1514 4bdcdc52e55a
child 1516 4b143ef7d138
version 1.4.6 [BATCH] printing stdout is done, if possible, via :print_message function [BATCH] when both manual and automatic switches detected - manual wins (--image vs --Ignoreimage) [PS] kicked out the pause when logging is ignored do to locked log file
smalltalk.bat
smalltalk.ps1
--- a/smalltalk.bat	Wed Jul 12 10:25:43 2017 +0200
+++ b/smalltalk.bat	Tue Jul 18 14:00:22 2017 +0200
@@ -53,7 +53,7 @@
 :: Versions =
 :: ==========
 :: This script
-SET batch_script_version=1.4.5
+SET batch_script_version=1.4.6
 :: Smalltalk/X
 SET stx_version=6.2.6
 
@@ -440,17 +440,8 @@
         )
     )
     IF "!stx.verify_print_message!" EQU "TRUE" (
-        IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "==============================="
-            CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "Variable syntax validated.    ="
-            CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "==============================="
-            ECHO:
-        ) ELSE (
-            ECHO "==============================="
-            ECHO "Variable syntax validated.    ="
-            ECHO "==============================="
-            ECHO:
-        )
+        CALL :print_message !use_color! !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "===============================" "Variable syntax validated.    =" "==============================="
+        ECHO:
     )
 )
 
@@ -462,27 +453,11 @@
 :: THEN quick start is used
 IF "!stx.__binary.stx_quick_start!" EQU "TRUE" (
     IF "!stx.__binary.start_with_image!" EQU "TRUE" (
-        IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] Your configuration flawed - compensating."
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] stx_quick_start=TRUE AND start_with_image=TRUE which makes no sense."
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] Using only image functionality. start_with_image=TRUE and stx_quick_start=FALSE"
-        ) ELSE (
-            ECHO "[WARN] Your configuration flawed - compensating."
-            ECHO "[WARN] stx_quick_start=TRUE AND start_with_image=TRUE which makes no sense."
-            ECHO "[WARN] Using only image functionality. start_with_image=TRUE and stx_quick_start=FALSE"
-        )
+        CALL :print_message !use_color! !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] Your configuration flawed - compensating." "[WARN] stx_quick_start=TRUE AND start_with_image=TRUE which makes no sense." "[WARN] Using only image functionality. start_with_image=TRUE and stx_quick_start=FALSE"
         ECHO:
         SET "stx.__binary.stx_quick_start=FALSE"
     ) ELSE IF "!stx.__binary.list_available_images!" EQU "TRUE" (
-        IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] Your configuration flawed - compensating."
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] start_with_image=FALSE, list_available_images=TRUE, AND stx_quick_start=TRUE which makes no sense."
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] Using only stx_quick_start=TRUE"
-        ) ELSE (
-            ECHO "[WARN] Your configuration flawed - compensating."
-            ECHO "[WARN] start_with_image=FALSE, list_available_images=TRUE, AND stx_quick_start=TRUE which makes no sense."
-            ECHO "[WARN] Using only stx_quick_start=TRUE"
-        )
+        CALL :print_message !use_color! !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] Your configuration flawed - compensating." "[WARN] start_with_image=FALSE, list_available_images=TRUE, AND stx_quick_start=TRUE which makes no sense." "[WARN] Using only stx_quick_start=TRUE"
         ECHO:
         SET "stx.__binary.list_available_images=FALSE"
     )
@@ -491,6 +466,7 @@
 :: ==========================================================================
 :: Pair stx.__binary.start_with_image ^& stx.__binary.list_available_images =
 :: ==========================================================================
+:: NOTE: not using :print_message -> sending too many messages
 IF "!stx.__binary.start_with_image!" EQU "FALSE" (
     IF "!stx.__binary.list_available_images!" EQU "TRUE" (
         IF "!use_color!" EQU "TRUE" (
@@ -512,6 +488,7 @@
 :: ============================================================================================
 :: Pair variables (work together) stx.__binary.record_log_file and stx.__binary.append_to_log =
 :: ============================================================================================
+:: NOTE: not using :print_message -> sending too many messages
 IF "!stx.__binary.record_log_file!" EQU "FALSE" (
     IF "!stx.__binary.append_to_log!" EQU "TRUE" (
         ECHO:
@@ -604,13 +581,7 @@
 :: Checking existence of logging directory, if not found all logging is disabled =
 :: ===============================================================================
 IF NOT EXIST "!stx.log_directory!" (
-    IF "!use_color" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] The logging path: !stx.log_directory! NOT found."
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] Logging will be DISABLED."
-        ) ELSE (
-            ECHO "[WARN] The logging path: !stx.log_directory! NOT found."
-            ECHO "[WARN] Logging will be DISABLED."
-        )
+    CALL :print_message !use_color! !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] The logging path: !stx.log_directory! NOT found." "[WARN] Logging will be DISABLED."
     ECHO:
     SET stx.__binary.start_with_image=FALSE
     SET stx.__binary.append_to_log=FALSE
@@ -620,11 +591,7 @@
 :: Checking existence of log file if not found append is disabled =
 :: ================================================================
 IF NOT EXIST "!log_filename!" (
-    IF "!use_color!" EQU "TRUE" (
-        CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] No log file found turning off the append mode."
-    ) ELSE (
-        ECHO "[INFO] No log file found turning off the append mode."
-    )
+    CALL :print_message !use_color! !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] No log file found turning off the append mode."
     ECHO:
     SET stx.__binary.append_to_log=FALSE
 )
@@ -729,13 +696,7 @@
 IF "!stx_manual_switch_detected!" EQU "TRUE" (
     IF "!stx.__binary.cmd_in_powershell!" EQU "TRUE" (
         ECHO:
-        IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] You can not simultaneously pass command-line switches to stx.com and log using CMD PowerShell mode - __binary.cmd_in_powershell=TRUE"
-            CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] Switching off LOGGING and executing only via cmd.exe."
-        ) ELSE (
-            ECHO "[WARN] You can not simultaneously pass command-line switches to stx.com and log using CMD PowerShell mode - __binary.cmd_in_powershell=TRUE"
-            ECHO "[WARN] Switching off LOGGING and executing only via cmd.exe."
-        )
+        CALL :print_message !use_color! !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] You can not simultaneously pass command-line switches to stx.com and log using CMD PowerShell mode - __binary.cmd_in_powershell=TRUE" "[WARN] Switching off LOGGING and executing only via cmd.exe."
         ECHO:
         SET stx.__binary.record_log_file=FALSE
         SET stx.__binary.append_to_log=FALSE
@@ -752,11 +713,7 @@
     IF "!stx.__binary.list_available_images!" EQU "TRUE" (
         REM USER INPUT
         CALL :user_input !stx.image_path! stx.image_name !stx.image_suffix!
-        IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] Loading image =>!stx.image_name:"=!"<= selected by the user."
-        ) ELSE (
-            ECHO "[INFO] Loading image =>!stx.image_name:"=!"<= selected by the user."
-        )
+        CALL :print_message !use_color! !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] Loading image =>!stx.image_name:"=!"<= selected by the user."
         SET user_selected_image="!stx.image_name:"=!"
         IF DEFINED internal_runtime_options (
             SET stx_switch=!stx_switch! !internal_runtime_options! "--image" !user_selected_image!
@@ -765,11 +722,7 @@
         )
         SET user_selected_image=
     ) ELSE (
-        IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] DEFAULT IMAGE: !stx.image_path:"=!!default_image_name:"=! starts"
-        ) ELSE (
-            ECHO "[INFO] DEFAULT IMAGE: !stx.image_path:"=!!default_image_name:"=! starts"
-        )
+        CALL :print_message !use_color! !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] DEFAULT IMAGE: !stx.image_path:"=!!default_image_name:"=! starts"
         IF DEFINED internal_runtime_options (
             SET stx_switch="--image" !default_image_name! !internal_runtime_options! !stx_switch!
         ) ELSE (
@@ -778,7 +731,10 @@
     )
 ) ELSE (
     IF "!stx.__binary.stx_quick_start!" EQU "TRUE" (
-        IF DEFINED internal_runtime_options (
+        IF "!stx_manual_switch_detected!" EQU "TRUE" (
+            CALL :print_message !use_color! !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] Manual switch detected - configuration is ignored"
+            SET stx_switch= !stx_switch!
+        ) ELSE IF DEFINED internal_runtime_options (
             SET stx_switch="--ignoreImage" !stx_switch! !internal_runtime_options! "--quick"
         ) ELSE (
             SET stx_switch="--ignoreImage" !stx_switch! "--quick"
@@ -802,6 +758,7 @@
 :: =============================================================================
 :: Check if the log file is not too big (with jumping into log file directory) =
 :: =============================================================================
+:: NOTE: not using :print_message -> sending too many messages
 :: Changing to log directory
 pushd "!stx.log_directory!"
 IF "!stx.__binary.append_to_log!" EQU "TRUE" (
@@ -854,17 +811,9 @@
     SET exec_command$=CALL !powershell_exec! -WindowStyle Normal -nologo -noninteractive -NoProfile -ExecutionPolicy Bypass -Command "& {!powershell_script_file! -executable '!smalltalk_executable:"=!' -log_file '!stx.log_directory:"=!!log_filename:"=!' -log_file_encoding '!stx.log_file_encoding!' -append_to_log '!stx.__binary.append_to_log!' -cmd_close '!cmd_close!' -PowerShellVersion '!PowerShellVersion!' -cmd_in_powershell '!stx.__binary.cmd_in_powershell!' -stx_manual_switch_detected '!stx_manual_switch_detected!'};"
 ) ELSE (
     ECHO:
-    IF "!use_color!" EQU "TRUE" (
-        CALL :printInColor !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] NO LOGGING"
-        ECHO:
-        CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] User disabled or limitation applies."
-        CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] Executing: cmd.exe !cmd_close:"=! CALL !smalltalk_executable:"=! !stx_switch!"
-    ) ELSE (
-        ECHO "[WARN] NO LOGGING."
-        ECHO:
-        ECHO "[INFO] User disabled or limitation applies."
-        ECHO "[INFO] Executing: cmd.exe !cmd_close:"=! CALL !smalltalk_executable:"=! !stx_switch!"
-    )
+    CALL :print_message !use_color! !stx.stdout_WarningBackgroundColor! !stx.stdout_WarningForegroundColor! "[WARN] NO LOGGING"
+    ECHO:
+    CALL :print_message !use_color! !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] User disabled or limitation applies." "[INFO] Executing: cmd.exe !cmd_close:"=! CALL !smalltalk_executable:"=! !stx_switch!"
     SET "exec_command$=cmd.exe !cmd_close! CALL !smalltalk_executable:"=! !stx_switch!"
 )
 
@@ -938,27 +887,13 @@
 IF "!__numeric.exit_value!" NEQ "0" (
     IF "%~1" NEQ "" (
         ECHO:
-        IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_ErrorForegroundColor! !stx.stdout_ErrorBackgroundColor! "[ERROR] "%1""
-        ) ELSE (
-            ECHO "%~1"
-        )
+        CALL :print_message !use_color! !stx.stdout_ErrorForegroundColor! !stx.stdout_ErrorBackgroundColor! "[ERROR] "%1""
     )
     IF "%~2" NEQ "" (
-        IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_ErrorForegroundColor! !stx.stdout_ErrorBackgroundColor! "[ERROR] "%2""
-        ) ELSE (
-            ECHO "%~2"
-        )
+        CALL :print_message !use_color! !stx.stdout_ErrorForegroundColor! !stx.stdout_ErrorBackgroundColor! "[ERROR] "%2""
     )
     ECHO:
-    IF "!use_color!" EQU "TRUE" (
-        CALL :printInColor !stx.stdout_ErrorForegroundColor! !stx.stdout_ErrorBackgroundColor! "[ERROR] Exiting with error. Script __numeric.exit_value: !__numeric.exit_value!."
-        CALL :printInColor !stx.stdout_ErrorForegroundColor! !stx.stdout_ErrorForegroundColor! "[ERROR] Batch errorlevel: !ERRORLEVEL!"
-    ) ELSE (
-        ECHO "[ERROR] Exiting with error. Script __numeric.exit_value: !__numeric.exit_value!."
-        ECHO "[ERROR] Batch errorlevel: !ERRORLEVEL!"
-    )
+    CALL :print_message !use_color! !stx.stdout_ErrorForegroundColor! !stx.stdout_ErrorBackgroundColor! "[ERROR] Exiting with error. Script __numeric.exit_value: !__numeric.exit_value!." "[ERROR] Batch errorlevel: !ERRORLEVEL!"
     PAUSE
     REM Cleanup namespace stx.
     REM nul redirection stops error output if no stx. var is set
@@ -970,11 +905,7 @@
     EXIT /B 1
 ) ELSE (
     ECHO:
-    IF "!use_color!" EQU "TRUE" (
-            CALL :printInColor !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] Exiting correctly."
-    ) ELSE (
-            ECHO "[INFO] Exiting correctly."
-    )
+    CALL :print_message !use_color! !stx.stdout_VerboseBackgroundColor! !stx.stdout_VerboseForegroundColor! "[INFO] Exiting correctly."
     REM Cleanup namespace stx.
     REM nul redirection stops error output if no stx. var is set
     FOR /F "tokens=1 delims==" %%V IN ('SET stx. 2^>NUL') DO (
@@ -1189,6 +1120,44 @@
 
 EXIT /B
 
+:print_message
+SET "use_color=%1"
+SET "stdout_VerboseBackgroundColor=%2"
+SET "stdout_VerboseForegroundColor=%3"
+REM ECHO here.
+REM ECHO %use_color%
+REM ECHO %stdout_VerboseBackgroundColor%
+REM ECHO %stdout_VerboseForegroundColor%
+REM pause
+SET "message1=%4"
+SET "message2=%5"
+SET "message3=%6"
+
+IF "%use_color%" EQU "TRUE" (
+    IF DEFINED message1 (
+        CALL :printInColor %stdout_VerboseBackgroundColor% %stdout_VerboseForegroundColor% %message1%
+    ) ELSE (
+        CALL :printInColor %stdout_VerboseBackgroundColor% %stdout_VerboseForegroundColor% "[ERROR] No message defined."
+    )
+    IF DEFINED message2 (
+        CALL :printInColor %stdout_VerboseBackgroundColor% %stdout_VerboseForegroundColor% %message2%
+        IF DEFINED message3 (
+            CALL :printInColor %stdout_VerboseBackgroundColor% %stdout_VerboseForegroundColor% %message2%
+        )
+    )
+) ELSE (
+    IF DEFINED message1 (
+        ECHO "%message1%"
+    ) ELSE (
+        ECHO "[ERROR] No message defined."
+    )
+    IF DEFINED message2 (
+        ECHO "%message2%"
+        IF DEFINED message3 (
+            ECHO "%message3%"
+        )
+    )
+)
 
 :: ======================================
 :: Native Shell coloring for Windows 10 =
--- a/smalltalk.ps1	Wed Jul 12 10:25:43 2017 +0200
+++ b/smalltalk.ps1	Tue Jul 18 14:00:22 2017 +0200
@@ -14,6 +14,7 @@
 # ===========================================================================
 # StX switches which are build during batch file execution $env:stx_switch;
 $stx_switch = [environment]::GetEnvironmentVariable("stx_switch");
+
 # PowerShell version detected during batch file execution  $env:powershell_version_all_functionality;
 $stx_powershell_version = [environment]::GetEnvironmentVariable("powershell_version_all_functionality");
 # getting line width for the log file
@@ -148,6 +149,7 @@
        $execute_command
     )
     try {
+       "`n", "[INFO] Executing command: $execute_command" | PrintMessage;
        Invoke-Expression -Command:$execute_command
        If ($lastexitcode -ne 0) {
            $result = $result -join "`n";
@@ -219,8 +221,8 @@
 If ($is_logfile_locked){
     "`n", "[WARN] Log file $log_file in use.`n`n  !!NO LOGGING will be available for this Smalltalk/X instance!!" | PrintMessage;
     '[INFO] Press any key to continue ...' | PrintMessage;
-    # waits for pressing any key
-    $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-null;
+    # pause - waits for pressing any key
+    # $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-null;
     $logging_function = "Tee-Host | Out-null";
 } Else {
     If ($append_to_log) {