Skip to content

Commit

Permalink
#143: OutputChannelDriver_Modal: Disable redirection to channels that…
Browse files Browse the repository at this point in the history
… do not accept the stream.

E.g. OutputChannelDriver_OpenFiles does not accept "stderr".
  • Loading branch information
Taitava committed Feb 22, 2022
1 parent 1adb7e0 commit 0bb5dd9
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/output_channels/OutputChannelDriver_Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,24 @@ class OutputModal extends Modal {
// Ensure this channel is not excluded
if (!excluded_output_channels.contains(output_channel_name)) {
const output_channel_driver = output_channel_drivers[output_channel_name];
redirect_setting.addButton(button => button
.setButtonText(output_channel_driver.getTitle(output_stream))
.onClick(() => {
// Redirect output to the selected driver
const output_streams: OutputStreams = {};
const textarea_element = textarea_setting.settingEl.find("textarea") as HTMLTextAreaElement;
output_streams[output_stream] =
getSelectionFromTextarea(textarea_element, true) // Use the selection, or...
?? output_textarea.getValue() // ...use the whole text, if nothing is selected.
;
output_channel_driver.initialize(this.plugin, this.t_shell_command, this.shell_command_parsing_result);
output_channel_driver.handle(output_streams, this.exit_code);
textarea_element.focus(); // Bring the focus back to the textarea in order to show a possible highlight (=selection) again.
}),
);
// Ensure the output channel accepts this output stream. E.g. OutputChannelDriver_OpenFiles does not accept "stderr".
if (output_channel_driver.acceptsOutputStream(output_stream)) {
redirect_setting.addButton(button => button
.setButtonText(output_channel_driver.getTitle(output_stream))
.onClick(() => {
// Redirect output to the selected driver
const output_streams: OutputStreams = {};
const textarea_element = textarea_setting.settingEl.find("textarea") as HTMLTextAreaElement;
output_streams[output_stream] =
getSelectionFromTextarea(textarea_element, true) // Use the selection, or...
?? output_textarea.getValue() // ...use the whole text, if nothing is selected.
;
output_channel_driver.initialize(this.plugin, this.t_shell_command, this.shell_command_parsing_result);
output_channel_driver.handle(output_streams, this.exit_code);
textarea_element.focus(); // Bring the focus back to the textarea in order to show a possible highlight (=selection) again.
}),
);
}
}
});

Expand Down

0 comments on commit 0bb5dd9

Please sign in to comment.