Compare commits
13 commits
diagram_pl
...
main
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6b6af9e826 | ||
|
b97f105408 | ||
|
e4ac219bf9 | ||
|
fbe0a4f554 | ||
|
4fd4b6eb17 | ||
|
e08c673e86 | ||
|
f992a24719 | ||
|
24710414bd | ||
![]() |
4c00a633af | ||
![]() |
6500531270 | ||
![]() |
fdaacaa6f3 | ||
![]() |
ac484fdea8 | ||
![]() |
01a9501f86 |
1856
Cargo.lock
generated
1856
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -165,7 +165,7 @@ description = "Install Tauri CLI (tauri) locally"
|
||||||
command = "cargo"
|
command = "cargo"
|
||||||
args = [
|
args = [
|
||||||
"install",
|
"install",
|
||||||
"tauri-cli@=2.0.0-beta.17",
|
"tauri-cli@=2.1.0",
|
||||||
"--locked",
|
"--locked",
|
||||||
"--root",
|
"--root",
|
||||||
"tauri",
|
"tauri",
|
||||||
|
|
10
README.md
10
README.md
|
@ -69,6 +69,16 @@
|
||||||
<img width="800" src="docs/video_diagrams.gif" alt="Fastwave - Diagrams" />
|
<img width="800" src="docs/video_diagrams.gif" alt="Fastwave - Diagrams" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p align="center">Diagram Connector Demo</p>
|
||||||
|
<p align="center">
|
||||||
|
<img width="800" src="docs/video_diagram_connector.gif" alt="Fastwave - Diagram Connector demo" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">Diagram Connector Code snippet</p>
|
||||||
|
<p align="center">
|
||||||
|
<img width="500" src="docs/screenshot_diagram_connector_rs.png" alt="Fastwave - Diagram Connector Code snippet" />
|
||||||
|
</p>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Installation (desktop version):
|
### Installation (desktop version):
|
||||||
|
|
BIN
docs/screenshot_diagram_connector_rs.png
Normal file
BIN
docs/screenshot_diagram_connector_rs.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 170 KiB |
BIN
docs/video_diagram_connector.gif
Normal file
BIN
docs/video_diagram_connector.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 MiB |
BIN
docs/video_konata.gif
Normal file
BIN
docs/video_konata.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 MiB |
|
@ -14,6 +14,7 @@ wasm-bindgen-test = "0.3.19"
|
||||||
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(FASTWAVE_PLATFORM)'] }
|
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(FASTWAVE_PLATFORM)'] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
unicode-segmentation = "1.10"
|
||||||
zoon.workspace = true
|
zoon.workspace = true
|
||||||
wellen.workspace = true
|
wellen.workspace = true
|
||||||
shared = { path = "../shared", features = ["frontend"] }
|
shared = { path = "../shared", features = ["frontend"] }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{platform, theme::*, Filename, Layout, Mode};
|
use crate::{platform, theme::*, Filename, Layout, Mode};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use zoon::*;
|
use zoon::*;
|
||||||
|
use crate::term::TERM_OPEN;
|
||||||
|
|
||||||
pub struct HeaderPanel {
|
pub struct HeaderPanel {
|
||||||
hierarchy: Mutable<Option<Arc<wellen::Hierarchy>>>,
|
hierarchy: Mutable<Option<Arc<wellen::Hierarchy>>>,
|
||||||
|
@ -36,7 +37,9 @@ impl HeaderPanel {
|
||||||
.s(Gap::both(15))
|
.s(Gap::both(15))
|
||||||
.item(self.load_button())
|
.item(self.load_button())
|
||||||
.item(self.layout_switcher())
|
.item(self.layout_switcher())
|
||||||
.item(self.mode_switcher()),
|
.item(self.mode_switcher())
|
||||||
|
.item(self.open_terminal())
|
||||||
|
.item(self.open_konata_file()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,4 +196,44 @@ impl HeaderPanel {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn open_konata_file(&self) -> impl Element {
|
||||||
|
let (hovered, hovered_signal) = Mutable::new_and_signal(false);
|
||||||
|
Button::new()
|
||||||
|
.s(Padding::new().x(20).y(10))
|
||||||
|
.s(Background::new().color_signal(
|
||||||
|
hovered_signal.map_bool(|| COLOR_MEDIUM_SLATE_BLUE, || COLOR_SLATE_BLUE),
|
||||||
|
))
|
||||||
|
.s(Align::new().left())
|
||||||
|
.s(RoundedCorners::all(15))
|
||||||
|
.label(
|
||||||
|
El::new()
|
||||||
|
.s(Font::new().no_wrap())
|
||||||
|
.child("Open Konata file.."),
|
||||||
|
)
|
||||||
|
.on_hovered_change(move |is_hovered| hovered.set_neq(is_hovered))
|
||||||
|
.on_press(move || Task::start(platform::open_konata_file()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_terminal(&self) -> impl Element {
|
||||||
|
let (hovered, hovered_signal) = Mutable::new_and_signal(false);
|
||||||
|
Button::new()
|
||||||
|
.s(Padding::new().x(20).y(10))
|
||||||
|
.s(Background::new().color_signal(
|
||||||
|
hovered_signal.map_bool(|| COLOR_MEDIUM_SLATE_BLUE, || COLOR_SLATE_BLUE),
|
||||||
|
))
|
||||||
|
.s(Align::new().left())
|
||||||
|
.s(RoundedCorners::all(15))
|
||||||
|
.label(
|
||||||
|
El::new()
|
||||||
|
.s(Font::new().no_wrap())
|
||||||
|
.child("Open Terminal"),
|
||||||
|
)
|
||||||
|
.on_hovered_change(move |is_hovered| hovered.set_neq(is_hovered))
|
||||||
|
.on_press(move || {
|
||||||
|
let term_open = TERM_OPEN.get();
|
||||||
|
TERM_OPEN.set(!term_open);
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use shared::DiagramConnectorMessage;
|
use shared::DiagramConnectorMessage;
|
||||||
|
use term::TERM_OPEN;
|
||||||
use std::{mem, sync::Arc};
|
use std::{mem, sync::Arc};
|
||||||
use zoon::*;
|
use zoon::*;
|
||||||
|
|
||||||
|
@ -23,6 +24,9 @@ use command_panel::CommandPanel;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
use theme::*;
|
use theme::*;
|
||||||
|
|
||||||
|
pub mod term;
|
||||||
|
use shared::term::{TerminalDownMsg, TerminalScreen};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default)]
|
#[derive(Clone, Copy, Default)]
|
||||||
enum Layout {
|
enum Layout {
|
||||||
Tree,
|
Tree,
|
||||||
|
@ -98,8 +102,10 @@ fn main() {
|
||||||
.unwrap_throw()
|
.unwrap_throw()
|
||||||
.set_component_text(&component_id, &text),
|
.set_component_text(&component_id, &text),
|
||||||
}
|
}
|
||||||
})
|
}).await;
|
||||||
.await
|
platform::listen_term_update(|down_msg| {
|
||||||
|
term::TERMINAL_STATE.set(down_msg);
|
||||||
|
}).await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,4 +187,20 @@ fn root() -> impl Element {
|
||||||
}
|
}
|
||||||
})))
|
})))
|
||||||
.item(CommandPanel::new())
|
.item(CommandPanel::new())
|
||||||
|
.item_signal(
|
||||||
|
TERM_OPEN.signal_cloned().map(
|
||||||
|
|term_open| {
|
||||||
|
match term_open {
|
||||||
|
true =>
|
||||||
|
El::new()
|
||||||
|
.s(Height::fill().max(400).min(400))
|
||||||
|
.s(Padding::all(5))
|
||||||
|
.child(term::root()),
|
||||||
|
false =>
|
||||||
|
El::new()
|
||||||
|
.child("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ type DiagramConnectorPath = String;
|
||||||
type DiagramConnectorName = String;
|
type DiagramConnectorName = String;
|
||||||
type ComponentId = String;
|
type ComponentId = String;
|
||||||
|
|
||||||
|
use shared::term::{TerminalDownMsg, TerminalScreen};
|
||||||
|
|
||||||
pub async fn show_window() {
|
pub async fn show_window() {
|
||||||
platform::show_window().await
|
platform::show_window().await
|
||||||
}
|
}
|
||||||
|
@ -72,6 +74,10 @@ pub async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||||
platform::unload_signal(signal_ref).await
|
platform::unload_signal(signal_ref).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn send_char(c : String) {
|
||||||
|
platform::send_char(c).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
|
pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
|
||||||
let count = platform::add_decoders(decoder_paths).await;
|
let count = platform::add_decoders(decoder_paths).await;
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
|
@ -112,6 +118,12 @@ pub async fn listen_diagram_connectors_messages(
|
||||||
platform::listen_diagram_connectors_messages(on_message).await;
|
platform::listen_diagram_connectors_messages(on_message).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn listen_term_update(
|
||||||
|
on_message: impl FnMut(TerminalDownMsg) + 'static,
|
||||||
|
) {
|
||||||
|
platform::listen_term_update(on_message).await;
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn notify_diagram_connector_text_change(
|
pub async fn notify_diagram_connector_text_change(
|
||||||
diagram_connector: DiagramConnectorName,
|
diagram_connector: DiagramConnectorName,
|
||||||
component_id: ComponentId,
|
component_id: ComponentId,
|
||||||
|
@ -119,3 +131,7 @@ pub async fn notify_diagram_connector_text_change(
|
||||||
) {
|
) {
|
||||||
platform::notify_diagram_connector_text_change(diagram_connector, component_id, text).await;
|
platform::notify_diagram_connector_text_change(diagram_connector, component_id, text).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn open_konata_file() {
|
||||||
|
platform::open_konata_file().await;
|
||||||
|
}
|
||||||
|
|
|
@ -166,3 +166,8 @@ pub async fn notify_diagram_connector_text_change(
|
||||||
// @TODO error message for user
|
// @TODO error message for user
|
||||||
eprintln!("Diagram connectors notifications are not supported in the browser.");
|
eprintln!("Diagram connectors notifications are not supported in the browser.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn open_konata_file() {
|
||||||
|
// @TODO error message for user
|
||||||
|
eprintln!("Opening Konata files is not supported in the browser.");
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use shared::DiagramConnectorMessage;
|
use shared::DiagramConnectorMessage;
|
||||||
|
use shared::term::{TerminalDownMsg, TerminalScreen};
|
||||||
use zoon::*;
|
use zoon::*;
|
||||||
|
|
||||||
pub(super) async fn show_window() {
|
pub(super) async fn show_window() {
|
||||||
|
@ -57,6 +58,12 @@ pub(super) async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||||
.unwrap_throw()
|
.unwrap_throw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) async fn send_char(c : String) {
|
||||||
|
tauri_glue::send_char(c)
|
||||||
|
.await
|
||||||
|
.unwrap_throw()
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) async fn add_decoders(
|
pub(super) async fn add_decoders(
|
||||||
decoder_paths: Vec<super::DecoderPath>,
|
decoder_paths: Vec<super::DecoderPath>,
|
||||||
) -> super::AddedDecodersCount {
|
) -> super::AddedDecodersCount {
|
||||||
|
@ -97,6 +104,14 @@ pub(super) async fn listen_diagram_connectors_messages(
|
||||||
tauri_glue::listen_diagram_connectors_messages(Closure::new(on_message).into_js_value()).await
|
tauri_glue::listen_diagram_connectors_messages(Closure::new(on_message).into_js_value()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) async fn listen_term_update(
|
||||||
|
mut on_message: impl FnMut(TerminalDownMsg) + 'static,
|
||||||
|
) {
|
||||||
|
let on_message =
|
||||||
|
move |message: JsValue| on_message(serde_wasm_bindgen::from_value(message).unwrap_throw());
|
||||||
|
tauri_glue::listen_term_update(Closure::new(on_message).into_js_value()).await
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) async fn notify_diagram_connector_text_change(
|
pub(super) async fn notify_diagram_connector_text_change(
|
||||||
diagram_connector: super::DiagramConnectorName,
|
diagram_connector: super::DiagramConnectorName,
|
||||||
component_id: super::ComponentId,
|
component_id: super::ComponentId,
|
||||||
|
@ -107,6 +122,10 @@ pub(super) async fn notify_diagram_connector_text_change(
|
||||||
.unwrap_throw();
|
.unwrap_throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) async fn open_konata_file() {
|
||||||
|
tauri_glue::open_konata_file().await;
|
||||||
|
}
|
||||||
|
|
||||||
mod tauri_glue {
|
mod tauri_glue {
|
||||||
use zoon::*;
|
use zoon::*;
|
||||||
|
|
||||||
|
@ -138,6 +157,9 @@ mod tauri_glue {
|
||||||
#[wasm_bindgen(catch)]
|
#[wasm_bindgen(catch)]
|
||||||
pub async fn unload_signal(signal_ref_index: usize) -> Result<(), JsValue>;
|
pub async fn unload_signal(signal_ref_index: usize) -> Result<(), JsValue>;
|
||||||
|
|
||||||
|
#[wasm_bindgen(catch)]
|
||||||
|
pub async fn send_char(c : String) -> Result<(), JsValue>;
|
||||||
|
|
||||||
#[wasm_bindgen(catch)]
|
#[wasm_bindgen(catch)]
|
||||||
pub async fn add_decoders(
|
pub async fn add_decoders(
|
||||||
decoder_paths: Vec<super::super::DecoderPath>,
|
decoder_paths: Vec<super::super::DecoderPath>,
|
||||||
|
@ -156,11 +178,15 @@ mod tauri_glue {
|
||||||
|
|
||||||
pub async fn listen_diagram_connectors_messages(on_event: JsValue);
|
pub async fn listen_diagram_connectors_messages(on_event: JsValue);
|
||||||
|
|
||||||
|
pub async fn listen_term_update(on_event: JsValue);
|
||||||
|
|
||||||
#[wasm_bindgen(catch)]
|
#[wasm_bindgen(catch)]
|
||||||
pub async fn notify_diagram_connector_text_change(
|
pub async fn notify_diagram_connector_text_change(
|
||||||
diagram_connector: super::super::DiagramConnectorName,
|
diagram_connector: super::super::DiagramConnectorName,
|
||||||
component_id: super::super::ComponentId,
|
component_id: super::super::ComponentId,
|
||||||
text: String,
|
text: String,
|
||||||
) -> Result<(), JsValue>;
|
) -> Result<(), JsValue>;
|
||||||
|
|
||||||
|
pub async fn open_konata_file();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
142
frontend/src/term.rs
Normal file
142
frontend/src/term.rs
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
use std::ops::Index;
|
||||||
|
|
||||||
|
use chrono::format;
|
||||||
|
use zoon::*;
|
||||||
|
use zoon::{println, eprintln, *};
|
||||||
|
use shared::term::{TerminalDownMsg, TerminalScreen, TerminalUpMsg};
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
});
|
||||||
|
|
||||||
|
pub fn root() -> impl Element {
|
||||||
|
let terminal =
|
||||||
|
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"),
|
||||||
|
FontFamily::new("monospace")
|
||||||
|
]))
|
||||||
|
.update_raw_el(|raw_el| {
|
||||||
|
raw_el.global_event_handler(|event: events::KeyDown| {
|
||||||
|
send_char(
|
||||||
|
(&event).key().as_str(),
|
||||||
|
(&event).ctrl_key(),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.child_signal(TERMINAL_STATE.signal_cloned().map(
|
||||||
|
|down_msg| {
|
||||||
|
match down_msg {
|
||||||
|
TerminalDownMsg::FullTermUpdate(term) => {
|
||||||
|
make_grid_with_newlines(&term)
|
||||||
|
},
|
||||||
|
TerminalDownMsg::TermNotStarted => {
|
||||||
|
"Term not yet started!".to_string()
|
||||||
|
},
|
||||||
|
TerminalDownMsg::BackendTermStartFailure(msg) => {
|
||||||
|
format!("Error: BackendTermStartFailure: {}", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
let root = Column::new()
|
||||||
|
.s(Width::fill())
|
||||||
|
.s(Height::fill())
|
||||||
|
.s(Align::new().top())
|
||||||
|
.item(terminal);
|
||||||
|
root
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_char(
|
||||||
|
s : &str,
|
||||||
|
has_control : bool,
|
||||||
|
) {
|
||||||
|
match process_str(s, has_control) {
|
||||||
|
Some(c) => {
|
||||||
|
let send_c = c.clone();
|
||||||
|
Task::start(async move {
|
||||||
|
crate::platform::send_char(send_c.to_string()).await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn make_grid_with_newlines(term: &TerminalScreen) -> String {
|
||||||
|
let mut formatted = String::with_capacity(term.content.len() + (term.content.len() / term.cols as usize));
|
||||||
|
|
||||||
|
term.content.chars().enumerate().for_each(|(i, c)| {
|
||||||
|
formatted.push(c);
|
||||||
|
if (i + 1) as u16 % term.cols == 0 {
|
||||||
|
formatted.push('\n');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
formatted
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn process_str(s: &str, has_ctrl: bool) -> Option<char> {
|
||||||
|
match s {
|
||||||
|
"Enter" => {return Some('\n');}
|
||||||
|
"Escape" => {return Some('\x1B');}
|
||||||
|
"Backspace" => {return Some('\x08');}
|
||||||
|
"ArrowUp" => {return Some('\x10');}
|
||||||
|
"ArrowDown" => {return Some('\x0E');}
|
||||||
|
"ArrowLeft" => {return Some('\x02');}
|
||||||
|
"ArrowRight" => {return Some('\x06');}
|
||||||
|
"Control" => {return None;}
|
||||||
|
"Shift" => {return None;}
|
||||||
|
"Meta" => {return None;}
|
||||||
|
"Alt" => {return None;}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut graphemes = s.graphemes(true);
|
||||||
|
let first = graphemes.next();
|
||||||
|
|
||||||
|
if let Some(g) = first {
|
||||||
|
if g.len() == 1 {
|
||||||
|
if let Some(c) = g.chars().next() {
|
||||||
|
let c = process_for_ctrl_char(c, has_ctrl);
|
||||||
|
return Some(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to process control characters
|
||||||
|
|
||||||
|
fn is_lowercase_alpha(c: char) -> bool {
|
||||||
|
char_is_between_inclusive(c, 'a', 'z')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process_for_ctrl_char(c: char, has_ctrl: bool) -> char {
|
||||||
|
if has_ctrl {
|
||||||
|
(c as u8 & 0x1F) as char
|
||||||
|
} else {
|
||||||
|
c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn char_is_between_inclusive(c : char, lo_char : char, hi_char : char) -> bool {
|
||||||
|
c >= lo_char && c <= hi_char
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -59,6 +59,10 @@ export async function unload_signal(signal_ref_index: number): Promise<void> {
|
||||||
return await invoke("unload_signal", { signal_ref_index });
|
return await invoke("unload_signal", { signal_ref_index });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function send_char(c : string): Promise<void> {
|
||||||
|
return await invoke("send_char", { c });
|
||||||
|
}
|
||||||
|
|
||||||
export async function add_decoders(decoder_paths: Array<DecoderPath>): Promise<AddedDecodersCount> {
|
export async function add_decoders(decoder_paths: Array<DecoderPath>): Promise<AddedDecodersCount> {
|
||||||
return await invoke("add_decoders", { decoder_paths });
|
return await invoke("add_decoders", { decoder_paths });
|
||||||
}
|
}
|
||||||
|
@ -79,6 +83,14 @@ export async function listen_diagram_connectors_messages(on_message: (message: a
|
||||||
return await listen("diagram_connector_message", (message) => on_message(message.payload));
|
return await listen("diagram_connector_message", (message) => on_message(message.payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function listen_term_update(on_message: (message: any) => void) {
|
||||||
|
return await listen("term_content", (message) => on_message(message.payload));
|
||||||
|
}
|
||||||
|
|
||||||
export async function notify_diagram_connector_text_change(diagram_connector: DiagramConnectorName, component_id: ComponentId, text: string): Promise<void> {
|
export async function notify_diagram_connector_text_change(diagram_connector: DiagramConnectorName, component_id: ComponentId, text: string): Promise<void> {
|
||||||
return await invoke("notify_diagram_connector_text_change", { diagram_connector, component_id, text });
|
return await invoke("notify_diagram_connector_text_change", { diagram_connector, component_id, text });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function open_konata_file() {
|
||||||
|
return await invoke("open_konata_file");
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ mod signal_to_timeline;
|
||||||
pub use signal_to_timeline::signal_to_timeline;
|
pub use signal_to_timeline::signal_to_timeline;
|
||||||
|
|
||||||
pub mod wellen_helpers;
|
pub mod wellen_helpers;
|
||||||
|
pub mod term;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||||
#[serde(crate = "serde")]
|
#[serde(crate = "serde")]
|
||||||
|
|
25
shared/src/term.rs
Normal file
25
shared/src/term.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use moonlight::*;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
#[serde(crate = "serde")]
|
||||||
|
pub enum TerminalUpMsg {
|
||||||
|
RequestFullTermState,
|
||||||
|
RequestIncrementalTermStateUpdate,
|
||||||
|
SendCharacter(char),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
#[serde(crate = "serde")]
|
||||||
|
pub enum TerminalDownMsg {
|
||||||
|
FullTermUpdate(TerminalScreen),
|
||||||
|
BackendTermStartFailure(String),
|
||||||
|
TermNotStarted
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||||
|
#[serde(crate = "serde")]
|
||||||
|
pub struct TerminalScreen {
|
||||||
|
pub cols : u16,
|
||||||
|
pub rows : u16,
|
||||||
|
pub content : String,
|
||||||
|
}
|
|
@ -13,18 +13,21 @@ name = "app_lib"
|
||||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-build = { version = "=2.0.0-beta.17", features = [] }
|
tauri-build = { version = "2.0.3", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wellen.workspace = true
|
wellen.workspace = true
|
||||||
|
alacritty_terminal = { git = "https://github.com/alacritty/alacritty", rev = "cacdb5bb3b72bad2c729227537979d95af75978f" }
|
||||||
shared = { path = "../shared", features = ["backend"] }
|
shared = { path = "../shared", features = ["backend"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "=2.0.0-beta.22", features = ["macos-private-api", "linux-ipc-protocol"] }
|
tauri = { version = "2.1.1", features = ["macos-private-api"] }
|
||||||
tauri-plugin-window-state = "=2.0.0-beta.9"
|
tauri-plugin-window-state = "2.0.2"
|
||||||
tauri-plugin-dialog = "=2.0.0-beta.9"
|
tauri-plugin-dialog = "2.0.4"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
|
reqwest = "0.12.9"
|
||||||
|
tokio = "*"
|
||||||
|
|
||||||
# wasmtime = "22.0.0"
|
# wasmtime = "22.0.0"
|
||||||
# wasmtime-wasi = "22.0.0"
|
# wasmtime-wasi = "22.0.0"
|
||||||
|
|
|
@ -4,14 +4,6 @@
|
||||||
"description": "enables the default permissions",
|
"description": "enables the default permissions",
|
||||||
"windows": ["main"],
|
"windows": ["main"],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"path:default",
|
"core:default"
|
||||||
"event:default",
|
|
||||||
"window:default",
|
|
||||||
"webview:default",
|
|
||||||
"app:default",
|
|
||||||
"resources:default",
|
|
||||||
"image:default",
|
|
||||||
"menu:default",
|
|
||||||
"tray:default"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
2
src-tauri/f.txt
Normal file
2
src-tauri/f.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Hello, I'm typing a file in vim!!
|
||||||
|
|
116
src-tauri/src/aterm.rs
Normal file
116
src-tauri/src/aterm.rs
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
use std::result;
|
||||||
|
use std::sync::{mpsc, Arc};
|
||||||
|
|
||||||
|
use alacritty_terminal::event::{Event, EventListener};
|
||||||
|
use alacritty_terminal::event_loop::{EventLoop, Notifier};
|
||||||
|
use alacritty_terminal::sync::FairMutex;
|
||||||
|
use alacritty_terminal::term::{self, Term};
|
||||||
|
use alacritty_terminal::term::cell::Cell;
|
||||||
|
use alacritty_terminal::{tty, Grid};
|
||||||
|
use tauri::Emitter;
|
||||||
|
use shared::term::{TerminalDownMsg, TerminalScreen};
|
||||||
|
|
||||||
|
use crate::terminal_size;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct EventProxy(mpsc::Sender<Event>);
|
||||||
|
impl EventListener for EventProxy {
|
||||||
|
fn send_event(&self, event: Event) {
|
||||||
|
let _ = self.0.send(event.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ATerm {
|
||||||
|
pub term: Arc<FairMutex<Term<EventProxy>>>,
|
||||||
|
|
||||||
|
pub rows : u16,
|
||||||
|
pub cols : u16,
|
||||||
|
|
||||||
|
/// Use tx to write things to terminal instance from outside world
|
||||||
|
pub tx: Notifier,
|
||||||
|
|
||||||
|
/// Use rx to read things from terminal instance.
|
||||||
|
/// Rx only has data when terminal state has changed,
|
||||||
|
/// otherwise, `std::sync::mpsc::recv` will block and sleep
|
||||||
|
/// until there is data.
|
||||||
|
pub rx: mpsc::Receiver<(u64, Event)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ATerm {
|
||||||
|
pub fn new() -> result::Result<ATerm, std::io::Error> {
|
||||||
|
let (rows, cols) = (21, 85);
|
||||||
|
let id = 1;
|
||||||
|
let pty_config = tty::Options {
|
||||||
|
shell: Some(tty::Shell::new("/bin/bash".to_string(), vec![])),
|
||||||
|
..tty::Options::default()
|
||||||
|
};
|
||||||
|
let config = term::Config::default();
|
||||||
|
let terminal_size = terminal_size::TerminalSize::new(rows, cols);
|
||||||
|
let pty = tty::new(&pty_config, terminal_size.into(), id)?;
|
||||||
|
let (event_sender, event_receiver) = mpsc::channel();
|
||||||
|
let event_proxy = EventProxy(event_sender);
|
||||||
|
let term = Term::new::<terminal_size::TerminalSize>(
|
||||||
|
config,
|
||||||
|
&terminal_size.into(),
|
||||||
|
event_proxy.clone(),
|
||||||
|
);
|
||||||
|
let term = Arc::new(FairMutex::new(term));
|
||||||
|
let pty_event_loop = EventLoop::new(term.clone(), event_proxy, pty, false, false)?;
|
||||||
|
let notifier = Notifier(pty_event_loop.channel());
|
||||||
|
let (pty_proxy_sender, pty_proxy_receiver) = std::sync::mpsc::channel();
|
||||||
|
// Start pty event loop
|
||||||
|
pty_event_loop.spawn();
|
||||||
|
std::thread::Builder::new()
|
||||||
|
.name(format!("pty_event_subscription_{}", id))
|
||||||
|
.spawn(move || loop {
|
||||||
|
if let Ok(event) = event_receiver.recv() {
|
||||||
|
if let Event::Exit = event {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if let Some(app_handle) = crate::APP_HANDLE.read().unwrap().clone() {
|
||||||
|
let term = crate::TERM.lock().unwrap();
|
||||||
|
let content = 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
Ok(ATerm {
|
||||||
|
term,
|
||||||
|
rows,
|
||||||
|
cols,
|
||||||
|
tx: notifier,
|
||||||
|
rx: pty_proxy_receiver,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
return term_grid_to_string(&grid, rows, cols);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn term_grid_to_string(grid: &Grid<Cell>, rows: u16, cols: u16) -> String {
|
||||||
|
let mut term_content = String::with_capacity((rows*cols) as usize);
|
||||||
|
|
||||||
|
// Populate string from grid
|
||||||
|
for indexed in grid.display_iter() {
|
||||||
|
let x = indexed.point.column.0 as usize;
|
||||||
|
let y = indexed.point.line.0 as usize;
|
||||||
|
if y < rows as usize && x < cols as usize {
|
||||||
|
term_content.push(indexed.c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return term_content;
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ use once_cell::sync::Lazy;
|
||||||
use shared::{DiagramConnectorMessage, VarFormat};
|
use shared::{DiagramConnectorMessage, VarFormat};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tauri::async_runtime::{Mutex, RwLock};
|
use tauri::async_runtime::{Mutex, RwLock};
|
||||||
use tauri::Manager;
|
use tauri::Emitter;
|
||||||
use wasmtime::component::{Component as WasmtimeComponent, *};
|
use wasmtime::component::{Component as WasmtimeComponent, *};
|
||||||
use wasmtime::{AsContextMut, Engine, Store};
|
use wasmtime::{AsContextMut, Engine, Store};
|
||||||
use wasmtime_wasi::{WasiCtx, WasiView};
|
use wasmtime_wasi::{WasiCtx, WasiView};
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::process::Command;
|
||||||
use std::sync::{Arc, RwLock as StdRwLock};
|
use std::sync::{Arc, RwLock as StdRwLock};
|
||||||
|
use std::time::Duration;
|
||||||
use tauri::{async_runtime::RwLock, AppHandle};
|
use tauri::{async_runtime::RwLock, AppHandle};
|
||||||
use tauri_plugin_dialog::DialogExt;
|
use tauri_plugin_dialog::DialogExt;
|
||||||
|
use tokio::time::sleep;
|
||||||
use wasmtime::AsContextMut;
|
use wasmtime::AsContextMut;
|
||||||
use wellen::simple::Waveform;
|
use wellen::simple::Waveform;
|
||||||
|
use tauri::Emitter;
|
||||||
|
|
||||||
type Filename = String;
|
type Filename = String;
|
||||||
type JavascriptCode = String;
|
type JavascriptCode = String;
|
||||||
|
@ -18,15 +22,25 @@ type RemovedDiagramConnectorsCount = usize;
|
||||||
type DiagramConnectorPath = String;
|
type DiagramConnectorPath = String;
|
||||||
type DiagramConnectorName = String;
|
type DiagramConnectorName = String;
|
||||||
type ComponentId = String;
|
type ComponentId = String;
|
||||||
|
use alacritty_terminal::event::Notify;
|
||||||
|
use shared::term::{TerminalDownMsg, TerminalScreen};
|
||||||
|
|
||||||
mod component_manager;
|
mod component_manager;
|
||||||
|
mod aterm;
|
||||||
|
mod terminal_size;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
pub static APP_HANDLE: Lazy<Arc<StdRwLock<Option<AppHandle>>>> = Lazy::new(<_>::default);
|
pub static APP_HANDLE: Lazy<Arc<StdRwLock<Option<AppHandle>>>> = Lazy::new(<_>::default);
|
||||||
pub static WAVEFORM: Lazy<StdRwLock<Arc<RwLock<Option<Waveform>>>>> = Lazy::new(<_>::default);
|
pub static WAVEFORM: Lazy<StdRwLock<Arc<RwLock<Option<Waveform>>>>> = Lazy::new(<_>::default);
|
||||||
|
|
||||||
|
static TERM: Lazy<Mutex<aterm::ATerm>> = Lazy::new(|| {
|
||||||
|
Mutex::new(aterm::ATerm::new().expect("Failed to initialize ATerm"))
|
||||||
|
});
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Store {
|
struct Store {
|
||||||
waveform: Arc<RwLock<Option<Waveform>>>,
|
waveform: Arc<RwLock<Option<Waveform>>>,
|
||||||
|
val : Arc<RwLock<bool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command(rename_all = "snake_case")]
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
@ -39,27 +53,30 @@ async fn pick_and_load_waveform(
|
||||||
store: tauri::State<'_, Store>,
|
store: tauri::State<'_, Store>,
|
||||||
app: tauri::AppHandle,
|
app: tauri::AppHandle,
|
||||||
) -> Result<Option<Filename>, ()> {
|
) -> Result<Option<Filename>, ()> {
|
||||||
let Some(file_response) = app.dialog().file().blocking_pick_file() else {
|
let Some(file_path) = app.dialog().file().blocking_pick_file() else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
let file_path = file_response.path.as_os_str().to_str().unwrap();
|
let file_buf = file_path.into_path().unwrap();
|
||||||
|
let file_str = file_buf.as_os_str().to_str().unwrap();
|
||||||
// @TODO `read` should accept `Path` instead of `&str`
|
// @TODO `read` should accept `Path` instead of `&str`
|
||||||
let waveform = wellen::simple::read(file_path);
|
let waveform = wellen::simple::read(file_str);
|
||||||
let Ok(waveform) = waveform else {
|
let Ok(waveform) = waveform else {
|
||||||
panic!("Waveform file reading failed")
|
panic!("Waveform file reading failed")
|
||||||
};
|
};
|
||||||
*store.waveform.write().await = Some(waveform);
|
*store.waveform.write().await = Some(waveform);
|
||||||
*WAVEFORM.write().unwrap() = Arc::clone(&store.waveform);
|
*WAVEFORM.write().unwrap() = Arc::clone(&store.waveform);
|
||||||
Ok(Some(file_response.name.unwrap()))
|
Ok(Some(
|
||||||
|
file_buf.file_name().unwrap().to_string_lossy().to_string(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command(rename_all = "snake_case")]
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
async fn load_file_with_selected_vars(app: tauri::AppHandle) -> Result<Option<JavascriptCode>, ()> {
|
async fn load_file_with_selected_vars(app: tauri::AppHandle) -> Result<Option<JavascriptCode>, ()> {
|
||||||
let Some(file_response) = app.dialog().file().blocking_pick_file() else {
|
let Some(file_path) = app.dialog().file().blocking_pick_file() else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
// @TODO Tokio's `fs` or a Tauri `fs`?
|
// @TODO Tokio's `fs` or a Tauri `fs`?
|
||||||
let Ok(javascript_code) = fs::read_to_string(file_response.path) else {
|
let Ok(javascript_code) = fs::read_to_string(file_path.into_path().unwrap()) else {
|
||||||
panic!("Selected vars file reading failed")
|
panic!("Selected vars file reading failed")
|
||||||
};
|
};
|
||||||
Ok(Some(javascript_code))
|
Ok(Some(javascript_code))
|
||||||
|
@ -138,6 +155,17 @@ async fn unload_signal(signal_ref_index: usize, store: tauri::State<'_, Store>)
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
async fn send_char(c : String) -> Result<(), ()> {
|
||||||
|
if c.len() == 1 {
|
||||||
|
let term = TERM.lock().unwrap();
|
||||||
|
term.tx.notify(c.into_bytes());
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command(rename_all = "snake_case")]
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> Result<AddedDecodersCount, ()> {
|
async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> Result<AddedDecodersCount, ()> {
|
||||||
Ok(component_manager::decoders::add_decoders(decoder_paths).await)
|
Ok(component_manager::decoders::add_decoders(decoder_paths).await)
|
||||||
|
@ -179,6 +207,82 @@ async fn notify_diagram_connector_text_change(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
async fn open_konata_file(app: tauri::AppHandle) {
|
||||||
|
let Some(file_path) = app.dialog().file().blocking_pick_file() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let file_str = file_path
|
||||||
|
.into_path()
|
||||||
|
.unwrap()
|
||||||
|
.into_os_string()
|
||||||
|
.into_string()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let port = 30000;
|
||||||
|
let base_url = format!("http://localhost:{port}");
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.connect_timeout(Duration::from_secs(1))
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut konata_server_ready = false;
|
||||||
|
|
||||||
|
let is_konata_server_ready = || async {
|
||||||
|
client
|
||||||
|
.get(format!("{base_url}/status"))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.is_ok()
|
||||||
|
};
|
||||||
|
|
||||||
|
if is_konata_server_ready().await {
|
||||||
|
konata_server_ready = true;
|
||||||
|
} else {
|
||||||
|
spawn_konata_app();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut attempts = 1;
|
||||||
|
while !konata_server_ready {
|
||||||
|
attempts += 1;
|
||||||
|
if attempts > 5 {
|
||||||
|
eprintln!("Failed to get Konata server status (5 attempts)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
konata_server_ready = is_konata_server_ready().await;
|
||||||
|
sleep(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
client
|
||||||
|
.post(format!("{base_url}/open-konata-file"))
|
||||||
|
.json(&serde_json::json!({
|
||||||
|
"file_path": file_str
|
||||||
|
}))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.error_for_status()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
fn spawn_konata_app() {
|
||||||
|
Command::new("cscript")
|
||||||
|
.current_dir("../../Konata")
|
||||||
|
.arg("konata.vbs")
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
fn spawn_konata_app() {
|
||||||
|
Command::new("sh")
|
||||||
|
.current_dir("../../Konata")
|
||||||
|
.arg("konata.sh")
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
// https://github.com/tauri-apps/tauri/issues/8462
|
// https://github.com/tauri-apps/tauri/issues/8462
|
||||||
|
@ -197,14 +301,37 @@ pub fn run() {
|
||||||
get_hierarchy,
|
get_hierarchy,
|
||||||
load_signal_and_get_timeline,
|
load_signal_and_get_timeline,
|
||||||
unload_signal,
|
unload_signal,
|
||||||
|
send_char,
|
||||||
add_decoders,
|
add_decoders,
|
||||||
remove_all_decoders,
|
remove_all_decoders,
|
||||||
add_diagram_connectors,
|
add_diagram_connectors,
|
||||||
remove_all_diagram_connectors,
|
remove_all_diagram_connectors,
|
||||||
notify_diagram_connector_text_change,
|
notify_diagram_connector_text_change,
|
||||||
|
open_konata_file,
|
||||||
])
|
])
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
*APP_HANDLE.write().unwrap() = Some(app.handle().to_owned());
|
*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(1));
|
||||||
|
|
||||||
|
//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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
|
mod terminal_size;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
app_lib::run();
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue