2023-08-17 18:39:47 +02:00
|
|
|
import asyncio
|
|
|
|
import Codemp.bindings.codemp_client as libcodemp
|
|
|
|
|
|
|
|
class CodempClient():
|
|
|
|
|
|
|
|
def __init__(self):
|
2023-08-25 14:29:11 +02:00
|
|
|
self.handle = libcodemp.codemp_init()
|
2023-11-22 12:25:08 +01:00
|
|
|
## Bindings
|
2023-08-25 14:29:11 +02:00
|
|
|
async def connect(self, server_host): # -> None
|
|
|
|
await self.handle.connect(server_host)
|
2023-08-29 23:38:39 +02:00
|
|
|
|
2023-08-25 14:29:11 +02:00
|
|
|
async def join(self, session): # -> CursorController
|
2023-11-22 12:25:08 +01:00
|
|
|
return CursorController(await self.handle.join(session))
|
|
|
|
|
|
|
|
async def create(self, path, content=None): # -> None
|
|
|
|
await self.handle.create(path, content)
|
2023-08-25 14:29:11 +02:00
|
|
|
|
|
|
|
async def attach(self, path): # -> BufferController
|
2023-11-22 12:25:08 +01:00
|
|
|
return BufferController(await self.handle.attach(path))
|
2023-08-25 14:29:11 +02:00
|
|
|
|
|
|
|
async def get_cursor(self): # -> CursorController
|
2023-11-22 12:25:08 +01:00
|
|
|
return CursorController(await self.handle.get_cursor())
|
2023-08-17 18:39:47 +02:00
|
|
|
|
2023-08-25 14:29:11 +02:00
|
|
|
async def get_buffer(self, path): # -> BufferController
|
2023-11-22 12:25:08 +01:00
|
|
|
return BufferController(await self.handle.get_buffer())
|
2023-08-17 18:39:47 +02:00
|
|
|
|
2023-11-22 12:25:08 +01:00
|
|
|
async def leave_workspace(self): # -> None
|
|
|
|
await self.handle.leave_workspace()
|
|
|
|
|
2023-09-04 17:01:04 +02:00
|
|
|
async def disconnect_buffer(self, path): # -> None
|
2023-11-22 12:25:08 +01:00
|
|
|
await self.handle.disconnect_buffer(path)
|
2023-08-17 18:39:47 +02:00
|
|
|
|
2023-11-24 10:36:06 +01:00
|
|
|
async def select_buffer(self): # -> String
|
2023-11-22 12:25:08 +01:00
|
|
|
await self.handle.select_buffer()
|
|
|
|
|
|
|
|
## Custom
|
|
|
|
async def disconnect(self): # -> None
|
|
|
|
# disconnect all buffers and workspaces first, maybe?
|
|
|
|
await self.leave_workspace()
|
|
|
|
# drop the handle, it will require a new instantiation
|
|
|
|
self.handle = None
|
2023-08-29 23:38:39 +02:00
|
|
|
|
2023-08-17 18:39:47 +02:00
|
|
|
class CursorController():
|
|
|
|
def __init__(self, handle):
|
|
|
|
self.handle = handle
|
|
|
|
|
2023-08-25 14:29:11 +02:00
|
|
|
def send(self, path, start, end): # -> None
|
|
|
|
self.handle.send(path, start, end)
|
|
|
|
|
|
|
|
def try_recv(self): # -> Optional[CursorEvent]
|
|
|
|
return self.handle.try_recv()
|
2023-08-17 18:39:47 +02:00
|
|
|
|
2023-08-25 14:29:11 +02:00
|
|
|
async def recv(self): # -> CursorEvent
|
|
|
|
return await self.handle.recv()
|
|
|
|
|
|
|
|
async def poll(self): # -> None
|
|
|
|
# await until new cursor event, then returns
|
|
|
|
return await self.handle.poll()
|
|
|
|
|
|
|
|
class BufferController():
|
2023-08-17 18:39:47 +02:00
|
|
|
def __init__(self, handle):
|
|
|
|
self.handle = handle
|
|
|
|
|
2023-11-24 10:36:06 +01:00
|
|
|
def content(self): # -> String
|
|
|
|
return self.content()
|
|
|
|
|
2023-11-22 12:25:08 +01:00
|
|
|
def send(self, start, end, txt): # -> None
|
|
|
|
self.handle.send(start, end, txt)
|
2023-08-25 14:29:11 +02:00
|
|
|
|
|
|
|
def try_recv(self): # -> Optional[TextChange]
|
|
|
|
return self.handle.try_recv()
|
|
|
|
|
|
|
|
async def recv(self): # -> TextChange
|
|
|
|
return await self.handle.recv()
|
|
|
|
|
|
|
|
async def poll(self): # -> ??
|
|
|
|
return await self.handle.poll()
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-17 18:39:47 +02:00
|
|
|
|
|
|
|
|