From ba251cfae08d9af87ce7a8689b311ea6c480ce59 Mon Sep 17 00:00:00 2001 From: marcsosduma <31162117+marcsosduma@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:16:12 +0200 Subject: [PATCH] Add support for several terminal emulator programs --- README.md | 10 +---- package.json | 4 ++ src/mi2.ts | 121 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 111 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 242fcba..cec5ffa 100644 --- a/README.md +++ b/README.md @@ -156,13 +156,6 @@ Add `gdbtty` property to your `launch.json`. Here’s an example: ``` ![GdbTTY](gdbttydisplay.png) -* Linux Requirements: `xterm` - -How to install xterm on Ubuntu: -``` -sudo apt-get install xterm -``` - On Linux you can see the output of the application in Vs Code itself. Add `gdbtty` property with `vscode` value to your `launch.json`. Here is an example: ```json { @@ -179,8 +172,9 @@ On Linux you can see the output of the application in Vs Code itself. Add `gdbtt ``` ![GdbTTY](gdbttyvscode.png) -### Documentation +You can also use these options with `gdbtty`: `xterm`, `gnome-terminal`, `konsole` and `xfce4-terminal`. +### Documentation For a more in depth documentation please check the [Superbol Documentation](https://ocamlpro.com/superbol/) ### Troubleshooting diff --git a/package.json b/package.json index e437aeb..365d467 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,10 @@ true, false, "vscode", + "xterm", + "gnome-terminal", + "xfce4-terminal", + "konsole", "external" ] } diff --git a/src/mi2.ts b/src/mi2.ts index c37f6a1..57d5eeb 100644 --- a/src/mi2.ts +++ b/src/mi2.ts @@ -943,7 +943,7 @@ export class MI2 extends EventEmitter implements IDebugger { try_find++; if (xterm_device != "") break; } - if (xterm_device === "") this.log("stderr", "tty: Install 'xterm' to use gdb's tty option\n"); + if (xterm_device === "") this.log("stderr", "tty: Install a terminal to use gdb's tty option\n"); } if (xterm_device.includes("pts")) { this.gdbArgs.push("--tty=" + xterm_device); @@ -991,24 +991,113 @@ export class MI2 extends EventEmitter implements IDebugger { return strCode; } + isTerminalInstalled(terminalCommand: string): boolean { + try { + ChildProcess.execSync(`command -v ${terminalCommand}`); + return true; + } catch (error) { + return false; + } + } + + createXFCETerminal(sleepVal, target) { + let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target; + let param = "bash -c 'echo \"GnuCOBOL DEBUG\"; sleep " + sleepVal + ";'"; + const xfce4_terminal_args = [ + "--title", "GnuCOBOL Debug - " + dispTarget, + "--font=DejaVu Sans Mono 14", + "--command", param + ] + const xfce_process = ChildProcess.spawn("xfce4-terminal", xfce4_terminal_args, { + detached: true, + stdio: 'ignore' + }); + xfce_process.unref(); + } + + createKDETerminal(sleepVal, target) { + let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target; + let param = "bash -c 'echo \"GnuCOBOL DEBUG\"; sleep " + sleepVal + ";'"; + const konsole_args = [ + "--title", "GnuCOBOL Debug - " + dispTarget, + "--separate", + "--nofork", + "--hold", + "-e", + param + ] + const kde_process = ChildProcess.spawn("konsole", konsole_args, { + detached: true, + stdio: 'ignore' + }); + kde_process.unref(); + } + + createGNOMETerminal(sleepVal, target) { + let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target; + const gnome_terminal_args = [ + "--title", "GnuCOBOL Debug - " + dispTarget, + "--", + "bash", "-c","echo 'GnuCOBOL DEBUG';" + "sleep " + sleepVal + ";" + ] + const gnome_process = ChildProcess.spawn("gnome-terminal", gnome_terminal_args, { + detached: true, + stdio: 'ignore', + }); + gnome_process.unref(); + } + + createXtermTerminal(sleepVal, target) { + let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target; + const xterm_args = [ + "-title", "GnuCOBOL Debug - " + dispTarget, + "-fa", "DejaVu Sans Mono", + "-fs", "14", + "-e", "/usr/bin/tty;" + + "echo 'GnuCOBOL DEBUG';" + + "sleep " + sleepVal + ";" + ] + const xterm_process = ChildProcess.spawn("xterm", xterm_args, { + detached: true, + stdio: 'ignore', + }); + xterm_process.unref(); + } + // Opens a terminal to show the application screen - gdbtty createTerminal(gdbtty, sleepVal, target) { + let findTerminal = true; if (gdbtty != "vscode") { - let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target; - const xterm_args = [ - "-title", "GnuCOBOL Debug - " + dispTarget, - "-fa", "DejaVu Sans Mono", - "-fs", "14", - "-e", "/usr/bin/tty;" + - "echo 'GnuCOBOL DEBUG';" + - "sleep " + sleepVal + ";" - ] - - const xterm_process = ChildProcess.spawn("xterm", xterm_args, { - detached: true, - stdio: 'ignore', - }); - xterm_process.unref(); + if (typeof gdbtty === 'string' && gdbtty!="external") { + if(this.isTerminalInstalled(gdbtty)){ + findTerminal = false; + switch (gdbtty) { + case "xterm": + this.createXtermTerminal(sleepVal, target); + break; + case "gnome-terminal": + this.createGNOMETerminal(sleepVal, target); + break; + case "konsole": + this.createKDETerminal(sleepVal, target); + break; + case "xfce4-terminal": + this.createXFCETerminal(sleepVal, target); + break; + } + } + } + if(findTerminal){ + if(this.isTerminalInstalled("xterm")){ + this.createXtermTerminal(sleepVal, target); + }else if(this.isTerminalInstalled("gnome-terminal")){ + this.createGNOMETerminal(sleepVal, target); + }else if(this.isTerminalInstalled("xfce4-terminal")){ + this.createXFCETerminal(sleepVal, target); + }else if(this.isTerminalInstalled("konsole")){ + this.createKDETerminal(sleepVal, target); + } + } } else { let terminal = this.selectTerminal(); if (!terminal) {