feat: lua leave, detach, delete

This commit is contained in:
əlemi 2024-08-08 04:42:11 +02:00
parent e736646b8c
commit 0aa7690533
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -3,6 +3,7 @@ use std::sync::Mutex;
use crate::api::Cursor;
use crate::prelude::*;
use crate::workspace::DetachResult;
use mlua::prelude::*;
use tokio::sync::broadcast;
@ -61,6 +62,10 @@ impl LuaUserData for CodempClient {
Ok(cursor)
});
methods.add_method("leave_workspace", |_, this, (session,):(String,)| {
Ok(this.leave_workspace(&session))
});
methods.add_method("get_workspace", |_, this, (session,):(String,)| Ok(this.get_workspace(&session)));
}
@ -73,12 +78,17 @@ impl LuaUserData for CodempWorkspace {
Ok(RT.block_on(async { this.create(&name).await })?)
});
methods.add_method("attach_buffer", |_, this, (name,):(String,)| {
methods.add_method("attach", |_, this, (name,):(String,)| {
Ok(RT.block_on(async { this.attach(&name).await })?)
});
// TODO disconnect_buffer
// TODO leave_workspace:w
methods.add_method("detach", |_, this, (name,):(String,)| {
Ok(matches!(this.detach(&name), DetachResult::Detaching | DetachResult::AlreadyDetached))
});
methods.add_method("delete_buffer", |_, this, (name,):(String,)| {
Ok(RT.block_on(this.delete(&name))?)
});
methods.add_method("get_buffer", |_, this, (name,):(String,)| Ok(this.buffer_by_name(&name)));
}