From f992a2471999a5dc16e639b20a8ee9d2fdda9cec Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 24 Dec 2024 18:24:55 -0500 Subject: [PATCH] at least we're now sending a character --- frontend/src/main.rs | 18 ++- frontend/src/platform.rs | 12 ++ frontend/src/platform/tauri.rs | 20 ++++ frontend/src/term.rs | 26 ++--- frontend/typescript/bundles/tauri_glue.js | 2 +- frontend/typescript/tauri_glue/tauri_glue.ts | 23 ++-- shared/src/term.rs | 4 +- src-tauri/src/aterm.rs | 116 +++++++++++++++++++ src-tauri/src/lib.rs | 14 +++ 9 files changed, 203 insertions(+), 32 deletions(-) create mode 100644 src-tauri/src/aterm.rs diff --git a/frontend/src/main.rs b/frontend/src/main.rs index 65a40b5..d1f34d9 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -25,6 +25,7 @@ pub mod theme; use theme::*; pub mod term; +use shared::term::{TerminalDownMsg, TerminalScreen}; #[derive(Clone, Copy, Default)] enum Layout { @@ -101,8 +102,11 @@ fn main() { .unwrap_throw() .set_component_text(&component_id, &text), } - }) - .await + }).await; + platform::listen_term_update(|down_msg| { + term::TERMINAL_STATE.set(down_msg); + }).await; + zoon::println!("Printing on line 106"); }); } @@ -188,11 +192,15 @@ fn root() -> impl Element { TERM_OPEN.signal_cloned().map( |term_open| { match term_open { - true => {El::new().child("Terminal")} - false => {El::new().child("")} + true => + El::new() + .s(Height::fill().max(450)) + .child(term::root()), + false => + El::new() + .child("") } } ) - // El::new() ) } diff --git a/frontend/src/platform.rs b/frontend/src/platform.rs index 8d3a9c4..0d31241 100644 --- a/frontend/src/platform.rs +++ b/frontend/src/platform.rs @@ -29,6 +29,8 @@ type DiagramConnectorPath = String; type DiagramConnectorName = String; type ComponentId = String; +use shared::term::{TerminalDownMsg, TerminalScreen}; + pub async fn show_window() { platform::show_window().await } @@ -72,6 +74,10 @@ pub async fn unload_signal(signal_ref: wellen::SignalRef) { platform::unload_signal(signal_ref).await } +pub async fn send_char() { + platform::send_char().await +} + pub async fn add_decoders(decoder_paths: Vec) -> AddedDecodersCount { let count = platform::add_decoders(decoder_paths).await; if count > 0 { @@ -112,6 +118,12 @@ pub async fn listen_diagram_connectors_messages( 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( diagram_connector: DiagramConnectorName, component_id: ComponentId, diff --git a/frontend/src/platform/tauri.rs b/frontend/src/platform/tauri.rs index 37b4c39..1d9e6c1 100644 --- a/frontend/src/platform/tauri.rs +++ b/frontend/src/platform/tauri.rs @@ -1,4 +1,5 @@ use shared::DiagramConnectorMessage; +use shared::term::{TerminalDownMsg, TerminalScreen}; use zoon::*; pub(super) async fn show_window() { @@ -57,6 +58,12 @@ pub(super) async fn unload_signal(signal_ref: wellen::SignalRef) { .unwrap_throw() } +pub(super) async fn send_char() { + tauri_glue::send_char() + .await + .unwrap_throw() +} + pub(super) async fn add_decoders( decoder_paths: Vec, ) -> 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 } +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( diagram_connector: super::DiagramConnectorName, component_id: super::ComponentId, @@ -142,6 +157,9 @@ mod tauri_glue { #[wasm_bindgen(catch)] pub async fn unload_signal(signal_ref_index: usize) -> Result<(), JsValue>; + #[wasm_bindgen(catch)] + pub async fn send_char() -> Result<(), JsValue>; + #[wasm_bindgen(catch)] pub async fn add_decoders( decoder_paths: Vec, @@ -160,6 +178,8 @@ mod tauri_glue { pub async fn listen_diagram_connectors_messages(on_event: JsValue); + pub async fn listen_term_update(on_event: JsValue); + #[wasm_bindgen(catch)] pub async fn notify_diagram_connector_text_change( diagram_connector: super::super::DiagramConnectorName, diff --git a/frontend/src/term.rs b/frontend/src/term.rs index 9586cbd..0399b29 100644 --- a/frontend/src/term.rs +++ b/frontend/src/term.rs @@ -8,24 +8,11 @@ use shared::term::{TerminalDownMsg, TerminalScreen, TerminalUpMsg}; // use tokio::time::timeout; pub static TERM_OPEN: Lazy> = Lazy::new(|| {false.into()}); -static TERMINAL_STATE: Lazy> = +pub static TERMINAL_STATE: Lazy> = Lazy::new(|| { Mutable::new(TerminalDownMsg::TermNotStarted) }); -// static CONNECTION: Lazy> = Lazy::new(|| { -// Connection::new( -// |down_msg, _| { -// match down_msg { -// DownMsg::TerminalDownMsg(terminal_msg) => { -// TERMINAL_STATE.set(terminal_msg); -// } - -// } -// } -// ) -// }); - pub fn root() -> impl Element { term_request(); let terminal = @@ -39,7 +26,6 @@ pub fn root() -> impl Element { ])) .update_raw_el(|raw_el| { raw_el.global_event_handler(|event: events::KeyDown| { - println!("Pressed key: {}", &event.key()); send_char( (&event).key().as_str(), (&event).ctrl_key(), @@ -82,7 +68,13 @@ fn send_char( match process_str(s, has_control) { // TODO : fill this out Some(c) => { - eprintln!("Sending char: {}", c); + let send_c = c.clone(); + Task::start(async move { + println!("Sending char: {}", &c); + crate::platform::send_char().await; + // crate::platform::unload_signal().await; + println!("Sent char: {}", &c); + }); } None => {eprintln!("Not processing: {}", s)} } @@ -94,7 +86,7 @@ fn make_grid_with_newlines(term : &TerminalScreen) -> String { let mut formatted = String::new(); for (i, c) in term.content.chars().enumerate() { formatted.push(c); - if (i + 1) % term.cols == 0 { + if ((i + 1) as u16) % term.cols == 0 { formatted.push('\n'); } } diff --git a/frontend/typescript/bundles/tauri_glue.js b/frontend/typescript/bundles/tauri_glue.js index de96555..d069557 100644 --- a/frontend/typescript/bundles/tauri_glue.js +++ b/frontend/typescript/bundles/tauri_glue.js @@ -1 +1 @@ -var ae=Object.defineProperty;var q=(n,e)=>{for(var t in e)ae(n,t,{get:e[t],enumerable:!0})};var M={};q(M,{Channel:()=>k,PluginListener:()=>R,Resource:()=>y,addPluginListener:()=>se,convertFileSrc:()=>le,invoke:()=>i,isTauri:()=>oe,transformCallback:()=>T});function c(n,e,t,r){if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?n!==e||!r:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?r:t==="a"?r.call(n):r?r.value:e.get(n)}function _(n,e,t,r,a){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!a)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?n!==e||!a:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?a.call(n,t):a?a.value=t:e.set(n,t),t}var b,A,f,L;function T(n,e=!1){return window.__TAURI_INTERNALS__.transformCallback(n,e)}var k=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,b.set(this,()=>{}),A.set(this,0),f.set(this,{}),this.id=T(({message:e,id:t})=>{if(t===c(this,A,"f")){_(this,A,t+1,"f"),c(this,b,"f").call(this,e);let r=Object.keys(c(this,f,"f"));if(r.length>0){let a=t+1;for(let u of r.sort())if(parseInt(u)===a){let s=c(this,f,"f")[u];delete c(this,f,"f")[u],c(this,b,"f").call(this,s),a+=1}else break;_(this,A,a,"f")}}else c(this,f,"f")[t.toString()]=e})}set onmessage(e){_(this,b,e,"f")}get onmessage(){return c(this,b,"f")}toJSON(){return`__CHANNEL__:${this.id}`}};b=new WeakMap,A=new WeakMap,f=new WeakMap;var R=class{constructor(e,t,r){this.plugin=e,this.event=t,this.channelId=r}async unregister(){return i(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function se(n,e,t){let r=new k;return r.onmessage=t,i(`plugin:${n}|register_listener`,{event:e,handler:r}).then(()=>new R(n,e,r.id))}async function i(n,e={},t){return window.__TAURI_INTERNALS__.invoke(n,e,t)}function le(n,e="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(n,e)}var y=class{get rid(){return c(this,L,"f")}constructor(e){L.set(this,void 0),_(this,L,e,"f")}async close(){return i("plugin:resources|close",{rid:this.rid})}};L=new WeakMap;function oe(){return"isTauri"in window&&!!window.isTauri}var E={};q(E,{TauriEvent:()=>l,emit:()=>x,emitTo:()=>P,listen:()=>p,once:()=>w});var l;(function(n){n.WINDOW_RESIZED="tauri://resize",n.WINDOW_MOVED="tauri://move",n.WINDOW_CLOSE_REQUESTED="tauri://close-requested",n.WINDOW_DESTROYED="tauri://destroyed",n.WINDOW_FOCUS="tauri://focus",n.WINDOW_BLUR="tauri://blur",n.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",n.WINDOW_THEME_CHANGED="tauri://theme-changed",n.WINDOW_CREATED="tauri://window-created",n.WEBVIEW_CREATED="tauri://webview-created",n.DRAG="tauri://drag",n.DROP="tauri://drop",n.DROP_OVER="tauri://drop-over",n.DROP_CANCELLED="tauri://drag-cancelled"})(l||(l={}));async function J(n,e){await i("plugin:event|unlisten",{event:n,eventId:e})}async function p(n,e,t){var r;let a=typeof t?.target=="string"?{kind:"AnyLabel",label:t.target}:(r=t?.target)!==null&&r!==void 0?r:{kind:"Any"};return i("plugin:event|listen",{event:n,target:a,handler:T(e)}).then(u=>async()=>J(n,u))}async function w(n,e,t){return p(n,r=>{e(r),J(n,r.id).catch(()=>{})},t)}async function x(n,e){await i("plugin:event|emit",{event:n,payload:e})}async function P(n,e,t){await i("plugin:event|emit_to",{target:typeof n=="string"?{kind:"AnyLabel",label:n}:n,event:e,payload:t})}var F=class{constructor(e,t){this.type="Logical",this.width=e,this.height=t}},h=class{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new F(this.width/e,this.height/e)}},O=class{constructor(e,t){this.type="Logical",this.x=e,this.y=t}},d=class{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new O(this.x/e,this.y/e)}};var I=class n extends y{constructor(e){super(e)}static async new(e,t,r){return i("plugin:image|new",{rgba:g(e),width:t,height:r}).then(a=>new n(a))}static async fromBytes(e){return i("plugin:image|from_bytes",{bytes:g(e)}).then(t=>new n(t))}static async fromPath(e){return i("plugin:image|from_path",{path:e}).then(t=>new n(t))}async rgba(){return i("plugin:image|rgba",{rid:this.rid}).then(e=>new Uint8Array(e))}async size(){return i("plugin:image|size",{rid:this.rid})}};function g(n){return n==null?null:typeof n=="string"?n:n instanceof Uint8Array?Array.from(n):n instanceof ArrayBuffer?Array.from(new Uint8Array(n)):n instanceof I?n.rid:n}var V;(function(n){n[n.Critical=1]="Critical",n[n.Informational=2]="Informational"})(V||(V={}));var G=class{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},K;(function(n){n.None="none",n.Normal="normal",n.Indeterminate="indeterminate",n.Paused="paused",n.Error="error"})(K||(K={}));function H(){return new m(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}function z(){return window.__TAURI_INTERNALS__.metadata.windows.map(n=>new m(n.label,{skip:!0}))}var U=["tauri://created","tauri://error"],m=class{constructor(e,t={}){var r;this.label=e,this.listeners=Object.create(null),t?.skip||i("plugin:window|create",{options:{...t,parent:typeof t.parent=="string"?t.parent:(r=t.parent)===null||r===void 0?void 0:r.label,label:e}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static getByLabel(e){var t;return(t=z().find(r=>r.label===e))!==null&&t!==void 0?t:null}static getCurrent(){return H()}static getAll(){return z()}static async getFocusedWindow(){for(let e of z())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):p(e,t,{target:{kind:"Window",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):w(e,t,{target:{kind:"Window",label:this.label}})}async emit(e,t){if(U.includes(e)){for(let r of this.listeners[e]||[])r({event:e,id:-1,payload:t});return Promise.resolve()}return x(e,t)}async emitTo(e,t,r){if(U.includes(t)){for(let a of this.listeners[t]||[])a({event:t,id:-1,payload:r});return Promise.resolve()}return P(e,t,r)}_handleTauriEvent(e,t){return U.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async scaleFactor(){return i("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return i("plugin:window|inner_position",{label:this.label}).then(({x:e,y:t})=>new d(e,t))}async outerPosition(){return i("plugin:window|outer_position",{label:this.label}).then(({x:e,y:t})=>new d(e,t))}async innerSize(){return i("plugin:window|inner_size",{label:this.label}).then(({width:e,height:t})=>new h(e,t))}async outerSize(){return i("plugin:window|outer_size",{label:this.label}).then(({width:e,height:t})=>new h(e,t))}async isFullscreen(){return i("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return i("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return i("plugin:window|is_maximized",{label:this.label})}async isFocused(){return i("plugin:window|is_focused",{label:this.label})}async isDecorated(){return i("plugin:window|is_decorated",{label:this.label})}async isResizable(){return i("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return i("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return i("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return i("plugin:window|is_closable",{label:this.label})}async isVisible(){return i("plugin:window|is_visible",{label:this.label})}async title(){return i("plugin:window|title",{label:this.label})}async theme(){return i("plugin:window|theme",{label:this.label})}async center(){return i("plugin:window|center",{label:this.label})}async requestUserAttention(e){let t=null;return e&&(e===V.Critical?t={type:"Critical"}:t={type:"Informational"}),i("plugin:window|request_user_attention",{label:this.label,value:t})}async setResizable(e){return i("plugin:window|set_resizable",{label:this.label,value:e})}async setMaximizable(e){return i("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return i("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return i("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return i("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return i("plugin:window|maximize",{label:this.label})}async unmaximize(){return i("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return i("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return i("plugin:window|minimize",{label:this.label})}async unminimize(){return i("plugin:window|unminimize",{label:this.label})}async show(){return i("plugin:window|show",{label:this.label})}async hide(){return i("plugin:window|hide",{label:this.label})}async close(){return i("plugin:window|close",{label:this.label})}async destroy(){return i("plugin:window|destroy",{label:this.label})}async setDecorations(e){return i("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return i("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return i("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return i("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return i("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return i("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return i("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");let t={};return t[`${e.type}`]={width:e.width,height:e.height},i("plugin:window|set_size",{label:this.label,value:t})}async setMinSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");let t=null;return e&&(t={},t[`${e.type}`]={width:e.width,height:e.height}),i("plugin:window|set_min_size",{label:this.label,value:t})}async setMaxSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");let t=null;return e&&(t={},t[`${e.type}`]={width:e.width,height:e.height}),i("plugin:window|set_max_size",{label:this.label,value:t})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");let t={};return t[`${e.type}`]={x:e.x,y:e.y},i("plugin:window|set_position",{label:this.label,value:t})}async setFullscreen(e){return i("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return i("plugin:window|set_focus",{label:this.label})}async setIcon(e){return i("plugin:window|set_icon",{label:this.label,value:g(e)})}async setSkipTaskbar(e){return i("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return i("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return i("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return i("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");let t={};return t[`${e.type}`]={x:e.x,y:e.y},i("plugin:window|set_cursor_position",{label:this.label,value:t})}async setIgnoreCursorEvents(e){return i("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return i("plugin:window|start_dragging",{label:this.label})}async startResizeDragging(e){return i("plugin:window|start_resize_dragging",{label:this.label,value:e})}async setProgressBar(e){return i("plugin:window|set_progress_bar",{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return i("plugin:window|set_visible_on_all_workspaces",{label:this.label,value:e})}async onResized(e){return this.listen(l.WINDOW_RESIZED,t=>{t.payload=pe(t.payload),e(t)})}async onMoved(e){return this.listen(l.WINDOW_MOVED,t=>{t.payload=W(t.payload),e(t)})}async onCloseRequested(e){return this.listen(l.WINDOW_CLOSE_REQUESTED,t=>{let r=new G(t);Promise.resolve(e(r)).then(()=>{if(!r.isPreventDefault())return this.destroy()})})}async onDragDropEvent(e){let t=await this.listen(l.DRAG,s=>{e({...s,payload:{type:"dragged",paths:s.payload.paths,position:W(s.payload.position)}})}),r=await this.listen(l.DROP,s=>{e({...s,payload:{type:"dropped",paths:s.payload.paths,position:W(s.payload.position)}})}),a=await this.listen(l.DROP_OVER,s=>{e({...s,payload:{type:"dragOver",position:W(s.payload.position)}})}),u=await this.listen(l.DROP_CANCELLED,s=>{e({...s,payload:{type:"cancelled"}})});return()=>{t(),r(),a(),u()}}async onFocusChanged(e){let t=await this.listen(l.WINDOW_FOCUS,a=>{e({...a,payload:!0})}),r=await this.listen(l.WINDOW_BLUR,a=>{e({...a,payload:!1})});return()=>{t(),r()}}async onScaleChanged(e){return this.listen(l.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(l.WINDOW_THEME_CHANGED,e)}},Z;(function(n){n.AppearanceBased="appearanceBased",n.Light="light",n.Dark="dark",n.MediumLight="mediumLight",n.UltraDark="ultraDark",n.Titlebar="titlebar",n.Selection="selection",n.Menu="menu",n.Popover="popover",n.Sidebar="sidebar",n.HeaderView="headerView",n.Sheet="sheet",n.WindowBackground="windowBackground",n.HudWindow="hudWindow",n.FullScreenUI="fullScreenUI",n.Tooltip="tooltip",n.ContentBackground="contentBackground",n.UnderWindowBackground="underWindowBackground",n.UnderPageBackground="underPageBackground",n.Mica="mica",n.Blur="blur",n.Acrylic="acrylic",n.Tabbed="tabbed",n.TabbedDark="tabbedDark",n.TabbedLight="tabbedLight"})(Z||(Z={}));var Y;(function(n){n.FollowsWindowActiveState="followsWindowActiveState",n.Active="active",n.Inactive="inactive"})(Y||(Y={}));function W(n){return new d(n.x,n.y)}function pe(n){return new h(n.width,n.height)}function N(){return new v(H(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}function X(){return window.__TAURI_INTERNALS__.metadata.webviews.map(n=>new v(m.getByLabel(n.windowLabel),n.label,{skip:!0}))}var j=["tauri://created","tauri://error"],v=class{constructor(e,t,r){this.window=e,this.label=t,this.listeners=Object.create(null),r?.skip||i("plugin:webview|create_webview",{windowLabel:e.label,label:t,options:r}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static getByLabel(e){var t;return(t=X().find(r=>r.label===e))!==null&&t!==void 0?t:null}static getCurrent(){return N()}static getAll(){return X()}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):p(e,t,{target:{kind:"Webview",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):w(e,t,{target:{kind:"Webview",label:this.label}})}async emit(e,t){if(j.includes(e)){for(let r of this.listeners[e]||[])r({event:e,id:-1,payload:t});return Promise.resolve()}return x(e,t)}async emitTo(e,t,r){if(j.includes(t)){for(let a of this.listeners[t]||[])a({event:t,id:-1,payload:r});return Promise.resolve()}return P(e,t,r)}_handleTauriEvent(e,t){return j.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async position(){return i("plugin:webview|webview_position",{label:this.label}).then(({x:e,y:t})=>new d(e,t))}async size(){return i("plugin:webview|webview_size",{label:this.label}).then(({width:e,height:t})=>new h(e,t))}async close(){return i("plugin:webview|close",{label:this.label})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");let t={};return t[`${e.type}`]={width:e.width,height:e.height},i("plugin:webview|set_webview_size",{label:this.label,value:t})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");let t={};return t[`${e.type}`]={x:e.x,y:e.y},i("plugin:webview|set_webview_position",{label:this.label,value:t})}async setFocus(){return i("plugin:webview|set_webview_focus",{label:this.label})}async setZoom(e){return i("plugin:webview|set_webview_zoom",{label:this.label,value:e})}async reparent(e){return i("plugin:webview|set_webview_focus",{label:this.label,window:typeof e=="string"?e:e.label})}async onDragDropEvent(e){let t=await this.listen(l.DRAG,s=>{e({...s,payload:{type:"dragged",paths:s.payload.paths,position:$(s.payload.position)}})}),r=await this.listen(l.DROP,s=>{e({...s,payload:{type:"dropped",paths:s.payload.paths,position:$(s.payload.position)}})}),a=await this.listen(l.DROP_CANCELLED,s=>{e({...s,payload:{type:"dragOver",position:$(s.payload.position)}})}),u=await this.listen(l.DROP_CANCELLED,s=>{e({...s,payload:{type:"cancelled"}})});return()=>{t(),r(),a(),u()}}};function $(n){return new d(n.x,n.y)}function ye(){let n=N();return new C(n.label,{skip:!0})}function B(){return window.__TAURI_INTERNALS__.metadata.webviews.map(n=>new C(n.label,{skip:!0}))}var C=class n{constructor(e,t={}){var r;this.label=e,this.listeners=Object.create(null),t?.skip||i("plugin:webview|create_webview_window",{options:{...t,parent:typeof t.parent=="string"?t.parent:(r=t.parent)===null||r===void 0?void 0:r.label,label:e}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static getByLabel(e){var t;let r=(t=B().find(a=>a.label===e))!==null&&t!==void 0?t:null;return r?new n(r.label,{skip:!0}):null}static getCurrent(){return ye()}static getAll(){return B().map(e=>new n(e.label,{skip:!0}))}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):p(e,t,{target:{kind:"WebviewWindow",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):w(e,t,{target:{kind:"WebviewWindow",label:this.label}})}};we(C,[m,v]);function we(n,e){(Array.isArray(e)?e:[e]).forEach(t=>{Object.getOwnPropertyNames(t.prototype).forEach(r=>{var a;typeof n.prototype=="object"&&n.prototype&&r in n.prototype||Object.defineProperty(n.prototype,r,(a=Object.getOwnPropertyDescriptor(t.prototype,r))!==null&&a!==void 0?a:Object.create(null))})})}var ee;(function(n){n[n.Audio=1]="Audio",n[n.Cache=2]="Cache",n[n.Config=3]="Config",n[n.Data=4]="Data",n[n.LocalData=5]="LocalData",n[n.Document=6]="Document",n[n.Download=7]="Download",n[n.Picture=8]="Picture",n[n.Public=9]="Public",n[n.Video=10]="Video",n[n.Resource=11]="Resource",n[n.Temp=12]="Temp",n[n.AppConfig=13]="AppConfig",n[n.AppData=14]="AppData",n[n.AppLocalData=15]="AppLocalData",n[n.AppCache=16]="AppCache",n[n.AppLog=17]="AppLog",n[n.Desktop=18]="Desktop",n[n.Executable=19]="Executable",n[n.Font=20]="Font",n[n.Home=21]="Home",n[n.Runtime=22]="Runtime",n[n.Template=23]="Template"})(ee||(ee={}));var fe,ke;fe=new WeakMap,ke=new WeakMap;var Q;(function(n){n.Add="Add",n.Advanced="Advanced",n.Bluetooth="Bluetooth",n.Bookmarks="Bookmarks",n.Caution="Caution",n.ColorPanel="ColorPanel",n.ColumnView="ColumnView",n.Computer="Computer",n.EnterFullScreen="EnterFullScreen",n.Everyone="Everyone",n.ExitFullScreen="ExitFullScreen",n.FlowView="FlowView",n.Folder="Folder",n.FolderBurnable="FolderBurnable",n.FolderSmart="FolderSmart",n.FollowLinkFreestanding="FollowLinkFreestanding",n.FontPanel="FontPanel",n.GoLeft="GoLeft",n.GoRight="GoRight",n.Home="Home",n.IChatTheater="IChatTheater",n.IconView="IconView",n.Info="Info",n.InvalidDataFreestanding="InvalidDataFreestanding",n.LeftFacingTriangle="LeftFacingTriangle",n.ListView="ListView",n.LockLocked="LockLocked",n.LockUnlocked="LockUnlocked",n.MenuMixedState="MenuMixedState",n.MenuOnState="MenuOnState",n.MobileMe="MobileMe",n.MultipleDocuments="MultipleDocuments",n.Network="Network",n.Path="Path",n.PreferencesGeneral="PreferencesGeneral",n.QuickLook="QuickLook",n.RefreshFreestanding="RefreshFreestanding",n.Refresh="Refresh",n.Remove="Remove",n.RevealFreestanding="RevealFreestanding",n.RightFacingTriangle="RightFacingTriangle",n.Share="Share",n.Slideshow="Slideshow",n.SmartBadge="SmartBadge",n.StatusAvailable="StatusAvailable",n.StatusNone="StatusNone",n.StatusPartiallyAvailable="StatusPartiallyAvailable",n.StatusUnavailable="StatusUnavailable",n.StopProgressFreestanding="StopProgressFreestanding",n.StopProgress="StopProgress",n.TrashEmpty="TrashEmpty",n.TrashFull="TrashFull",n.User="User",n.UserAccounts="UserAccounts",n.UserGroup="UserGroup",n.UserGuest="UserGuest"})(Q||(Q={}));var o=M.invoke,xe=E.listen;async function zn(){return await o("show_window")}async function Un(){return await o("pick_and_load_waveform")}async function Vn(){return await o("load_file_with_selected_vars")}async function Gn(){return await o("get_hierarchy")}async function Hn(n,e,t,r,a,u){return await o("load_signal_and_get_timeline",{signal_ref_index:n,timeline_zoom:e,timeline_viewport_width:t,timeline_viewport_x:r,block_height:a,var_format:u})}async function jn(n){return await o("unload_signal",{signal_ref_index:n})}async function $n(n){return await o("add_decoders",{decoder_paths:n})}async function Nn(){return await o("remove_all_decoders")}async function Qn(n){return await o("add_diagram_connectors",{diagram_connector_paths:n})}async function qn(){return await o("remove_all_diagram_connectors")}async function Jn(n){return await xe("diagram_connector_message",e=>n(e.payload))}async function Kn(n,e,t){return await o("notify_diagram_connector_text_change",{diagram_connector:n,component_id:e,text:t})}async function Zn(){return await o("open_konata_file")}export{$n as add_decoders,Qn as add_diagram_connectors,Gn as get_hierarchy,Jn as listen_diagram_connectors_messages,Vn as load_file_with_selected_vars,Hn as load_signal_and_get_timeline,Kn as notify_diagram_connector_text_change,Zn as open_konata_file,Un as pick_and_load_waveform,Nn as remove_all_decoders,qn as remove_all_diagram_connectors,zn as show_window,jn as unload_signal}; +var se=Object.defineProperty;var q=(n,e)=>{for(var t in e)se(n,t,{get:e[t],enumerable:!0})};var M={};q(M,{Channel:()=>k,PluginListener:()=>R,Resource:()=>y,addPluginListener:()=>le,convertFileSrc:()=>oe,invoke:()=>i,isTauri:()=>ue,transformCallback:()=>T});function c(n,e,t,r){if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?n!==e||!r:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?r:t==="a"?r.call(n):r?r.value:e.get(n)}function _(n,e,t,r,a){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!a)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?n!==e||!a:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?a.call(n,t):a?a.value=t:e.set(n,t),t}var b,A,f,L;function T(n,e=!1){return window.__TAURI_INTERNALS__.transformCallback(n,e)}var k=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,b.set(this,()=>{}),A.set(this,0),f.set(this,{}),this.id=T(({message:e,id:t})=>{if(t===c(this,A,"f")){_(this,A,t+1,"f"),c(this,b,"f").call(this,e);let r=Object.keys(c(this,f,"f"));if(r.length>0){let a=t+1;for(let u of r.sort())if(parseInt(u)===a){let s=c(this,f,"f")[u];delete c(this,f,"f")[u],c(this,b,"f").call(this,s),a+=1}else break;_(this,A,a,"f")}}else c(this,f,"f")[t.toString()]=e})}set onmessage(e){_(this,b,e,"f")}get onmessage(){return c(this,b,"f")}toJSON(){return`__CHANNEL__:${this.id}`}};b=new WeakMap,A=new WeakMap,f=new WeakMap;var R=class{constructor(e,t,r){this.plugin=e,this.event=t,this.channelId=r}async unregister(){return i(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function le(n,e,t){let r=new k;return r.onmessage=t,i(`plugin:${n}|register_listener`,{event:e,handler:r}).then(()=>new R(n,e,r.id))}async function i(n,e={},t){return window.__TAURI_INTERNALS__.invoke(n,e,t)}function oe(n,e="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(n,e)}var y=class{get rid(){return c(this,L,"f")}constructor(e){L.set(this,void 0),_(this,L,e,"f")}async close(){return i("plugin:resources|close",{rid:this.rid})}};L=new WeakMap;function ue(){return"isTauri"in window&&!!window.isTauri}var E={};q(E,{TauriEvent:()=>l,emit:()=>x,emitTo:()=>P,listen:()=>p,once:()=>w});var l;(function(n){n.WINDOW_RESIZED="tauri://resize",n.WINDOW_MOVED="tauri://move",n.WINDOW_CLOSE_REQUESTED="tauri://close-requested",n.WINDOW_DESTROYED="tauri://destroyed",n.WINDOW_FOCUS="tauri://focus",n.WINDOW_BLUR="tauri://blur",n.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",n.WINDOW_THEME_CHANGED="tauri://theme-changed",n.WINDOW_CREATED="tauri://window-created",n.WEBVIEW_CREATED="tauri://webview-created",n.DRAG="tauri://drag",n.DROP="tauri://drop",n.DROP_OVER="tauri://drop-over",n.DROP_CANCELLED="tauri://drag-cancelled"})(l||(l={}));async function J(n,e){await i("plugin:event|unlisten",{event:n,eventId:e})}async function p(n,e,t){var r;let a=typeof t?.target=="string"?{kind:"AnyLabel",label:t.target}:(r=t?.target)!==null&&r!==void 0?r:{kind:"Any"};return i("plugin:event|listen",{event:n,target:a,handler:T(e)}).then(u=>async()=>J(n,u))}async function w(n,e,t){return p(n,r=>{e(r),J(n,r.id).catch(()=>{})},t)}async function x(n,e){await i("plugin:event|emit",{event:n,payload:e})}async function P(n,e,t){await i("plugin:event|emit_to",{target:typeof n=="string"?{kind:"AnyLabel",label:n}:n,event:e,payload:t})}var F=class{constructor(e,t){this.type="Logical",this.width=e,this.height=t}},h=class{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new F(this.width/e,this.height/e)}},O=class{constructor(e,t){this.type="Logical",this.x=e,this.y=t}},d=class{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new O(this.x/e,this.y/e)}};var I=class n extends y{constructor(e){super(e)}static async new(e,t,r){return i("plugin:image|new",{rgba:g(e),width:t,height:r}).then(a=>new n(a))}static async fromBytes(e){return i("plugin:image|from_bytes",{bytes:g(e)}).then(t=>new n(t))}static async fromPath(e){return i("plugin:image|from_path",{path:e}).then(t=>new n(t))}async rgba(){return i("plugin:image|rgba",{rid:this.rid}).then(e=>new Uint8Array(e))}async size(){return i("plugin:image|size",{rid:this.rid})}};function g(n){return n==null?null:typeof n=="string"?n:n instanceof Uint8Array?Array.from(n):n instanceof ArrayBuffer?Array.from(new Uint8Array(n)):n instanceof I?n.rid:n}var V;(function(n){n[n.Critical=1]="Critical",n[n.Informational=2]="Informational"})(V||(V={}));var G=class{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},K;(function(n){n.None="none",n.Normal="normal",n.Indeterminate="indeterminate",n.Paused="paused",n.Error="error"})(K||(K={}));function H(){return new m(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}function z(){return window.__TAURI_INTERNALS__.metadata.windows.map(n=>new m(n.label,{skip:!0}))}var U=["tauri://created","tauri://error"],m=class{constructor(e,t={}){var r;this.label=e,this.listeners=Object.create(null),t?.skip||i("plugin:window|create",{options:{...t,parent:typeof t.parent=="string"?t.parent:(r=t.parent)===null||r===void 0?void 0:r.label,label:e}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static getByLabel(e){var t;return(t=z().find(r=>r.label===e))!==null&&t!==void 0?t:null}static getCurrent(){return H()}static getAll(){return z()}static async getFocusedWindow(){for(let e of z())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):p(e,t,{target:{kind:"Window",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):w(e,t,{target:{kind:"Window",label:this.label}})}async emit(e,t){if(U.includes(e)){for(let r of this.listeners[e]||[])r({event:e,id:-1,payload:t});return Promise.resolve()}return x(e,t)}async emitTo(e,t,r){if(U.includes(t)){for(let a of this.listeners[t]||[])a({event:t,id:-1,payload:r});return Promise.resolve()}return P(e,t,r)}_handleTauriEvent(e,t){return U.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async scaleFactor(){return i("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return i("plugin:window|inner_position",{label:this.label}).then(({x:e,y:t})=>new d(e,t))}async outerPosition(){return i("plugin:window|outer_position",{label:this.label}).then(({x:e,y:t})=>new d(e,t))}async innerSize(){return i("plugin:window|inner_size",{label:this.label}).then(({width:e,height:t})=>new h(e,t))}async outerSize(){return i("plugin:window|outer_size",{label:this.label}).then(({width:e,height:t})=>new h(e,t))}async isFullscreen(){return i("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return i("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return i("plugin:window|is_maximized",{label:this.label})}async isFocused(){return i("plugin:window|is_focused",{label:this.label})}async isDecorated(){return i("plugin:window|is_decorated",{label:this.label})}async isResizable(){return i("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return i("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return i("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return i("plugin:window|is_closable",{label:this.label})}async isVisible(){return i("plugin:window|is_visible",{label:this.label})}async title(){return i("plugin:window|title",{label:this.label})}async theme(){return i("plugin:window|theme",{label:this.label})}async center(){return i("plugin:window|center",{label:this.label})}async requestUserAttention(e){let t=null;return e&&(e===V.Critical?t={type:"Critical"}:t={type:"Informational"}),i("plugin:window|request_user_attention",{label:this.label,value:t})}async setResizable(e){return i("plugin:window|set_resizable",{label:this.label,value:e})}async setMaximizable(e){return i("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return i("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return i("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return i("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return i("plugin:window|maximize",{label:this.label})}async unmaximize(){return i("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return i("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return i("plugin:window|minimize",{label:this.label})}async unminimize(){return i("plugin:window|unminimize",{label:this.label})}async show(){return i("plugin:window|show",{label:this.label})}async hide(){return i("plugin:window|hide",{label:this.label})}async close(){return i("plugin:window|close",{label:this.label})}async destroy(){return i("plugin:window|destroy",{label:this.label})}async setDecorations(e){return i("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return i("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return i("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return i("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return i("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return i("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return i("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");let t={};return t[`${e.type}`]={width:e.width,height:e.height},i("plugin:window|set_size",{label:this.label,value:t})}async setMinSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");let t=null;return e&&(t={},t[`${e.type}`]={width:e.width,height:e.height}),i("plugin:window|set_min_size",{label:this.label,value:t})}async setMaxSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");let t=null;return e&&(t={},t[`${e.type}`]={width:e.width,height:e.height}),i("plugin:window|set_max_size",{label:this.label,value:t})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");let t={};return t[`${e.type}`]={x:e.x,y:e.y},i("plugin:window|set_position",{label:this.label,value:t})}async setFullscreen(e){return i("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return i("plugin:window|set_focus",{label:this.label})}async setIcon(e){return i("plugin:window|set_icon",{label:this.label,value:g(e)})}async setSkipTaskbar(e){return i("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return i("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return i("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return i("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");let t={};return t[`${e.type}`]={x:e.x,y:e.y},i("plugin:window|set_cursor_position",{label:this.label,value:t})}async setIgnoreCursorEvents(e){return i("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return i("plugin:window|start_dragging",{label:this.label})}async startResizeDragging(e){return i("plugin:window|start_resize_dragging",{label:this.label,value:e})}async setProgressBar(e){return i("plugin:window|set_progress_bar",{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return i("plugin:window|set_visible_on_all_workspaces",{label:this.label,value:e})}async onResized(e){return this.listen(l.WINDOW_RESIZED,t=>{t.payload=he(t.payload),e(t)})}async onMoved(e){return this.listen(l.WINDOW_MOVED,t=>{t.payload=W(t.payload),e(t)})}async onCloseRequested(e){return this.listen(l.WINDOW_CLOSE_REQUESTED,t=>{let r=new G(t);Promise.resolve(e(r)).then(()=>{if(!r.isPreventDefault())return this.destroy()})})}async onDragDropEvent(e){let t=await this.listen(l.DRAG,s=>{e({...s,payload:{type:"dragged",paths:s.payload.paths,position:W(s.payload.position)}})}),r=await this.listen(l.DROP,s=>{e({...s,payload:{type:"dropped",paths:s.payload.paths,position:W(s.payload.position)}})}),a=await this.listen(l.DROP_OVER,s=>{e({...s,payload:{type:"dragOver",position:W(s.payload.position)}})}),u=await this.listen(l.DROP_CANCELLED,s=>{e({...s,payload:{type:"cancelled"}})});return()=>{t(),r(),a(),u()}}async onFocusChanged(e){let t=await this.listen(l.WINDOW_FOCUS,a=>{e({...a,payload:!0})}),r=await this.listen(l.WINDOW_BLUR,a=>{e({...a,payload:!1})});return()=>{t(),r()}}async onScaleChanged(e){return this.listen(l.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(l.WINDOW_THEME_CHANGED,e)}},Z;(function(n){n.AppearanceBased="appearanceBased",n.Light="light",n.Dark="dark",n.MediumLight="mediumLight",n.UltraDark="ultraDark",n.Titlebar="titlebar",n.Selection="selection",n.Menu="menu",n.Popover="popover",n.Sidebar="sidebar",n.HeaderView="headerView",n.Sheet="sheet",n.WindowBackground="windowBackground",n.HudWindow="hudWindow",n.FullScreenUI="fullScreenUI",n.Tooltip="tooltip",n.ContentBackground="contentBackground",n.UnderWindowBackground="underWindowBackground",n.UnderPageBackground="underPageBackground",n.Mica="mica",n.Blur="blur",n.Acrylic="acrylic",n.Tabbed="tabbed",n.TabbedDark="tabbedDark",n.TabbedLight="tabbedLight"})(Z||(Z={}));var Y;(function(n){n.FollowsWindowActiveState="followsWindowActiveState",n.Active="active",n.Inactive="inactive"})(Y||(Y={}));function W(n){return new d(n.x,n.y)}function he(n){return new h(n.width,n.height)}function N(){return new v(H(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}function X(){return window.__TAURI_INTERNALS__.metadata.webviews.map(n=>new v(m.getByLabel(n.windowLabel),n.label,{skip:!0}))}var j=["tauri://created","tauri://error"],v=class{constructor(e,t,r){this.window=e,this.label=t,this.listeners=Object.create(null),r?.skip||i("plugin:webview|create_webview",{windowLabel:e.label,label:t,options:r}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static getByLabel(e){var t;return(t=X().find(r=>r.label===e))!==null&&t!==void 0?t:null}static getCurrent(){return N()}static getAll(){return X()}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):p(e,t,{target:{kind:"Webview",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):w(e,t,{target:{kind:"Webview",label:this.label}})}async emit(e,t){if(j.includes(e)){for(let r of this.listeners[e]||[])r({event:e,id:-1,payload:t});return Promise.resolve()}return x(e,t)}async emitTo(e,t,r){if(j.includes(t)){for(let a of this.listeners[t]||[])a({event:t,id:-1,payload:r});return Promise.resolve()}return P(e,t,r)}_handleTauriEvent(e,t){return j.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async position(){return i("plugin:webview|webview_position",{label:this.label}).then(({x:e,y:t})=>new d(e,t))}async size(){return i("plugin:webview|webview_size",{label:this.label}).then(({width:e,height:t})=>new h(e,t))}async close(){return i("plugin:webview|close",{label:this.label})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");let t={};return t[`${e.type}`]={width:e.width,height:e.height},i("plugin:webview|set_webview_size",{label:this.label,value:t})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");let t={};return t[`${e.type}`]={x:e.x,y:e.y},i("plugin:webview|set_webview_position",{label:this.label,value:t})}async setFocus(){return i("plugin:webview|set_webview_focus",{label:this.label})}async setZoom(e){return i("plugin:webview|set_webview_zoom",{label:this.label,value:e})}async reparent(e){return i("plugin:webview|set_webview_focus",{label:this.label,window:typeof e=="string"?e:e.label})}async onDragDropEvent(e){let t=await this.listen(l.DRAG,s=>{e({...s,payload:{type:"dragged",paths:s.payload.paths,position:$(s.payload.position)}})}),r=await this.listen(l.DROP,s=>{e({...s,payload:{type:"dropped",paths:s.payload.paths,position:$(s.payload.position)}})}),a=await this.listen(l.DROP_CANCELLED,s=>{e({...s,payload:{type:"dragOver",position:$(s.payload.position)}})}),u=await this.listen(l.DROP_CANCELLED,s=>{e({...s,payload:{type:"cancelled"}})});return()=>{t(),r(),a(),u()}}};function $(n){return new d(n.x,n.y)}function we(){let n=N();return new C(n.label,{skip:!0})}function B(){return window.__TAURI_INTERNALS__.metadata.webviews.map(n=>new C(n.label,{skip:!0}))}var C=class n{constructor(e,t={}){var r;this.label=e,this.listeners=Object.create(null),t?.skip||i("plugin:webview|create_webview_window",{options:{...t,parent:typeof t.parent=="string"?t.parent:(r=t.parent)===null||r===void 0?void 0:r.label,label:e}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static getByLabel(e){var t;let r=(t=B().find(a=>a.label===e))!==null&&t!==void 0?t:null;return r?new n(r.label,{skip:!0}):null}static getCurrent(){return we()}static getAll(){return B().map(e=>new n(e.label,{skip:!0}))}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):p(e,t,{target:{kind:"WebviewWindow",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve(()=>{let r=this.listeners[e];r.splice(r.indexOf(t),1)}):w(e,t,{target:{kind:"WebviewWindow",label:this.label}})}};ge(C,[m,v]);function ge(n,e){(Array.isArray(e)?e:[e]).forEach(t=>{Object.getOwnPropertyNames(t.prototype).forEach(r=>{var a;typeof n.prototype=="object"&&n.prototype&&r in n.prototype||Object.defineProperty(n.prototype,r,(a=Object.getOwnPropertyDescriptor(t.prototype,r))!==null&&a!==void 0?a:Object.create(null))})})}var ee;(function(n){n[n.Audio=1]="Audio",n[n.Cache=2]="Cache",n[n.Config=3]="Config",n[n.Data=4]="Data",n[n.LocalData=5]="LocalData",n[n.Document=6]="Document",n[n.Download=7]="Download",n[n.Picture=8]="Picture",n[n.Public=9]="Public",n[n.Video=10]="Video",n[n.Resource=11]="Resource",n[n.Temp=12]="Temp",n[n.AppConfig=13]="AppConfig",n[n.AppData=14]="AppData",n[n.AppLocalData=15]="AppLocalData",n[n.AppCache=16]="AppCache",n[n.AppLog=17]="AppLog",n[n.Desktop=18]="Desktop",n[n.Executable=19]="Executable",n[n.Font=20]="Font",n[n.Home=21]="Home",n[n.Runtime=22]="Runtime",n[n.Template=23]="Template"})(ee||(ee={}));var ke,ve;ke=new WeakMap,ve=new WeakMap;var Q;(function(n){n.Add="Add",n.Advanced="Advanced",n.Bluetooth="Bluetooth",n.Bookmarks="Bookmarks",n.Caution="Caution",n.ColorPanel="ColorPanel",n.ColumnView="ColumnView",n.Computer="Computer",n.EnterFullScreen="EnterFullScreen",n.Everyone="Everyone",n.ExitFullScreen="ExitFullScreen",n.FlowView="FlowView",n.Folder="Folder",n.FolderBurnable="FolderBurnable",n.FolderSmart="FolderSmart",n.FollowLinkFreestanding="FollowLinkFreestanding",n.FontPanel="FontPanel",n.GoLeft="GoLeft",n.GoRight="GoRight",n.Home="Home",n.IChatTheater="IChatTheater",n.IconView="IconView",n.Info="Info",n.InvalidDataFreestanding="InvalidDataFreestanding",n.LeftFacingTriangle="LeftFacingTriangle",n.ListView="ListView",n.LockLocked="LockLocked",n.LockUnlocked="LockUnlocked",n.MenuMixedState="MenuMixedState",n.MenuOnState="MenuOnState",n.MobileMe="MobileMe",n.MultipleDocuments="MultipleDocuments",n.Network="Network",n.Path="Path",n.PreferencesGeneral="PreferencesGeneral",n.QuickLook="QuickLook",n.RefreshFreestanding="RefreshFreestanding",n.Refresh="Refresh",n.Remove="Remove",n.RevealFreestanding="RevealFreestanding",n.RightFacingTriangle="RightFacingTriangle",n.Share="Share",n.Slideshow="Slideshow",n.SmartBadge="SmartBadge",n.StatusAvailable="StatusAvailable",n.StatusNone="StatusNone",n.StatusPartiallyAvailable="StatusPartiallyAvailable",n.StatusUnavailable="StatusUnavailable",n.StopProgressFreestanding="StopProgressFreestanding",n.StopProgress="StopProgress",n.TrashEmpty="TrashEmpty",n.TrashFull="TrashFull",n.User="User",n.UserAccounts="UserAccounts",n.UserGroup="UserGroup",n.UserGuest="UserGuest"})(Q||(Q={}));var o=M.invoke,ae=E.listen;async function zn(){return await o("show_window")}async function Un(){return await o("pick_and_load_waveform")}async function Vn(){return await o("load_file_with_selected_vars")}async function Gn(){return await o("get_hierarchy")}async function Hn(n,e,t,r,a,u){return await o("load_signal_and_get_timeline",{signal_ref_index:n,timeline_zoom:e,timeline_viewport_width:t,timeline_viewport_x:r,block_height:a,var_format:u})}async function jn(n){return await o("unload_signal",{signal_ref_index:n})}async function $n(){return await o("send_char",{char:"a"})}async function Nn(n){return await o("add_decoders",{decoder_paths:n})}async function Qn(){return await o("remove_all_decoders")}async function qn(n){return await o("add_diagram_connectors",{diagram_connector_paths:n})}async function Jn(){return await o("remove_all_diagram_connectors")}async function Kn(n){return await ae("diagram_connector_message",e=>n(e.payload))}async function Zn(n){return await ae("term_content",e=>n(e.payload))}async function Yn(n,e,t){return await o("notify_diagram_connector_text_change",{diagram_connector:n,component_id:e,text:t})}async function Xn(){return await o("open_konata_file")}export{Nn as add_decoders,qn as add_diagram_connectors,Gn as get_hierarchy,Kn as listen_diagram_connectors_messages,Zn as listen_term_update,Vn as load_file_with_selected_vars,Hn as load_signal_and_get_timeline,Yn as notify_diagram_connector_text_change,Xn as open_konata_file,Un as pick_and_load_waveform,Qn as remove_all_decoders,Jn as remove_all_diagram_connectors,$n as send_char,zn as show_window,jn as unload_signal}; diff --git a/frontend/typescript/tauri_glue/tauri_glue.ts b/frontend/typescript/tauri_glue/tauri_glue.ts index 3f37098..f26ccc6 100644 --- a/frontend/typescript/tauri_glue/tauri_glue.ts +++ b/frontend/typescript/tauri_glue/tauri_glue.ts @@ -38,20 +38,20 @@ export async function get_hierarchy(): Promise { } export async function load_signal_and_get_timeline( - signal_ref_index: number, + signal_ref_index: number, timeline_zoom: number, timeline_viewport_width: number, - timeline_viewport_x: number, + timeline_viewport_x: number, block_height: number, var_format: VarFormat, ): Promise { - return await invoke("load_signal_and_get_timeline", { - signal_ref_index, - timeline_zoom, + return await invoke("load_signal_and_get_timeline", { + signal_ref_index, + timeline_zoom, timeline_viewport_width, timeline_viewport_x, - block_height, - var_format + block_height, + var_format }); } @@ -59,6 +59,11 @@ export async function unload_signal(signal_ref_index: number): Promise { return await invoke("unload_signal", { signal_ref_index }); } +export async function send_char(): Promise { + const char = "a"; + return await invoke("send_char", { char }); +} + export async function add_decoders(decoder_paths: Array): Promise { return await invoke("add_decoders", { decoder_paths }); } @@ -79,6 +84,10 @@ export async function listen_diagram_connectors_messages(on_message: (message: a 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 { return await invoke("notify_diagram_connector_text_change", { diagram_connector, component_id, text }); } diff --git a/shared/src/term.rs b/shared/src/term.rs index 64d0168..1f2c2b9 100644 --- a/shared/src/term.rs +++ b/shared/src/term.rs @@ -19,7 +19,7 @@ pub enum TerminalDownMsg { #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] #[serde(crate = "serde")] pub struct TerminalScreen { - pub cols : usize, - pub rows : usize, + pub cols : u16, + pub rows : u16, pub content : String, } diff --git a/src-tauri/src/aterm.rs b/src-tauri/src/aterm.rs new file mode 100644 index 0000000..c54d7fa --- /dev/null +++ b/src-tauri/src/aterm.rs @@ -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); +impl EventListener for EventProxy { + fn send_event(&self, event: Event) { + let _ = self.0.send(event.clone()); + } +} + +pub struct ATerm { + pub term: Arc>>, + + rows : u16, + 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 { + let (rows, cols) = (21, 158); + 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::( + 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, + }) + } +} + +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, 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; +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 6bb359b..b0f4636 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -24,10 +24,17 @@ type DiagramConnectorName = String; type ComponentId = String; mod component_manager; +mod aterm; +mod terminal_size; +use std::sync::Mutex; pub static APP_HANDLE: Lazy>>> = Lazy::new(<_>::default); pub static WAVEFORM: Lazy>>>> = Lazy::new(<_>::default); +static TERM: Lazy> = Lazy::new(|| { + Mutex::new(aterm::ATerm::new().expect("Failed to initialize ATerm")) +}); + #[derive(Default)] struct Store { waveform: Arc>>, @@ -146,6 +153,12 @@ async fn unload_signal(signal_ref_index: usize, store: tauri::State<'_, Store>) Ok(()) } +#[tauri::command(rename_all = "snake_case")] +async fn send_char() -> Result<(), ()> { + println!("Sending char: {}", "a"); + Ok(()) +} + #[tauri::command(rename_all = "snake_case")] async fn add_decoders(decoder_paths: Vec) -> Result { Ok(component_manager::decoders::add_decoders(decoder_paths).await) @@ -281,6 +294,7 @@ pub fn run() { get_hierarchy, load_signal_and_get_timeline, unload_signal, + send_char, add_decoders, remove_all_decoders, add_diagram_connectors,