new additions : What's new

 Rust PTY backend (portable-pty)
     - pty_spawn / pty_write / pty_resize / pty_kill commands
     - Output streamed via pty:data Tauri events (base64-encoded bytes)
     - Spawns /bin/bash (falls back to /bin/bash), starts in /home/code
   xterm.js terminal card (full ANSI + true color)
   Toolbar (top-left) with + Note / + Terminal
   Shared useDragHandle hook (notes + terminals)
   Terminal font-size scales with canvas zoom → crisp at any zoom
   Terminal auto-refits when card resizes or zoom changes
This commit is contained in:
Haapy
2026-05-14 22:22:18 +00:00
parent eaeb4c2d92
commit c3552d08b9
192 changed files with 44595 additions and 132 deletions

165
src-tauri/Cargo.lock generated
View File

@@ -79,12 +79,15 @@ checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
name = "app"
version = "0.1.0"
dependencies = [
"base64 0.22.1",
"log",
"portable-pty",
"serde",
"serde_json",
"tauri",
"tauri-build",
"tauri-plugin-log",
"uuid",
]
[[package]]
@@ -753,6 +756,12 @@ dependencies = [
"tendril",
]
[[package]]
name = "downcast-rs"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
[[package]]
name = "dpi"
version = "0.1.2"
@@ -815,7 +824,7 @@ dependencies = [
"rustc_version",
"toml 1.1.2+spec-1.1.0",
"vswhom",
"winreg",
"winreg 0.55.0",
]
[[package]]
@@ -881,10 +890,21 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f"
dependencies = [
"memoffset",
"memoffset 0.9.1",
"rustc_version",
]
[[package]]
name = "filedescriptor"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e40758ed24c9b2eeb76c35fb0aebc66c626084edd827e07e1552279814c6682d"
dependencies = [
"libc",
"thiserror 1.0.69",
"winapi",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.9"
@@ -1640,6 +1660,15 @@ dependencies = [
"cfb",
]
[[package]]
name = "ioctl-rs"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7970510895cee30b3e9128319f2cefd4bde883a39f38baa279567ba3a7eb97d"
dependencies = [
"libc",
]
[[package]]
name = "ipnet"
version = "2.12.0"
@@ -1764,6 +1793,12 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "leb128fmt"
version = "0.1.0"
@@ -1869,6 +1904,15 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
[[package]]
name = "memoffset"
version = "0.9.1"
@@ -1956,6 +2000,20 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
[[package]]
name = "nix"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4"
dependencies = [
"autocfg",
"bitflags 1.3.2",
"cfg-if",
"libc",
"memoffset 0.6.5",
"pin-utils",
]
[[package]]
name = "num-conv"
version = "0.2.1"
@@ -2322,6 +2380,12 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.33"
@@ -2367,6 +2431,27 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "portable-pty"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "806ee80c2a03dbe1a9fb9534f8d19e4c0546b790cde8fd1fea9d6390644cb0be"
dependencies = [
"anyhow",
"bitflags 1.3.2",
"downcast-rs",
"filedescriptor",
"lazy_static",
"libc",
"log",
"nix",
"serial",
"shared_library",
"shell-words",
"winapi",
"winreg 0.10.1",
]
[[package]]
name = "potential_utf"
version = "0.1.5"
@@ -2968,6 +3053,48 @@ dependencies = [
"syn 2.0.117",
]
[[package]]
name = "serial"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1237a96570fc377c13baa1b88c7589ab66edced652e43ffb17088f003db3e86"
dependencies = [
"serial-core",
"serial-unix",
"serial-windows",
]
[[package]]
name = "serial-core"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f46209b345401737ae2125fe5b19a77acce90cd53e1658cda928e4fe9a64581"
dependencies = [
"libc",
]
[[package]]
name = "serial-unix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f03fbca4c9d866e24a459cbca71283f545a37f8e3e002ad8c70593871453cab7"
dependencies = [
"ioctl-rs",
"libc",
"serial-core",
"termios",
]
[[package]]
name = "serial-windows"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15c6d3b776267a75d31bbdfd5d36c0ca051251caafc285827052bc53bcdc8162"
dependencies = [
"libc",
"serial-core",
]
[[package]]
name = "serialize-to-javascript"
version = "0.1.2"
@@ -3010,6 +3137,22 @@ dependencies = [
"digest",
]
[[package]]
name = "shared_library"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
dependencies = [
"lazy_static",
"libc",
]
[[package]]
name = "shell-words"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
[[package]]
name = "shlex"
version = "1.3.0"
@@ -3530,6 +3673,15 @@ dependencies = [
"utf-8",
]
[[package]]
name = "termios"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5d9cf598a6d7ce700a4e6a9199da127e6819a61e64b68609683cc9a01b5683a"
dependencies = [
"libc",
]
[[package]]
name = "thiserror"
version = "1.0.69"
@@ -4653,6 +4805,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi",
]
[[package]]
name = "winreg"
version = "0.55.0"

View File

@@ -23,3 +23,6 @@ serde = { version = "1.0", features = ["derive"] }
log = "0.4"
tauri = { version = "2.11.1" }
tauri-plugin-log = "2"
portable-pty = "0.8"
uuid = { version = "1", features = ["v4"] }
base64 = "0.22"

View File

@@ -1,16 +1,27 @@
mod pty;
use pty::{pty_kill, pty_resize, pty_spawn, pty_write, PtyState};
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
tauri_plugin_log::Builder::default()
.level(log::LevelFilter::Info)
.build(),
)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
tauri::Builder::default()
.manage(PtyState::default())
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
tauri_plugin_log::Builder::default()
.level(log::LevelFilter::Info)
.build(),
)?;
}
Ok(())
})
.invoke_handler(tauri::generate_handler![
pty_spawn,
pty_write,
pty_resize,
pty_kill,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

164
src-tauri/src/pty.rs Normal file
View File

@@ -0,0 +1,164 @@
use base64::{engine::general_purpose::STANDARD as B64, Engine as _};
use portable_pty::{native_pty_system, CommandBuilder, MasterPty, PtySize};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::io::{Read, Write};
use std::sync::Mutex;
use tauri::{AppHandle, Emitter, State};
use uuid::Uuid;
pub struct PtyHandle {
master: Box<dyn MasterPty + Send>,
writer: Box<dyn Write + Send>,
}
#[derive(Default)]
pub struct PtyState {
handles: Mutex<HashMap<String, PtyHandle>>,
}
#[derive(Deserialize)]
pub struct SpawnOpts {
pub cols: u16,
pub rows: u16,
pub shell: Option<String>,
pub cwd: Option<String>,
}
#[derive(Serialize, Clone)]
struct DataPayload {
id: String,
data: String,
}
#[derive(Serialize, Clone)]
struct ExitPayload {
id: String,
status: Option<i32>,
}
#[tauri::command]
pub async fn pty_spawn(
app: AppHandle,
state: State<'_, PtyState>,
opts: SpawnOpts,
) -> Result<String, String> {
let id = Uuid::new_v4().to_string();
let pty_system = native_pty_system();
let pair = pty_system
.openpty(PtySize {
rows: opts.rows.max(1),
cols: opts.cols.max(1),
pixel_width: 0,
pixel_height: 0,
})
.map_err(|e| e.to_string())?;
let shell = opts
.shell
.or_else(|| std::env::var("SHELL").ok())
.unwrap_or_else(|| "/bin/bash".into());
let mut cmd = CommandBuilder::new(&shell);
if let Some(cwd) = opts.cwd {
cmd.cwd(cwd);
} else if let Ok(home) = std::env::var("HOME") {
cmd.cwd(home);
}
cmd.env("TERM", "xterm-256color");
cmd.env("COLORTERM", "truecolor");
let mut child = pair
.slave
.spawn_command(cmd)
.map_err(|e| e.to_string())?;
drop(pair.slave);
let reader = pair
.master
.try_clone_reader()
.map_err(|e| e.to_string())?;
let writer = pair
.master
.take_writer()
.map_err(|e| e.to_string())?;
let app_for_thread = app.clone();
let id_for_thread = id.clone();
std::thread::spawn(move || {
let mut reader = reader;
let mut buf = vec![0u8; 4096];
loop {
match reader.read(&mut buf) {
Ok(0) => break,
Ok(n) => {
let payload = DataPayload {
id: id_for_thread.clone(),
data: B64.encode(&buf[..n]),
};
let _ = app_for_thread.emit("pty:data", payload);
}
Err(_) => break,
}
}
let status = child.wait().ok().map(|s| s.exit_code() as i32);
let _ = app_for_thread.emit(
"pty:exit",
ExitPayload {
id: id_for_thread,
status,
},
);
});
state
.handles
.lock()
.unwrap()
.insert(id.clone(), PtyHandle { master: pair.master, writer });
Ok(id)
}
#[tauri::command]
pub fn pty_write(
state: State<'_, PtyState>,
id: String,
data: String,
) -> Result<(), String> {
let bytes = B64.decode(&data).map_err(|e| e.to_string())?;
let mut handles = state.handles.lock().unwrap();
let handle = handles.get_mut(&id).ok_or("pty not found")?;
handle.writer.write_all(&bytes).map_err(|e| e.to_string())?;
handle.writer.flush().map_err(|e| e.to_string())?;
Ok(())
}
#[tauri::command]
pub fn pty_resize(
state: State<'_, PtyState>,
id: String,
cols: u16,
rows: u16,
) -> Result<(), String> {
let handles = state.handles.lock().unwrap();
let handle = handles.get(&id).ok_or("pty not found")?;
handle
.master
.resize(PtySize {
cols: cols.max(1),
rows: rows.max(1),
pixel_width: 0,
pixel_height: 0,
})
.map_err(|e| e.to_string())?;
Ok(())
}
#[tauri::command]
pub fn pty_kill(state: State<'_, PtyState>, id: String) -> Result<(), String> {
// Dropping the handle closes the master fd; child receives SIGHUP and exits.
state.handles.lock().unwrap().remove(&id);
Ok(())
}