getting towards terminal integration
This commit is contained in:
parent
4c00a633af
commit
24710414bd
10 changed files with 417 additions and 1 deletions
|
@ -17,6 +17,7 @@ tauri-build = { version = "2.0.3", features = [] }
|
|||
|
||||
[dependencies]
|
||||
wellen.workspace = true
|
||||
alacritty_terminal = { git = "https://github.com/alacritty/alacritty", rev = "cacdb5bb3b72bad2c729227537979d95af75978f" }
|
||||
shared = { path = "../shared", features = ["backend"] }
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
|
|
@ -8,6 +8,7 @@ use tauri_plugin_dialog::DialogExt;
|
|||
use tokio::time::sleep;
|
||||
use wasmtime::AsContextMut;
|
||||
use wellen::simple::Waveform;
|
||||
use tauri::Emitter;
|
||||
|
||||
type Filename = String;
|
||||
type JavascriptCode = String;
|
||||
|
@ -30,6 +31,7 @@ pub static WAVEFORM: Lazy<StdRwLock<Arc<RwLock<Option<Waveform>>>>> = Lazy::new(
|
|||
#[derive(Default)]
|
||||
struct Store {
|
||||
waveform: Arc<RwLock<Option<Waveform>>>,
|
||||
val : Arc<RwLock<bool>>,
|
||||
}
|
||||
|
||||
#[tauri::command(rename_all = "snake_case")]
|
||||
|
@ -288,6 +290,19 @@ pub fn run() {
|
|||
])
|
||||
.setup(|app| {
|
||||
*APP_HANDLE.write().unwrap() = Some(app.handle().to_owned());
|
||||
println!("Setting up yay!");
|
||||
|
||||
std::thread::spawn(move || {
|
||||
// Simulate emitting a message after a delay
|
||||
std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
|
||||
// Use APP_HANDLE to emit the event
|
||||
if let Some(app_handle) = APP_HANDLE.read().unwrap().clone() {
|
||||
let payload = serde_json::json!({ "message": "Hello from the backend using APP_HANDLE!" });
|
||||
app_handle.emit("backend-message", payload).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod terminal_size;
|
||||
|
||||
fn main() {
|
||||
app_lib::run();
|
||||
}
|
||||
|
|
55
src-tauri/src/terminal_size.rs
Normal file
55
src-tauri/src/terminal_size.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use alacritty_terminal::event::{WindowSize};
|
||||
use alacritty_terminal::grid::{Dimensions};
|
||||
use alacritty_terminal::index::{Column, Line};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TerminalSize {
|
||||
pub cell_width: u16,
|
||||
pub cell_height: u16,
|
||||
pub num_cols: u16,
|
||||
pub num_lines: u16,
|
||||
}
|
||||
|
||||
impl TerminalSize {
|
||||
pub fn new(rows : u16, cols : u16) -> Self {
|
||||
Self {
|
||||
cell_width: 1,
|
||||
cell_height: 1,
|
||||
num_cols: cols,
|
||||
num_lines: rows,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dimensions for TerminalSize {
|
||||
fn total_lines(&self) -> usize {
|
||||
self.screen_lines()
|
||||
}
|
||||
|
||||
fn screen_lines(&self) -> usize {
|
||||
self.num_lines as usize
|
||||
}
|
||||
|
||||
fn columns(&self) -> usize {
|
||||
self.num_cols as usize
|
||||
}
|
||||
|
||||
fn last_column(&self) -> Column {
|
||||
Column(self.num_cols as usize - 1)
|
||||
}
|
||||
|
||||
fn bottommost_line(&self) -> Line {
|
||||
Line(self.num_lines as i32 - 1)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TerminalSize> for WindowSize {
|
||||
fn from(size: TerminalSize) -> Self {
|
||||
Self {
|
||||
num_lines: size.num_lines,
|
||||
num_cols: size.num_cols,
|
||||
cell_width: size.cell_width,
|
||||
cell_height: size.cell_height,
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue