Skip to content

Commit

Permalink
Add support for several terminal emulator programs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcsosduma authored and nberth committed Apr 9, 2024
1 parent a1576ed commit ba251cf
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 24 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
true,
false,
"vscode",
"xterm",
"gnome-terminal",
"xfce4-terminal",
"konsole",
"external"
]
}
Expand Down
121 changes: 105 additions & 16 deletions src/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ba251cf

Please sign in to comment.