mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-27 15:17:38 +00:00
Fix terminal handling
This commit is contained in:
parent
936806edd6
commit
3e3f81b892
3 changed files with 33 additions and 3 deletions
|
|
@ -58,6 +58,12 @@ struct CreateSessionRequest {
|
||||||
command: Vec<String>,
|
command: Vec<String>,
|
||||||
#[serde(rename = "workingDir")]
|
#[serde(rename = "workingDir")]
|
||||||
working_dir: Option<String>,
|
working_dir: Option<String>,
|
||||||
|
#[serde(default = "default_term_value")]
|
||||||
|
term: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_term_value() -> String {
|
||||||
|
"xterm".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
@ -465,6 +471,7 @@ fn handle_create_session(
|
||||||
let session_id_clone = session_id.clone();
|
let session_id_clone = session_id.clone();
|
||||||
let cmdline_clone = cmdline.clone();
|
let cmdline_clone = cmdline.clone();
|
||||||
let working_dir_clone = current_dir.clone();
|
let working_dir_clone = current_dir.clone();
|
||||||
|
let term_clone = create_request.term.clone();
|
||||||
|
|
||||||
std::thread::Builder::new()
|
std::thread::Builder::new()
|
||||||
.name(format!("session-{}", session_id_clone))
|
.name(format!("session-{}", session_id_clone))
|
||||||
|
|
@ -519,6 +526,9 @@ fn handle_create_session(
|
||||||
.to_string();
|
.to_string();
|
||||||
tty_spawn.session_name(session_name);
|
tty_spawn.session_name(session_name);
|
||||||
|
|
||||||
|
// Set the TERM environment variable
|
||||||
|
tty_spawn.term(term_clone);
|
||||||
|
|
||||||
// Enable detached mode for API-created sessions
|
// Enable detached mode for API-created sessions
|
||||||
tty_spawn.detached(true);
|
tty_spawn.detached(true);
|
||||||
|
|
||||||
|
|
@ -1015,7 +1025,7 @@ fn handle_session_stream_direct(control_path: &PathBuf, path: &str, req: &mut Ht
|
||||||
"width": 80,
|
"width": 80,
|
||||||
"height": 24,
|
"height": 24,
|
||||||
"timestamp": start_time as u64,
|
"timestamp": start_time as u64,
|
||||||
"env": { "TERM": "xterm-256color" }
|
"env": { "TERM": session_entry.session_info.term.clone() }
|
||||||
});
|
});
|
||||||
let data = format!(
|
let data = format!(
|
||||||
"data: {}
|
"data: {}
|
||||||
|
|
@ -1035,7 +1045,7 @@ fn handle_session_stream_direct(control_path: &PathBuf, path: &str, req: &mut Ht
|
||||||
"width": 80,
|
"width": 80,
|
||||||
"height": 24,
|
"height": 24,
|
||||||
"timestamp": start_time as u64,
|
"timestamp": start_time as u64,
|
||||||
"env": { "TERM": "xterm-256color" }
|
"env": { "TERM": session_entry.session_info.term.clone() }
|
||||||
});
|
});
|
||||||
let data = format!(
|
let data = format!(
|
||||||
"data: {}
|
"data: {}
|
||||||
|
|
@ -1204,7 +1214,7 @@ fn handle_stream_all_sessions(control_path: &PathBuf, req: &mut HttpRequest) {
|
||||||
"width": 80,
|
"width": 80,
|
||||||
"height": 24,
|
"height": 24,
|
||||||
"timestamp": start_time as u64,
|
"timestamp": start_time as u64,
|
||||||
"env": { "TERM": "xterm-256color" }
|
"env": { "TERM": "xterm" }
|
||||||
});
|
});
|
||||||
let header_data = format!(
|
let header_data = format!(
|
||||||
"data: {}
|
"data: {}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,12 @@ pub struct SessionInfo {
|
||||||
pub started_at: Option<Timestamp>,
|
pub started_at: Option<Timestamp>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub waiting: bool,
|
pub waiting: bool,
|
||||||
|
#[serde(default = "default_term")]
|
||||||
|
pub term: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_term() -> String {
|
||||||
|
"xterm".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ impl TtySpawn {
|
||||||
session_json_path: None,
|
session_json_path: None,
|
||||||
session_name: None,
|
session_name: None,
|
||||||
detached: false,
|
detached: false,
|
||||||
|
term: "xterm".to_string(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -148,6 +149,12 @@ impl TtySpawn {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the TERM environment variable for the spawned process.
|
||||||
|
pub fn term<S: AsRef<str>>(&mut self, term: S) -> &mut Self {
|
||||||
|
self.options_mut().term = term.as_ref().to_string();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Spawns the application in the TTY.
|
/// Spawns the application in the TTY.
|
||||||
pub fn spawn(&mut self) -> Result<i32, io::Error> {
|
pub fn spawn(&mut self) -> Result<i32, io::Error> {
|
||||||
Ok(spawn(
|
Ok(spawn(
|
||||||
|
|
@ -168,6 +175,7 @@ struct SpawnOptions {
|
||||||
session_json_path: Option<PathBuf>,
|
session_json_path: Option<PathBuf>,
|
||||||
session_name: Option<String>,
|
session_name: Option<String>,
|
||||||
detached: bool,
|
detached: bool,
|
||||||
|
term: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new session JSON file with the provided information
|
/// Creates a new session JSON file with the provided information
|
||||||
|
|
@ -176,6 +184,7 @@ pub fn create_session_info(
|
||||||
cmdline: Vec<String>,
|
cmdline: Vec<String>,
|
||||||
name: String,
|
name: String,
|
||||||
cwd: String,
|
cwd: String,
|
||||||
|
term: String,
|
||||||
) -> Result<(), io::Error> {
|
) -> Result<(), io::Error> {
|
||||||
let session_info = SessionInfo {
|
let session_info = SessionInfo {
|
||||||
cmdline,
|
cmdline,
|
||||||
|
|
@ -186,6 +195,7 @@ pub fn create_session_info(
|
||||||
exit_code: None,
|
exit_code: None,
|
||||||
started_at: Some(Timestamp::now()),
|
started_at: Some(Timestamp::now()),
|
||||||
waiting: false,
|
waiting: false,
|
||||||
|
term,
|
||||||
};
|
};
|
||||||
|
|
||||||
let session_info_str = serde_json::to_string(&session_info)?;
|
let session_info_str = serde_json::to_string(&session_info)?;
|
||||||
|
|
@ -281,6 +291,7 @@ fn spawn(mut opts: SpawnOptions) -> Result<i32, Errno> {
|
||||||
cmdline.clone(),
|
cmdline.clone(),
|
||||||
session_name.clone(),
|
session_name.clone(),
|
||||||
current_dir.clone(),
|
current_dir.clone(),
|
||||||
|
opts.term.clone(),
|
||||||
)
|
)
|
||||||
.map_err(|e| Errno::from_raw(e.raw_os_error().unwrap_or(libc::EIO)))?;
|
.map_err(|e| Errno::from_raw(e.raw_os_error().unwrap_or(libc::EIO)))?;
|
||||||
|
|
||||||
|
|
@ -449,6 +460,9 @@ fn spawn(mut opts: SpawnOptions) -> Result<i32, Errno> {
|
||||||
|
|
||||||
drop(pty.master);
|
drop(pty.master);
|
||||||
if detached {
|
if detached {
|
||||||
|
// Set TERM environment variable for the child process
|
||||||
|
env::set_var("TERM", &opts.term);
|
||||||
|
|
||||||
// In detached mode, manually set up file descriptors without login_tty
|
// In detached mode, manually set up file descriptors without login_tty
|
||||||
// This prevents the child from connecting to the current terminal
|
// This prevents the child from connecting to the current terminal
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue