mirror of https://github.com/lapce/lapce.git
Add support to set terminal shell
This commit is contained in:
parent
612463fc03
commit
fc7a3b0824
|
@ -2103,6 +2103,7 @@ dependencies = [
|
|||
"toml",
|
||||
"wasmer",
|
||||
"wasmer-wasi",
|
||||
"which",
|
||||
"xi-rope",
|
||||
]
|
||||
|
||||
|
@ -2212,9 +2213,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.101"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21"
|
||||
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
|
||||
|
||||
[[package]]
|
||||
name = "libgit2-sys"
|
||||
|
@ -5384,9 +5385,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.2.2"
|
||||
version = "4.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9"
|
||||
checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae"
|
||||
dependencies = [
|
||||
"either",
|
||||
"lazy_static",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
modal = false
|
||||
color-theme = "Lapce Dark"
|
||||
icon-theme = ""
|
||||
terminal-shell = ""
|
||||
|
||||
[editor]
|
||||
font-family = "Cascadia Code"
|
||||
|
|
|
@ -102,6 +102,8 @@ pub struct LapceConfig {
|
|||
pub modal: bool,
|
||||
#[field_names(desc = "Set the color theme of Lapce")]
|
||||
pub color_theme: String,
|
||||
#[field_names(desc = "Set the terminal Shell")]
|
||||
pub terminal_shell: String,
|
||||
}
|
||||
|
||||
#[derive(FieldNames, Debug, Clone, Deserialize, Serialize, Default)]
|
||||
|
|
|
@ -370,6 +370,7 @@ pub fn new_terminal(
|
|||
&self,
|
||||
term_id: TermId,
|
||||
cwd: Option<PathBuf>,
|
||||
shell: String,
|
||||
raw: Arc<Mutex<RawTerminal>>,
|
||||
) {
|
||||
let _ = self.term_tx.send((term_id, TermEvent::NewTerminal(raw)));
|
||||
|
@ -378,6 +379,7 @@ pub fn new_terminal(
|
|||
&json!({
|
||||
"term_id": term_id,
|
||||
"cwd": cwd,
|
||||
"shell": shell,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -491,6 +491,7 @@ pub fn new(
|
|||
split_id: WidgetId,
|
||||
event_sink: ExtEventSink,
|
||||
proxy: Arc<LapceProxy>,
|
||||
config: &Config,
|
||||
) -> Self {
|
||||
let cwd = workspace.path.as_ref().cloned();
|
||||
let widget_id = WidgetId::next();
|
||||
|
@ -504,8 +505,9 @@ pub fn new(
|
|||
|
||||
let local_proxy = proxy.clone();
|
||||
let local_raw = raw.clone();
|
||||
let shell = config.lapce.terminal_shell.clone();
|
||||
std::thread::spawn(move || {
|
||||
local_proxy.new_terminal(term_id, cwd, local_raw);
|
||||
local_proxy.new_terminal(term_id, cwd, shell, local_raw);
|
||||
});
|
||||
|
||||
Self {
|
||||
|
|
|
@ -5,6 +5,7 @@ authors = ["Dongdong Zhou <dzhou121@gmail.com>"]
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
which = "4.2.5"
|
||||
regex = "1.5.4"
|
||||
grep-searcher = "0.1.8"
|
||||
grep-matcher = "0.1.5"
|
||||
|
|
|
@ -128,6 +128,7 @@ pub enum Notification {
|
|||
NewTerminal {
|
||||
term_id: TermId,
|
||||
cwd: Option<PathBuf>,
|
||||
shell: String,
|
||||
},
|
||||
InstallPlugin {
|
||||
plugin: PluginDescription,
|
||||
|
@ -532,8 +533,12 @@ fn handle_notification(&self, rpc: Notification) {
|
|||
);
|
||||
});
|
||||
}
|
||||
Notification::NewTerminal { term_id, cwd } => {
|
||||
let mut terminal = Terminal::new(term_id, cwd, 50, 10);
|
||||
Notification::NewTerminal {
|
||||
term_id,
|
||||
cwd,
|
||||
shell,
|
||||
} => {
|
||||
let mut terminal = Terminal::new(term_id, cwd, shell, 50, 10);
|
||||
let tx = terminal.tx.clone();
|
||||
self.terminals.lock().insert(term_id, tx);
|
||||
let dispatcher = self.clone();
|
||||
|
|
|
@ -69,6 +69,7 @@ impl Terminal {
|
|||
pub fn new(
|
||||
term_id: TermId,
|
||||
cwd: Option<PathBuf>,
|
||||
shell: String,
|
||||
width: usize,
|
||||
height: usize,
|
||||
) -> Terminal {
|
||||
|
@ -76,11 +77,17 @@ pub fn new(
|
|||
let mut config = TermConfig::default();
|
||||
config.pty_config.working_directory =
|
||||
cwd.or_else(|| BaseDirs::new().map(|d| PathBuf::from(d.home_dir())));
|
||||
config.pty_config.shell =
|
||||
std::env::var("SHELL").ok().map(|shell| Program::WithArgs {
|
||||
program: shell,
|
||||
args: vec!["-l".to_string()],
|
||||
});
|
||||
let shell = shell.trim();
|
||||
if !shell.is_empty() {
|
||||
let mut parts = shell.split(' ');
|
||||
let program = parts.next().unwrap();
|
||||
if let Ok(p) = which::which(program) {
|
||||
config.pty_config.shell = Some(Program::WithArgs {
|
||||
program: p.to_str().unwrap().to_string(),
|
||||
args: parts.map(|p| p.to_string()).collect::<Vec<String>>(),
|
||||
})
|
||||
}
|
||||
}
|
||||
setup_env(&config);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
|
|
|
@ -199,9 +199,7 @@ fn update(
|
|||
env: &Env,
|
||||
) {
|
||||
if data.settings.shown {
|
||||
for child in self.children.iter_mut() {
|
||||
child.update(ctx, data, env);
|
||||
}
|
||||
self.children[self.active].update(ctx, data, env);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,7 +429,6 @@ pub fn new(
|
|||
}
|
||||
|
||||
fn update_children(&mut self, ctx: &mut EventCtx, data: &mut LapceTabData) {
|
||||
println!("update settings children");
|
||||
self.children.clear();
|
||||
|
||||
let (kind, fileds, descs, settings) = match self.kind {
|
||||
|
|
|
@ -493,6 +493,7 @@ pub fn split_terminal(
|
|||
self.split_id,
|
||||
ctx.get_external_handle(),
|
||||
data.proxy.clone(),
|
||||
&data.config,
|
||||
));
|
||||
let terminal = LapceTerminalView::new(&terminal_data);
|
||||
Arc::make_mut(&mut data.terminal)
|
||||
|
@ -896,6 +897,7 @@ fn event(
|
|||
data.terminal.split_id,
|
||||
ctx.get_external_handle(),
|
||||
data.proxy.clone(),
|
||||
&data.config,
|
||||
));
|
||||
let terminal = LapceTerminalView::new(&terminal_data);
|
||||
self.insert_flex_child(
|
||||
|
|
Loading…
Reference in New Issue