2024-08-17 23:47:06 +02:00
|
|
|
use crate::buffer::Controller as BufferController;
|
|
|
|
use crate::cursor::Controller as CursorController;
|
|
|
|
use crate::workspace::Workspace;
|
|
|
|
use pyo3::prelude::*;
|
2024-08-17 01:09:29 +02:00
|
|
|
|
2024-08-20 22:18:29 +02:00
|
|
|
use super::RustPromise;
|
|
|
|
use crate::a_sync;
|
2024-08-20 21:09:10 +02:00
|
|
|
// use super::Promise;
|
2024-08-20 17:16:36 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pymethods]
|
|
|
|
impl Workspace {
|
|
|
|
// join a workspace
|
|
|
|
#[pyo3(name = "create")]
|
2024-08-20 22:18:29 +02:00
|
|
|
fn pycreate(&self, path: String) -> PyResult<RustPromise> {
|
|
|
|
let this = self.clone();
|
|
|
|
a_sync!(this.create(path.as_str()).await)
|
2024-08-17 23:47:06 +02:00
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "attach")]
|
2024-08-20 22:18:29 +02:00
|
|
|
fn pyattach(&self, path: String) -> PyResult<RustPromise> {
|
|
|
|
let this = self.clone();
|
|
|
|
a_sync!(this.attach(path.as_str()).await)
|
2024-08-17 23:47:06 +02:00
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "detach")]
|
|
|
|
fn pydetach(&self, path: String) -> bool {
|
|
|
|
match self.detach(path.as_str()) {
|
|
|
|
crate::workspace::worker::DetachResult::NotAttached => false,
|
|
|
|
crate::workspace::worker::DetachResult::Detaching => true,
|
|
|
|
crate::workspace::worker::DetachResult::AlreadyDetached => true,
|
|
|
|
}
|
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-20 22:18:29 +02:00
|
|
|
#[pyo3(name = "event")]
|
|
|
|
fn pyevent(&self) -> PyResult<RustPromise> {
|
|
|
|
let this = self.clone();
|
|
|
|
a_sync!(this.event().await)
|
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "fetch_buffers")]
|
2024-08-20 22:18:29 +02:00
|
|
|
fn pyfetch_buffers(&self) -> PyResult<RustPromise> {
|
|
|
|
let this = self.clone();
|
|
|
|
a_sync!(this.fetch_buffers().await)
|
2024-08-17 23:47:06 +02:00
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "fetch_users")]
|
2024-08-20 22:18:29 +02:00
|
|
|
fn pyfetch_users(&self) -> PyResult<RustPromise> {
|
|
|
|
let this = self.clone();
|
|
|
|
a_sync!(this.fetch_users().await)
|
2024-08-17 23:47:06 +02:00
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "list_buffer_users")]
|
2024-08-20 22:18:29 +02:00
|
|
|
fn pylist_buffer_users(&self, path: String) -> PyResult<RustPromise> {
|
|
|
|
// crate::Result<Vec<crate::api::User>> {
|
|
|
|
let this = self.clone();
|
|
|
|
a_sync!(this.list_buffer_users(path.as_str()).await)
|
2024-08-17 23:47:06 +02:00
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "delete")]
|
2024-08-20 22:18:29 +02:00
|
|
|
fn pydelete(&self, path: String) -> PyResult<RustPromise> {
|
|
|
|
let this = self.clone();
|
|
|
|
a_sync!(this.delete(path.as_str()).await)
|
2024-08-17 23:47:06 +02:00
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "id")]
|
|
|
|
fn pyid(&self) -> String {
|
|
|
|
self.id()
|
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "cursor")]
|
|
|
|
fn pycursor(&self) -> CursorController {
|
|
|
|
self.cursor()
|
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "buffer_by_name")]
|
|
|
|
fn pybuffer_by_name(&self, path: String) -> Option<BufferController> {
|
|
|
|
self.buffer_by_name(path.as_str())
|
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "buffer_list")]
|
|
|
|
fn pybuffer_list(&self) -> Vec<String> {
|
|
|
|
self.buffer_list()
|
|
|
|
}
|
2024-08-16 12:58:43 +02:00
|
|
|
|
2024-08-17 23:47:06 +02:00
|
|
|
#[pyo3(name = "filetree")]
|
|
|
|
fn pyfiletree(&self) -> Vec<String> {
|
|
|
|
self.filetree()
|
|
|
|
}
|
|
|
|
}
|