mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-06-30 20:10:57 +12:00
Terminal init command rework
This commit is contained in:
parent
0a3488324d
commit
a03f8d7e84
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue