Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eda8d3b99f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ src/target/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
*txt
|
*txt
|
||||||
|
.gitignore
|
||||||
|
|||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1204,7 +1204,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ostiary"
|
name = "ostiary"
|
||||||
version = "1.1.6"
|
version = "1.1.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ostiary"
|
name = "ostiary"
|
||||||
version = "1.1.6"
|
version = "1.1.7"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use crate::error::{AppError, Result};
|
|||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use libc;
|
use libc;
|
||||||
|
use std::io::Write;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
|
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
|
||||||
@@ -89,13 +90,20 @@ pub fn spawn(
|
|||||||
UnboundedSender<String>,
|
UnboundedSender<String>,
|
||||||
tokio::sync::oneshot::Sender<()>, // kill signal
|
tokio::sync::oneshot::Sender<()>, // kill signal
|
||||||
)> {
|
)> {
|
||||||
|
let random: u32 = rand::random();
|
||||||
|
let script_path = std::env::temp_dir().join(format!("ostiary_{}_{}.sh", std::process::id(), random));
|
||||||
|
{
|
||||||
|
let mut f = std::fs::File::create(&script_path)?;
|
||||||
|
f.write_all(script.as_bytes())?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut child = Command::new("bash")
|
let mut child = Command::new("bash")
|
||||||
.arg("-c")
|
.arg(&script_path)
|
||||||
.arg(script)
|
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()?;
|
.spawn()
|
||||||
|
.inspect_err(|_| { let _ = std::fs::remove_file(&script_path); })?;
|
||||||
|
|
||||||
// Capture the PID before moving child into tasks (needed for kill).
|
// Capture the PID before moving child into tasks (needed for kill).
|
||||||
let pid = child.id();
|
let pid = child.id();
|
||||||
@@ -159,6 +167,7 @@ pub fn spawn(
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let status = child.wait().await;
|
let status = child.wait().await;
|
||||||
let code = status.map(|s| s.code().unwrap_or(1)).unwrap_or(1);
|
let code = status.map(|s| s.code().unwrap_or(1)).unwrap_or(1);
|
||||||
|
let _ = std::fs::remove_file(&script_path);
|
||||||
let _ = finished_tx.send(code);
|
let _ = finished_tx.send(code);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@@ -29,6 +29,8 @@ async fn main() -> Result<()> {
|
|||||||
config::Config::create_with_endpoint(&url, &name)?
|
config::Config::create_with_endpoint(&url, &name)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cleanup_stale_temp_scripts();
|
||||||
|
|
||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
let mut stdout = io::stdout();
|
let mut stdout = io::stdout();
|
||||||
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
||||||
@@ -168,6 +170,19 @@ async fn run_exec(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cleanup_stale_temp_scripts() {
|
||||||
|
let tmp = std::env::temp_dir();
|
||||||
|
if let Ok(entries) = std::fs::read_dir(&tmp) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let name = entry.file_name();
|
||||||
|
let name = name.to_string_lossy();
|
||||||
|
if name.starts_with("ostiary_") && name.ends_with(".sh") {
|
||||||
|
let _ = std::fs::remove_file(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Runs before ratatui starts. Prompts for endpoint URL and name on first launch.
|
/// Runs before ratatui starts. Prompts for endpoint URL and name on first launch.
|
||||||
fn prompt_first_endpoint() -> Result<(String, String)> {
|
fn prompt_first_endpoint() -> Result<(String, String)> {
|
||||||
use std::io::{BufRead, BufReader, Write};
|
use std::io::{BufRead, BufReader, Write};
|
||||||
|
|||||||
Reference in New Issue
Block a user