Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Option to disable output tab from automatically opening when running code #1177

Open
nonoash opened this issue Sep 21, 2024 · 3 comments

Comments

@nonoash
Copy link

nonoash commented Sep 21, 2024

Is your feature request related to a problem? Please describe.

When using code runner extension and having the output opened in a new window (instead of a tab in vscode panel) whenever i run a script, code runner behavior is to automatically open the output tab, which will open on top of my output window.

Thus this gives me 2 mirrored outputs and kind of ruins the purpose and goal of having output as external window which i prefer.

Describe the solution you'd like

I would like an option in code runner's settings to simply disable the automatic opening of the output tab on running scripts True/False.

With the output tab not opening automatically, the script's output will be only visible on the external output window.

@MaxZhirniy
Copy link

MaxZhirniy commented Oct 4, 2024

Hello! i think It's possible. First let's talk about this: We are currently working in the extensions/formulahendry.code-runner-... folder.
First, let's create a settings item in the package.json file:

"code-runner.showOutputTab" : {
					"type": "boolean",
					"default": true,
					"description": "Show output tab during code execution",
                                        "scope": "resource"
				}

Place this code inside the configurations dictionary, be careful to follow json syntax!
Two step: realize it in code. Open /out/src/codeManager.js
find func:

executeCommandInOutputChannel(executor, appendFile = true) {
        return __awaiter(this, void 0, void 0, function* () {
            this._isRunning = true;
            vscode.commands.executeCommand("setContext", "code-runner.codeRunning", true);
            const clearPreviousOutput = this._config.get("clearPreviousOutput");
            if (clearPreviousOutput) {
                this._outputChannel.clear();
            }
            const showExecutionMessage = this._config.get("showExecutionMessage");
            this._outputChannel.show(this._config.get("preserveFocus"));
            const spawn = require("child_process").spawn;
            const command = yield this.getFinalCommandToRunCodeFile(executor, appendFile);
            if (showExecutionMessage) {
                this._outputChannel.appendLine("[Running] " + command);
            }
            this.sendRunEvent(executor, false);
            const startTime = new Date();
            this._process = spawn(command, [], { cwd: this._cwd, shell: true });
            this._process.stdout.on("data", (data) => {
                this._outputChannel.append(data.toString());
            });
            this._process.stderr.on("data", (data) => {
                this._outputChannel.append(data.toString());
            });
            this._process.on("close", (code) => {
                this._isRunning = false;
                vscode.commands.executeCommand("setContext", "code-runner.codeRunning", false);
                const endTime = new Date();
                const elapsedTime = (endTime.getTime() - startTime.getTime()) / 1000;
                this._outputChannel.appendLine("");
                if (showExecutionMessage) {
                    this._outputChannel.appendLine("[Done] exited with code=" + code + " in " + elapsedTime + " seconds");
                    this._outputChannel.appendLine("");
                }
                if (this._isTmpFile) {
                    fs.unlinkSync(this._codeFile);
                }
            });
        });
    }

And replace string
this._outputChannel.show(this._config.get("preserveFocus")); to this string:

if (this._config.get("showOutputTab")){this._outputChannel.show(this._config.get("preserveFocus"));}

Done!

P.S. After the tests, I can say that everything works if you figured out how to redirect the output to a new window. And sorry for my English))
P.P.S You can configure this in settings, for default Output tab will be shown because this is the optimal solution

@nonoash
Copy link
Author

nonoash commented Oct 5, 2024

Hello! i think It's possible. First let's talk about this: We are currently working in the extensions/formulahendry.code-runner-... folder. First, let's create a settings item in the package.json file:

"code-runner.showOutputTab" : {
					"type": "boolean",
					"default": true,
					"description": "Show output tab during code execution",
                                        "scope": "resource"
				}

Place this code inside the configurations dictionary, be careful to follow json syntax! Two step: realize it in code. Open /out/src/codeManager.js find func:

executeCommandInOutputChannel(executor, appendFile = true) {
        return __awaiter(this, void 0, void 0, function* () {
            this._isRunning = true;
            vscode.commands.executeCommand("setContext", "code-runner.codeRunning", true);
            const clearPreviousOutput = this._config.get("clearPreviousOutput");
            if (clearPreviousOutput) {
                this._outputChannel.clear();
            }
            const showExecutionMessage = this._config.get("showExecutionMessage");
            this._outputChannel.show(this._config.get("preserveFocus"));
            const spawn = require("child_process").spawn;
            const command = yield this.getFinalCommandToRunCodeFile(executor, appendFile);
            if (showExecutionMessage) {
                this._outputChannel.appendLine("[Running] " + command);
            }
            this.sendRunEvent(executor, false);
            const startTime = new Date();
            this._process = spawn(command, [], { cwd: this._cwd, shell: true });
            this._process.stdout.on("data", (data) => {
                this._outputChannel.append(data.toString());
            });
            this._process.stderr.on("data", (data) => {
                this._outputChannel.append(data.toString());
            });
            this._process.on("close", (code) => {
                this._isRunning = false;
                vscode.commands.executeCommand("setContext", "code-runner.codeRunning", false);
                const endTime = new Date();
                const elapsedTime = (endTime.getTime() - startTime.getTime()) / 1000;
                this._outputChannel.appendLine("");
                if (showExecutionMessage) {
                    this._outputChannel.appendLine("[Done] exited with code=" + code + " in " + elapsedTime + " seconds");
                    this._outputChannel.appendLine("");
                }
                if (this._isTmpFile) {
                    fs.unlinkSync(this._codeFile);
                }
            });
        });
    }

And replace string this._outputChannel.show(this._config.get("preserveFocus")); to this string:

if (this._config.get("showOutputTab")){this._outputChannel.show(this._config.get("preserveFocus"));}

Done!

P.S. After the tests, I can say that everything works if you figured out how to redirect the output to a new window. And sorry for my English)) P.P.S You can configure this in settings, for default Output tab will be shown because this is the optimal solution

Thank you very much for this solution, the behavior of not opening automatically the output tab does indeed work.

Unfortunately to my surprise, i realized that the external output window now isn't printing any outputs anymore. It will only print on the external output window if i reopen the output tab (from the sidebar) as if it was needed to be seen to print.
At this point I'm not even sure it's on Coderunner side.

I guess that's what you meant by if you figure out how to redirect the output? I didn't realize it was going to be a problem, I was simply "opening output as new window", thinking it would redirect automatically.
image

@MaxZhirniy
Copy link

MaxZhirniy commented Oct 6, 2024

Thank you very much for this solution, the behavior of not opening automatically the output tab does indeed work.

Unfortunately to my surprise, i realized that the external output window now isn't printing any outputs anymore. It will only print on the external output window if i reopen the output tab (from the sidebar) as if it was needed to be seen to print. At this point I'm not even sure it's on Coderunner side.

I guess that's what you meant by if you figure out how to redirect the output? I didn't realize it was going to be a problem, I was simply "opening output as new window", thinking it would redirect automatically. image

That's exactly what I wanted to say. This is a strange problem, but it's definitely VSCodeAPI's fault. When we open OutputTab in a new window, we actually open a log file, and for some reason it is written only when OutputTab is open (probably an optimization). I've looked for solutions but haven't found any because essentially it's impossible to update OutputTab without opening it. You can use a crutch in the form

 if (this._config.get("code-runner.showOutputTab")) {this._outputChannel.show(true);this._outputChannel.hide();}

but this will cause a flash on the screen and the window will update the content unpredictable, it’s more likely not to update it at all. The API also does not allow opening OutputTab in 1 px, so I don’t know what can be done here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants