term now working

This commit is contained in:
Yehowshua Immanuel 2024-12-24 19:31:46 -05:00
parent 4fd4b6eb17
commit fbe0a4f554
4 changed files with 25 additions and 15 deletions

View file

@ -194,7 +194,8 @@ fn root() -> impl Element {
match term_open {
true =>
El::new()
.s(Height::fill().max(450))
.s(Height::fill().max(400).min(400))
.s(Padding::all(5))
.child(term::root()),
false =>
El::new()

View file

@ -8,6 +8,8 @@ use shared::term::{TerminalDownMsg, TerminalScreen, TerminalUpMsg};
// use tokio::time::timeout;
pub static TERM_OPEN: Lazy<Mutable<bool>> = Lazy::new(|| {false.into()});
pub const TERMINAL_COLOR: Oklch = color!("oklch(20% 0.125 262.26)");
pub static TERMINAL_STATE: Lazy<Mutable<TerminalDownMsg>> =
Lazy::new(|| {
Mutable::new(TerminalDownMsg::TermNotStarted)
@ -19,6 +21,8 @@ pub fn root() -> impl Element {
El::new()
.s(Width::fill())
.s(Height::fill())
.s(Background::new().color(TERMINAL_COLOR))
.s(RoundedCorners::all(7))
.s(Font::new().family([
FontFamily::new("Lucida Console"),
FontFamily::new("Courier"),
@ -66,16 +70,13 @@ fn send_char(
has_control : bool,
) {
match process_str(s, has_control) {
// TODO : fill this out
Some(c) => {
let send_c = c.clone();
Task::start(async move {
println!("Sending char: {}", &c);
crate::platform::send_char(send_c.to_string()).await;
println!("Sent char: {}", &c);
});
}
None => {eprintln!("Not processing: {}", s)}
None => {}
}
}

View file

@ -23,8 +23,8 @@ impl EventListener for EventProxy {
pub struct ATerm {
pub term: Arc<FairMutex<Term<EventProxy>>>,
rows : u16,
cols : u16,
pub rows : u16,
pub cols : u16,
/// Use tx to write things to terminal instance from outside world
pub tx: Notifier,
@ -38,7 +38,7 @@ pub struct ATerm {
impl ATerm {
pub fn new() -> result::Result<ATerm, std::io::Error> {
let (rows, cols) = (21, 90);
let (rows, cols) = (21, 85);
let id = 1;
let pty_config = tty::Options {
shell: Some(tty::Shell::new("/bin/bash".to_string(), vec![])),
@ -93,7 +93,7 @@ impl ATerm {
}
}
fn terminal_instance_to_string(terminal_instance: &ATerm) -> String {
pub fn terminal_instance_to_string(terminal_instance: &ATerm) -> String {
let (rows, cols) = (terminal_instance.rows, terminal_instance.cols);
let term = terminal_instance.term.lock();
let grid = term.grid().clone();

View file

@ -23,6 +23,7 @@ type DiagramConnectorPath = String;
type DiagramConnectorName = String;
type ComponentId = String;
use alacritty_terminal::event::Notify;
use shared::term::{TerminalDownMsg, TerminalScreen};
mod component_manager;
mod aterm;
@ -156,7 +157,6 @@ async fn unload_signal(signal_ref_index: usize, store: tauri::State<'_, Store>)
#[tauri::command(rename_all = "snake_case")]
async fn send_char(c : String) -> Result<(), ()> {
// see if length of c is 1
if c.len() == 1 {
let term = TERM.lock().unwrap();
term.tx.notify(c.into_bytes());
@ -315,12 +315,20 @@ pub fn run() {
std::thread::spawn(move || {
// Simulate emitting a message after a delay
std::thread::sleep(std::time::Duration::from_secs(5));
std::thread::sleep(std::time::Duration::from_secs(1));
// 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();
//tart term and send initial update to backend
if let Some(app_handle) = crate::APP_HANDLE.read().unwrap().clone() {
let term = crate::TERM.lock().unwrap();
let content = crate::aterm::terminal_instance_to_string(&term);
let payload = TerminalScreen {
cols: term.cols,
rows: term.rows,
content: content
};
let payload = TerminalDownMsg::FullTermUpdate(payload);
let payload = serde_json::json!(payload);
app_handle.emit("term_content", payload).unwrap();
}
});