Add windows terminal preview support

This commit is contained in:
crschnick 2024-01-18 17:15:26 +00:00
parent d9f1a5a769
commit f467d59f49

View file

@ -13,6 +13,7 @@ import lombok.Getter;
import lombok.Value; import lombok.Value;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -88,6 +89,43 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
} }
}; };
ExternalTerminalType WINDOWS_TERMINAL_PREVIEW = new ExternalTerminalType() {
@Override
public void launch(LaunchConfiguration configuration) throws Exception {
// A weird behavior in Windows Terminal causes the trailing
// backslash of a filepath to escape the closing quote in the title argument
// So just remove that slash
var fixedName = FileNames.removeTrailingSlash(configuration.getTitle());
LocalShell.getShell()
.executeSimpleCommand(CommandBuilder.of()
.addFile(getPath().toString())
.add("-w", "1", "nt", "--title")
.addQuoted(fixedName)
.addFile(configuration.getScriptFile()));
}
private Path getPath() {
var local = System.getenv("LOCALAPPDATA");
return Path.of(local).resolve("Microsoft\\WindowsApps\\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\\wt.exe");
}
@Override
public boolean isAvailable() {
return Files.exists(getPath());
}
@Override
public boolean isSelectable() {
return OsType.getLocal().equals(OsType.WINDOWS);
}
@Override
public String getId() {
return "app.windowsTerminalPreview";
}
};
ExternalTerminalType WINDOWS_TERMINAL = new PathType("app.windowsTerminal", "wt.exe") { ExternalTerminalType WINDOWS_TERMINAL = new PathType("app.windowsTerminal", "wt.exe") {
@Override @Override
@ -195,9 +233,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
@Override @Override
protected void execute(Path file, LaunchConfiguration configuration) throws Exception { protected void execute(Path file, LaunchConfiguration configuration) throws Exception {
ThreadHelper.runFailableAsync(() -> { new LocalStore().control().command(CommandBuilder.of().addFile(file.toString()).add("start")
new LocalStore().control().command(CommandBuilder.of().addFile(file.toString()).add("start").addFile(configuration.getScriptFile())).execute(); .addFile(configuration.getScriptFile())).execute();
});
} }
@Override @Override
@ -566,6 +603,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
TABBY_WINDOWS, TABBY_WINDOWS,
ALACRITTY_WINDOWS, ALACRITTY_WINDOWS,
WEZ_WINDOWS, WEZ_WINDOWS,
WINDOWS_TERMINAL_PREVIEW,
WINDOWS_TERMINAL, WINDOWS_TERMINAL,
PWSH_WINDOWS, PWSH_WINDOWS,
POWERSHELL_WINDOWS, POWERSHELL_WINDOWS,