chore: removed unneeded file
Signed-off-by: mellobacon <mellodev@outlook.com>
mellobacon committed
May 13, 2024 at 13:36 UTC
b596a7a1de336ea816f4f6c742cd78bc75c2d03f
1 file changed
-84
src-tauri/src/terminal.rs
deleted
-84
@@ -1,84 +0,0 @@
1
-use std::{
2
- io::{BufRead, BufReader, Read, Write},
3
- process::exit,
4
- sync::Arc,
5
- thread::{self},
6
-};
7
-use tauri::{async_runtime::Mutex as AsyncMutex, State};
8
-use portable_pty::{CommandBuilder, PtyPair, PtySize};
9
-
10
-pub struct AppState {
11
- pub(crate) pty_pair: Arc<AsyncMutex<PtyPair>>,
12
- pub(crate) writer: Arc<AsyncMutex<Box<dyn Write + Send>>>,
13
- pub(crate) reader: Arc<AsyncMutex<BufReader<Box<dyn Read + Send>>>>,
14
-}
15
-
16
-pub async fn async_create_shell(state: State<'_, AppState>, path: &str) -> Result<(), String> {
17
- #[cfg(target_os = "windows")]
18
- let mut cmd = CommandBuilder::new("powershell.exe");
19
-
20
- #[cfg(not(target_os = "windows"))]
21
- let mut cmd = CommandBuilder::new("bash");
22
-
23
- // add the $TERM env variable so we can use clear and other commands
24
-
25
- #[cfg(target_os = "windows")]
26
- cmd.env("TERM", "cygwin");
27
-
28
- #[cfg(not(target_os = "windows"))]
29
- cmd.env("TERM", "xterm-256color");
30
-
31
- cmd.cwd(path);
32
-
33
- let mut child = state
34
- .pty_pair
35
- .lock()
36
- .await
37
- .slave
38
- .spawn_command(cmd)
39
- .map_err(|err| err.to_string())?;
40
-
41
- thread::spawn(move || {
42
- let status = child.wait().unwrap();
43
- exit(status.exit_code() as i32)
44
- });
45
- Ok(())
46
-}
47
-pub async fn async_write_to_pty(data: &str, state: State<'_, AppState>) -> Result<(), ()> {
48
- write!(state.writer.lock().await, "{}", data).map_err(|_| ())
49
-}
50
-pub async fn async_read_from_pty(state: State<'_, AppState>) -> Result<Option<String>, ()> {
51
- let mut reader = state.reader.lock().await;
52
- let data = {
53
- // Read all available text
54
- let data = reader.fill_buf().map_err(|_| ())?;
55
-
56
- // Send the data to the webview if necessary
57
- if data.len() > 0 {
58
- std::str::from_utf8(data)
59
- .map(|v| Some(v.to_string()))
60
- .map_err(|_| ())?
61
- } else {
62
- None
63
- }
64
- };
65
-
66
- if let Some(data) = &data {
67
- reader.consume(data.len());
68
- }
69
-
70
- Ok(data)
71
-}
72
-pub async fn async_resize_pty(rows: u16, cols: u16, state: State<'_, AppState>) -> Result<(), ()> {
73
- state
74
- .pty_pair
75
- .lock()
76
- .await
77
- .master
78
- .resize(PtySize {
79
- rows,
80
- cols,
81
- ..Default::default()
82
- })
83
- .map_err(|_| ())
84
-}
\ No newline at end of file