Terminal init command rework

This commit is contained in:
crschnick 2024-04-21 04:05:23 +00:00
parent 0a3488324d
commit a03f8d7e84
5 changed files with 78 additions and 7 deletions

View file

@ -577,7 +577,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
} }
@Override @Override
public String additionalInitCommands(ShellControl sc) { public TerminalInitFunction additionalInitCommands() {
return TerminalInitFunction.of(sc -> {
if (sc.getShellDialect() == ShellDialects.ZSH) { if (sc.getShellDialect() == ShellDialects.ZSH) {
return "printf '\\eP$f{\"hook\": \"SourcedRcFileForWarp\", \"value\": { \"shell\": \"zsh\"}}\\x9c'"; return "printf '\\eP$f{\"hook\": \"SourcedRcFileForWarp\", \"value\": { \"shell\": \"zsh\"}}\\x9c'";
} }
@ -588,6 +589,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
return "printf '\\eP$f{\"hook\": \"SourcedRcFileForWarp\", \"value\": { \"shell\": \"fish\"}}\\x9c'"; return "printf '\\eP$f{\"hook\": \"SourcedRcFileForWarp\", \"value\": { \"shell\": \"fish\"}}\\x9c'";
} }
return null; return null;
});
} }
}; };
ExternalTerminalType CUSTOM = new CustomTerminalType(); ExternalTerminalType CUSTOM = new CustomTerminalType();
@ -670,8 +672,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
.orElse(null); .orElse(null);
} }
default String additionalInitCommands(ShellControl sc) { default TerminalInitFunction additionalInitCommands() {
return null; return TerminalInitFunction.none();
} }
boolean supportsTabs(); boolean supportsTabs();

View file

@ -32,7 +32,7 @@ public class TerminalLauncher {
title, title,
type.shouldClear() type.shouldClear()
&& AppPrefs.get().clearTerminalOnInit().get(), && AppPrefs.get().clearTerminalOnInit().get(),
type.additionalInitCommands(sc))); null));
var config = new ExternalTerminalType.LaunchConfiguration(null, title, title, script, sc.getShellDialect()); var config = new ExternalTerminalType.LaunchConfiguration(null, title, title, script, sc.getShellDialect());
type.launch(config); type.launch(config);
} }
@ -55,7 +55,7 @@ public class TerminalLauncher {
var terminalConfig = new TerminalInitScriptConfig( var terminalConfig = new TerminalInitScriptConfig(
adjustedTitle, adjustedTitle,
type.shouldClear() && AppPrefs.get().clearTerminalOnInit().get(), type.shouldClear() && AppPrefs.get().clearTerminalOnInit().get(),
cc instanceof ShellControl sc ? type.additionalInitCommands(sc) : null); cc instanceof ShellControl sc ? type.additionalInitCommands() : TerminalInitFunction.none());
var request = UUID.randomUUID(); var request = UUID.randomUUID();
var d = ProcessControlProvider.get().getEffectiveLocalDialect(); var d = ProcessControlProvider.get().getEffectiveLocalDialect();

View file

@ -94,7 +94,7 @@ public interface ShellControl extends ProcessControl {
ShellControl withErrorFormatter(Function<String, String> formatter); ShellControl withErrorFormatter(Function<String, String> formatter);
String prepareIntermediateTerminalOpen( String prepareIntermediateTerminalOpen(
String content, TerminalInitScriptConfig config, WorkingDirectoryFunction workingDirectory) TerminalInitFunction content, TerminalInitScriptConfig config, WorkingDirectoryFunction workingDirectory)
throws Exception; throws Exception;
FilePath getSystemTemporaryDirectory(); FilePath getSystemTemporaryDirectory();

View file

@ -0,0 +1,69 @@
package io.xpipe.core.process;
import io.xpipe.core.util.FailableFunction;
public interface TerminalInitFunction {
static TerminalInitFunction of(FailableFunction<ShellControl, String, Exception> f) {
return new TerminalInitFunction() {
@Override
public boolean isFixed() {
return false;
}
@Override
public boolean isSpecified() {
return true;
}
@Override
public String apply(ShellControl shellControl) throws Exception {
return f.apply(shellControl);
}
};
}
static TerminalInitFunction fixed(String s) {
return new TerminalInitFunction() {
@Override
public boolean isFixed() {
return true;
}
@Override
public boolean isSpecified() {
return true;
}
@Override
public String apply(ShellControl shellControl) {
return s;
}
};
}
static TerminalInitFunction none() {
return new TerminalInitFunction() {
@Override
public boolean isFixed() {
return true;
}
@Override
public boolean isSpecified() {
return false;
}
@Override
public String apply(ShellControl shellControl) {
return null;
}
};
}
boolean isFixed();
boolean isSpecified();
String apply(ShellControl shellControl) throws Exception;
}

View file

@ -7,7 +7,7 @@ public class TerminalInitScriptConfig {
String displayName; String displayName;
boolean clearScreen; boolean clearScreen;
String terminalSpecificCommands; TerminalInitFunction terminalSpecificCommands;
public static TerminalInitScriptConfig ofName(String name) { public static TerminalInitScriptConfig ofName(String name) {
return new TerminalInitScriptConfig(name, true, null); return new TerminalInitScriptConfig(name, true, null);