Skip to content

Commit 6709614

Browse files
committed
Enable Logging and Terminal configuration from IDE
This allows the user to enable logging from within the IDE. When they do this, environment variables will be set to turn on logging to console at Information level with a default set of logging scopes. The program is started with a separate console to allow the logging to be viewed separate from the program (unless the program is $Console:Only and has no graphical view). The terminal configuration is specific for Linux and used for both logging output and $Console programs. It allows the user to configure a terminal emulator to be used for running programs, allowing the output of $Console programs to be viewed from it as well as logging output when enabled. When no terminal is configured we have logic that checks a list of common terminal emulators to see if any of them are availiable, and if so uses a known good configuration for them. The user can change this via a GUI dialog.
1 parent b17c396 commit 6709614

File tree

6 files changed

+306
-26
lines changed

6 files changed

+306
-26
lines changed

source/ide/config/cfg_global.bas

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ DIM SHARED StripDebugSymbols AS LONG
3030
DIM SHARED OptimizeCppProgram AS LONG
3131
DIM SHARED GenerateLicenseFile AS LONG
3232
DIM SHARED UseGuiDialogs AS _UNSIGNED LONG
33+
DIM SHARED DefaultTerminal AS STRING
34+
DIM SHARED LoggingEnabled AS _UNSIGNED LONG
3335

3436
'===== Define and check settings location =====================================
3537
ConfigFolder$ = "settings" 'relative config location inside the qb64pe main folder

source/ide/config/cfg_methods.bas

+8
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ SUB ReadInitialConfig
263263

264264
UseGuiDialogs = ReadWriteBooleanSettingValue%(generalSettingsSection$, "UseGuiDialogs", -1)
265265

266+
DefaultTerminal = ReadWriteStringSettingValue$(generalSettingsSection$, "DefaultTerminal", "")
267+
If DefaultTerminal = "" Then
268+
DefaultTerminal = findWorkingTerminal$
269+
WriteConfigSetting generalSettingsSection$, "DefaultTerminal", DefaultTerminal
270+
End If
271+
272+
LoggingEnabled = ReadWriteBooleanSettingValue%(generalSettingsSection$, "LoggingEnabled", 0)
273+
266274
'--- Mouse settings
267275
result = ReadConfigSetting(mouseSettingsSection$, "SwapMouseButton", value$)
268276
IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN

source/ide/ide_global.bas

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ DIM SHARED FileMenuExportAs AS INTEGER, FileMenuExportAsSubMenuID AS INTEGER
228228
DIM SHARED ViewMenuCompilerWarnings AS INTEGER
229229
DIM SHARED RunMenuID AS INTEGER, RunMenuSaveExeWithSource AS INTEGER, brackethighlight AS INTEGER
230230
DIM SHARED GenerateLicenseEnableMenu AS INTEGER
231+
DIM SHARED LoggingEnableMenu AS INTEGER
231232
DIM SHARED OptionsMenuGuiDialogs AS INTEGER
232233
DIM SHARED DebugMenuID AS INTEGER, DebugMenuCallStack AS INTEGER, DebugMenuWatchListToConsole AS INTEGER
233234
DIM SHARED DebugMenuAutoAddCommand AS INTEGER

source/ide/ide_methods.bas

+181
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ FUNCTION ide2 (ignore)
308308
menuDesc$(m, i - 1) = "Sets string returned by COMMAND$ function"
309309
menu$(m, i) = "-": i = i + 1
310310

311+
LoggingEnableMenu = i
312+
menu$(m, i) = "Display #Logging Output": i = i + 1
313+
menuDesc$(m, i - 1) = "Turns on logging output and displays it in a console window"
314+
IF LoggingEnabled THEN
315+
menu$(RunMenuID, LoggingEnableMenu) = CHR$(7) + menu$(RunMenuID, LoggingEnableMenu)
316+
END IF
317+
311318
RunMenuSaveExeWithSource = i
312319
menu$(m, i) = "Output EXE to Source #Folder": i = i + 1
313320
menuDesc$(m, i - 1) = "Toggles compiling program to QB64-PE's folder or to source folder"
@@ -320,6 +327,10 @@ FUNCTION ide2 (ignore)
320327
IF GenerateLicenseFile THEN
321328
menu$(RunMenuID, GenerateLicenseEnableMenu) = CHR$(7) + menu$(RunMenuID, GenerateLicenseEnableMenu)
322329
END IF
330+
IF os$ = "LNX" AND MacOSX = 0 THEN
331+
menu$(m, i) = "Change #Terminal": i = i + 1
332+
menuDesc$(m, i - 1) = "Configure the terminal used for $CONSOLE and logging output"
333+
END IF
323334
menu$(m, i) = "-": i = i + 1
324335

325336
IF os$ = "LNX" THEN
@@ -5177,6 +5188,21 @@ FUNCTION ide2 (ignore)
51775188

51785189

51795190

5191+
IF MID$(menu$(m, s), 1) = "Display #Logging Output" OR MID$(menu$(m, s), 2) = "Display #Logging Output" THEN
5192+
PCOPY 2, 0
5193+
LoggingEnabled = NOT LoggingEnabled
5194+
WriteConfigSetting generalSettingsSection$, "LoggingEnabled", BoolToTFString$(LoggingEnabled)
5195+
5196+
IF LoggingEnabled THEN
5197+
menu$(RunMenuID, LoggingEnableMenu) = CHR$(7) + "Display #Logging Output"
5198+
ELSE
5199+
menu$(RunMenuID, LoggingEnableMenu) = "Display #Logging Output"
5200+
END IF
5201+
5202+
PCOPY 3, 0: SCREEN , , 3, 0
5203+
GOTO ideloop
5204+
END IF
5205+
51805206
IF RIGHT$(menu$(m, s), 28) = "Output EXE to Source #Folder" THEN
51815207
PCOPY 2, 0
51825208
SaveExeWithSource = NOT SaveExeWithSource
@@ -5207,6 +5233,17 @@ FUNCTION ide2 (ignore)
52075233
GOTO ideloop
52085234
END IF
52095235

5236+
IF menu$(m, s) = "Change #Terminal" THEN
5237+
PCOPY 2, 0
5238+
5239+
ideTerminalBox
5240+
5241+
'retval is ignored
5242+
PCOPY 3, 0: SCREEN , , 3, 0
5243+
GOTO ideloop
5244+
END IF
5245+
5246+
52105247
IF RIGHT$(menu$(m, s), 29) = "#Output Watch List to Console" THEN
52115248
PCOPY 2, 0
52125249
WatchListToConsole = NOT WatchListToConsole
@@ -15785,6 +15822,150 @@ FUNCTION ideCompilerSettingsBox
1578515822
LOOP
1578615823
END FUNCTION
1578715824

15825+
SUB ideTerminalBox
15826+
15827+
'-------- generic dialog box header --------
15828+
PCOPY 0, 2
15829+
PCOPY 0, 1
15830+
SCREEN , , 1, 0
15831+
focus = 1
15832+
DIM p AS idedbptype
15833+
DIM o(1 TO 100) AS idedbotype
15834+
DIM sep AS STRING * 1
15835+
sep = CHR$(0)
15836+
'-------- end of generic dialog box header --------
15837+
15838+
'-------- init --------
15839+
15840+
i = 0
15841+
15842+
idepar p, 60, 7, "Default Terminal"
15843+
15844+
i = i + 1
15845+
PrevFocus = 1
15846+
o(i).typ = 1
15847+
o(i).y = 2
15848+
o(i).nam = idenewtxt("Terminal Command")
15849+
o(i).txt = idenewtxt(DefaultTerminal)
15850+
o(i).sx1 = 0
15851+
o(i).v1 = LEN(DefaultTerminal)
15852+
15853+
i = i + 1
15854+
o(i).typ = 3
15855+
o(i).y = 7
15856+
o(i).txt = idenewtxt("#OK" + sep + "#Cancel")
15857+
o(i).dft = 1
15858+
'-------- end of init --------
15859+
15860+
'-------- generic init --------
15861+
FOR i = 1 TO 100: o(i).par = p: NEXT 'set parent info of objects
15862+
'-------- end of generic init --------
15863+
15864+
DO 'main loop
15865+
15866+
15867+
'-------- generic display dialog box & objects --------
15868+
idedrawpar p
15869+
f = 1: cx = 0: cy = 0
15870+
FOR i = 1 TO 100
15871+
IF o(i).typ THEN
15872+
15873+
'prepare object
15874+
o(i).foc = focus - f 'focus offset
15875+
o(i).cx = 0: o(i).cy = 0
15876+
idedrawobj o(i), f 'display object
15877+
IF o(i).cx THEN cx = o(i).cx: cy = o(i).cy
15878+
END IF
15879+
NEXT i
15880+
lastfocus = f - 1
15881+
'-------- end of generic display dialog box & objects --------
15882+
15883+
'-------- custom display changes --------
15884+
LOCATE p.y + 4, p.x + 2
15885+
PRINT CHR$(34) + "$$" + CHR$(34) + " is replaced with the executable";
15886+
LOCATE p.y + 5, p.x + 2
15887+
PRINT CHR$(34) + "$@" + CHR$(34) + " is replaced with the COMMAND$ string";
15888+
'-------- end of custom display changes --------
15889+
15890+
'update visual page and cursor position
15891+
PCOPY 1, 0
15892+
IF cx THEN SCREEN , , 0, 0: LOCATE cy, cx, 1: SCREEN , , 1, 0
15893+
15894+
'-------- read input --------
15895+
change = 0
15896+
DO
15897+
GetInput
15898+
IF mWHEEL THEN change = 1
15899+
IF KB THEN change = 1
15900+
IF mCLICK THEN mousedown = 1: change = 1
15901+
IF mRELEASE THEN mouseup = 1: change = 1
15902+
IF mB THEN change = 1
15903+
alt = KALT: IF alt <> oldalt THEN change = 1
15904+
oldalt = alt
15905+
_LIMIT 100
15906+
LOOP UNTIL change
15907+
IF alt AND NOT KCTRL THEN idehl = 1 ELSE idehl = 0
15908+
'convert "alt+letter" scancode to letter's ASCII character
15909+
altletter$ = ""
15910+
IF alt AND NOT KCTRL THEN
15911+
IF LEN(K$) = 1 THEN
15912+
k = ASC(UCASE$(K$))
15913+
IF k >= 65 AND k <= 90 THEN altletter$ = CHR$(k)
15914+
END IF
15915+
END IF
15916+
SCREEN , , 0, 0: LOCATE , , 0: SCREEN , , 1, 0
15917+
'-------- end of read input --------
15918+
15919+
'-------- generic input response --------
15920+
info = 0
15921+
IF K$ = "" THEN K$ = CHR$(255)
15922+
IF KSHIFT = 0 AND K$ = CHR$(9) THEN focus = focus + 1
15923+
IF (KSHIFT AND K$ = CHR$(9)) OR (INSTR(_OS$, "MAC") AND K$ = CHR$(25)) THEN focus = focus - 1: K$ = ""
15924+
IF focus < 1 THEN focus = lastfocus
15925+
IF focus > lastfocus THEN focus = 1
15926+
f = 1
15927+
FOR i = 1 TO 100
15928+
t = o(i).typ
15929+
IF t THEN
15930+
focusoffset = focus - f
15931+
ideobjupdate o(i), focus, f, focusoffset, K$, altletter$, mB, mousedown, mouseup, mX, mY, info, mWHEEL
15932+
END IF
15933+
NEXT
15934+
'-------- end of generic input response --------
15935+
15936+
'specific post controls
15937+
IF focus <> PrevFocus THEN
15938+
'Always start with TextBox values selected upon getting focus
15939+
PrevFocus = focus
15940+
IF focus = 1 THEN
15941+
o(focus).v1 = LEN(idetxt(o(focus).txt))
15942+
IF o(focus).v1 > 0 THEN o(focus).issel = -1
15943+
o(focus).sx1 = 0
15944+
END IF
15945+
END IF
15946+
15947+
IF K$ = CHR$(27) OR (focus = 3 AND info <> 0) THEN
15948+
ClearMouse
15949+
EXIT SUB
15950+
END IF
15951+
15952+
IF K$ = CHR$(13) OR (focus = 2 AND info <> 0) THEN
15953+
DefaultTerminal = idetxt(o(1).txt)
15954+
15955+
WriteConfigSetting generalSettingsSection$, "DefaultTerminal", DefaultTerminal
15956+
15957+
ClearMouse
15958+
_KEYCLEAR
15959+
EXIT SUB
15960+
END IF
15961+
'end of custom controls
15962+
15963+
mousedown = 0
15964+
mouseup = 0
15965+
LOOP
15966+
15967+
END SUB
15968+
1578815969
FUNCTION idemessagebox (titlestr$, messagestr$, buttons$)
1578915970

1579015971
'-------- generic dialog box header --------

source/qb64pe.bas

+67-26
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ DEFLNG A-Z
3737
'-------- Optional IDE Component (1/2) --------
3838
'$INCLUDE:'ide\ide_global.bas'
3939

40-
4140
DIM SHARED NoExeSaved AS INTEGER
4241

4342
DIM SHARED vWatchErrorCall$, vWatchNewVariable$, vWatchVariableExclusions$
@@ -898,26 +897,86 @@ IF C = 9 THEN 'run
898897

899898
'execute program
900899

900+
IF LoggingEnabled THEN
901+
ENVIRON "QB64PE_LOG_HANDLERS=console"
902+
ENVIRON "QB64PE_LOG_SCOPES=qb64,libqb,libqb-image,libqb-audio"
903+
ELSE
904+
ENVIRON "QB64PE_LOG_HANDLERS="
905+
ENVIRON "QB64PE_LOG_SCOPES="
906+
END IF
907+
908+
ExecuteLine$ = ""
909+
910+
IF MacOSX THEN
911+
IF path.exe$ = "" THEN path.exe$ = "./"
912+
913+
IF LEFT$(lastBinaryGenerated$, LEN(path.exe$)) = path.exe$ THEN
914+
ExecuteName$ = _FULLPATH$(lastBinaryGenerated$)
915+
ELSE
916+
ExecuteName$ = _FULLPATH$(path.exe$ + lastBinaryGenerated$)
917+
END IF
918+
919+
IF path.exe$ = "./" THEN path.exe$ = ""
920+
921+
IF GetRCStateVar(ConsoleOn) OR LoggingEnabled THEN
922+
IF LoggingEnabled THEN handler$ = "console" ELSE handler$ = ""
923+
924+
generateMacOSLogScript ExecuteName$, handler$, "qb64,libqb,libqb-image,libqb-audio", ModifyCOMMAND$, tmpdir$ + "log.command"
925+
926+
' Spawning a program in a terminal is done via `open`.
927+
' We have to use a separate script to be able to set environment variables for the program
928+
ExecuteLine$ = "open -b com.apple.terminal " + _CHR_QUOTE + tmpdir$ + "log.command" + _CHR_QUOTE
929+
ELSE
930+
ExecuteLine$ = ExecuteName$
931+
END IF
932+
ELSEIF os$ = "WIN" THEN
933+
IF GetRCStateVar(ConsoleOn) OR LoggingEnabled THEN
934+
PrePend$ = "cmd /c"
935+
ELSE
936+
PrePend$ = ""
937+
END IF
938+
939+
ExecuteLine$ = PrePend$ + QuotedFilename$(CHR$(34) + lastBinaryGenerated$ + CHR$(34)) + ModifyCOMMAND$
940+
ELSEIF os$ = "LNX" THEN
941+
IF path.exe$ = "" THEN path.exe$ = "./"
942+
943+
IF GetRCStateVar(ConsoleOn) OR LoggingEnabled THEN
944+
ExecuteLine$ = DefaultTerminal
945+
946+
IF LEFT$(lastBinaryGenerated$, LEN(path.exe$)) = path.exe$ THEN
947+
ExecuteLine$ = StrReplace$(ExecuteLine$, "$$", QuotedFilename$(lastBinaryGenerated$))
948+
ELSE
949+
ExecuteLine$ = StrReplace$(ExecuteLine$, "$$", QuotedFilename$(path.exe$ + lastBinaryGenerated$))
950+
END IF
901951

952+
ExecuteLine$ = StrReplace$(ExecuteLine$, "$@", ModifyCOMMAND$)
953+
ELSE
954+
IF LEFT$(lastBinaryGenerated$, LEN(path.exe$)) = path.exe$ THEN
955+
ExecuteLine$ = QuotedFilename$(lastBinaryGenerated$) + ModifyCOMMAND$
956+
ELSE
957+
ExecuteLine$ = QuotedFilename$(path.exe$ + lastBinaryGenerated$) + ModifyCOMMAND$
958+
END IF
959+
END IF
902960

961+
IF path.exe$ = "./" THEN path.exe$ = ""
962+
END IF
903963

904964
IF iderunmode = 1 THEN
905965
IF NoExeSaved THEN
906966
'This is the section which deals with if the user selected to run the program without
907967
'saving an EXE file to the disk.
908968
'We start off by first running the EXE, and then we delete it from the drive.
909969
'making it a temporary file when all is said and done.
970+
SHELL ExecuteLine$
971+
910972
IF os$ = "WIN" THEN
911-
SHELL QuotedFilename$(CHR$(34) + lastBinaryGenerated$ + CHR$(34)) + ModifyCOMMAND$ 'run the newly created program
912973
SHELL _HIDE _DONTWAIT "del " + QuotedFilename$(CHR$(34) + lastBinaryGenerated$ + CHR$(34)) 'kill it
913974
END IF
914975
IF path.exe$ = "" THEN path.exe$ = "./"
915976
IF os$ = "LNX" THEN
916977
IF LEFT$(lastBinaryGenerated$, LEN(path.exe$)) = path.exe$ THEN
917-
SHELL QuotedFilename$(lastBinaryGenerated$) + ModifyCOMMAND$
918978
KILL lastBinaryGenerated$
919979
ELSE
920-
SHELL QuotedFilename$(path.exe$ + lastBinaryGenerated$) + ModifyCOMMAND$
921980
KILL path.exe$ + lastBinaryGenerated$
922981
END IF
923982
END IF
@@ -927,29 +986,10 @@ IF C = 9 THEN 'run
927986
GOTO sendcommand
928987
END IF
929988

930-
931-
932-
IF os$ = "WIN" THEN SHELL _DONTWAIT QuotedFilename$(CHR$(34) + lastBinaryGenerated$ + CHR$(34)) + ModifyCOMMAND$
933-
IF path.exe$ = "" THEN path.exe$ = "./"
934-
IF os$ = "LNX" THEN
935-
IF LEFT$(lastBinaryGenerated$, LEN(path.exe$)) = path.exe$ THEN
936-
SHELL _DONTWAIT QuotedFilename$(lastBinaryGenerated$) + ModifyCOMMAND$
937-
ELSE
938-
SHELL _DONTWAIT QuotedFilename$(path.exe$ + lastBinaryGenerated$) + ModifyCOMMAND$
939-
END IF
940-
END IF
941-
IF path.exe$ = "./" THEN path.exe$ = ""
989+
SHELL _DONTWAIT ExecuteLine$
942990
ELSE
943-
IF os$ = "WIN" THEN SHELL QuotedFilename$(CHR$(34) + lastBinaryGenerated$ + CHR$(34)) + ModifyCOMMAND$
944-
IF path.exe$ = "" THEN path.exe$ = "./"
945-
IF os$ = "LNX" THEN
946-
IF LEFT$(lastBinaryGenerated$, LEN(path.exe$)) = path.exe$ THEN
947-
SHELL QuotedFilename$(lastBinaryGenerated$) + ModifyCOMMAND$
948-
ELSE
949-
SHELL QuotedFilename$(path.exe$ + lastBinaryGenerated$) + ModifyCOMMAND$
950-
END IF
951-
END IF
952-
IF path.exe$ = "./" THEN path.exe$ = ""
991+
SHELL ExecuteLine$
992+
953993
DO: LOOP UNTIL INKEY$ = ""
954994
DO: LOOP UNTIL _KEYHIT = 0
955995
END IF
@@ -23829,6 +23869,7 @@ END FUNCTION
2382923869
'$INCLUDE:'utilities\type.bas'
2383023870
'$INCLUDE:'utilities\give_error.bas'
2383123871
'$INCLUDE:'utilities\format.bas'
23872+
'$include:'utilities\terminal.bas'
2383223873
'$INCLUDE:'emit\logging.bas'
2383323874

2383423875
DEFLNG A-Z

0 commit comments

Comments
 (0)