Skip to content

Commit

Permalink
设置前台进程组
Browse files Browse the repository at this point in the history
  • Loading branch information
MemoryShore committed Oct 1, 2024
1 parent 6c1ca14 commit 9c6d970
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/shell/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ impl Shell {
.expect("Failed to execute command");

if !run_backend {
let _ = child.wait();
unsafe {
libc::tcsetpgrp(libc::STDIN_FILENO, child.id() as i32);
let _ = child.wait();
libc::tcsetpgrp(libc::STDIN_FILENO, std::process::id() as i32);
};
} else {
self.add_backend_task(child);
}
Expand Down
15 changes: 5 additions & 10 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,24 @@ impl Shell {
}

pub fn exec(&mut self) {
// 开启终端raw模式
// 设置前台进程组
unsafe {
libc::tcsetpgrp(libc::STDIN_FILENO, std::process::id() as i32);
};

// 开启终端raw模式
crossterm::terminal::enable_raw_mode().expect("failed to enable raw mode");

// 循环读取一行

// 循环读取一行
loop {
self.printer.init_before_readline();
// 读取一行
// 读取一行
if self.readline() == 0 {
println!();
break;
}

let command_bytes = self.printer.buf.borrow().clone();

// 如果命令不以空格开头且不跟上一条命令相同,这条命令会被记录

// 如果命令不以空格开头且不跟上一条命令相同,这条命令会被记录
if !command_bytes.is_empty()
&& !command_bytes.starts_with(&[b' '])
Expand All @@ -87,9 +85,6 @@ impl Shell {
.push(Rc::new(RefCell::new(command_bytes.clone())));
self.write_commands(&command_bytes);
};

// 命令不为空,执行命令

// 命令不为空,执行命令
if !command_bytes.iter().all(|&byte| byte == b' ') {
self.exec_commands_in_line(&command_bytes);
Expand Down

0 comments on commit 9c6d970

Please sign in to comment.