-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
246 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ pub mod util; | |
|
||
pub mod sdwirec; | ||
|
||
pub mod pylogger; | ||
mod pylogger; | ||
pub mod asciicast; | ||
|
||
pub mod deansi; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//! IPC between windows and sub-windows. | ||
//! | ||
//! As the program may run in multiple processes, or in same process but different address space, | ||
//! we need a way to communicate between windows and sub-windows. | ||
use std::{ | ||
error::Error, | ||
io::{BufReader, ErrorKind}, | ||
}; | ||
|
||
use interprocess::local_socket::{ | ||
traits::ListenerExt, GenericNamespaced, Listener, ListenerNonblockingMode, ListenerOptions, | ||
ToNsName, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::from_reader; | ||
|
||
use crate::info; | ||
|
||
use super::{ | ||
main::MyApp, | ||
util::get_main_virt, | ||
}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct WindowIpcMessage { | ||
pub window_id: u64, | ||
pub message: String, | ||
} | ||
|
||
pub fn init_ipc() -> Result<Listener, Box<dyn Error>> { | ||
let sock_name = get_sock_name(get_main_virt().to_owned(), None); | ||
let sock_name = sock_name.to_ns_name::<GenericNamespaced>()?; | ||
|
||
let opts = ListenerOptions::new() | ||
.name(sock_name) | ||
.nonblocking(ListenerNonblockingMode::Both); | ||
|
||
let listener = opts.create_sync()?; | ||
Ok(listener) | ||
} | ||
|
||
impl MyApp { | ||
pub(super) fn handle_ipc(&mut self) { | ||
for m in self.listener.incoming() { | ||
match m { | ||
Err(e) if e.kind() == ErrorKind::WouldBlock => { | ||
info!("IPC would block"); | ||
break; | ||
} | ||
Err(e) => { | ||
info!("IPC error: {}", e); | ||
continue; | ||
} | ||
Ok(m) => { | ||
info!("IPC message received"); | ||
let mut reader = BufReader::new(m); | ||
let msg: WindowIpcMessage = match from_reader(&mut reader) { | ||
Ok(m) => m, | ||
Err(e) => { | ||
info!("IPC message decode error: {}", e); | ||
continue; | ||
} | ||
}; | ||
info!( | ||
"Received IPC message from window {}: {}", | ||
msg.window_id, msg.message | ||
); | ||
let conn = reader.get_mut(); | ||
for w in self.sub_windows.iter_mut() { | ||
if w.id.value() == msg.window_id { | ||
w.window.on_ipc(&msg.message, conn); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn get_sock_name(base_name: String, window_id: Option<u64>) -> String { | ||
if let Some(id) = window_id { | ||
format!("{}_{}.sock", base_name, id) | ||
} else { | ||
base_name + ".sock" | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
//! Parts to handle the UI render part | ||
//! | ||
//! | ||
//! If only use CLI feats, this part can be ignored; | ||
//! however, GUI part may need this part show what's going on. | ||
//! Or, use to create needle for GUI part. | ||
//! | ||
//! | ||
pub mod main; | ||
pub mod cli_hooker; | ||
pub mod code_editor; | ||
pub mod main; | ||
pub mod pyenv; | ||
pub mod terminal; | ||
pub mod cli_hooker; | ||
pub mod ui_cli_exec; | ||
pub mod util; | ||
pub mod ipc; | ||
|
||
mod test_window; | ||
|
||
use pyo3::{types::{PyModule, PyModuleMethods}, Bound, PyResult}; | ||
use pyo3::{ | ||
types::{PyModule, PyModuleMethods}, | ||
wrap_pyfunction, Bound, PyResult, | ||
}; | ||
use ui_cli_exec::UiExec; | ||
use util::__init_sub_virt__; | ||
|
||
pub fn register_ui(parent_module: &Bound<'_, PyModule>) -> PyResult<()> { | ||
let m = PyModule::new_bound(parent_module.py(), "ui")?; | ||
m.add_class::<UiExec>()?; | ||
|
||
m.add_function(wrap_pyfunction!(__init_sub_virt__, &m)?)?; | ||
|
||
parent_module.add_submodule(&m)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.