Added PIPE like functionality to recieve/update active target buffer
This commit is contained in:
@@ -73,4 +73,3 @@ class Application:
|
|||||||
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR2"),
|
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR2"),
|
||||||
debug_signal_handler
|
debug_signal_handler
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
|
import base64
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from plugins import plugins_controller
|
from plugins import plugins_controller
|
||||||
@@ -27,6 +29,8 @@ class CodeBase:
|
|||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
event_system.subscribe("handle-file", self._load_ipc_file)
|
event_system.subscribe("handle-file", self._load_ipc_file)
|
||||||
event_system.subscribe("handle-files", self._load_ipc_files)
|
event_system.subscribe("handle-files", self._load_ipc_files)
|
||||||
|
event_system.subscribe("get-current-buffer-pipe", self._get_current_buffer_pipe)
|
||||||
|
event_system.subscribe("update-current-buffer-pipe", self._update_current_buffer_pipe)
|
||||||
|
|
||||||
def _load_controllers(self):
|
def _load_controllers(self):
|
||||||
files_controller = FilesController()
|
files_controller = FilesController()
|
||||||
@@ -61,3 +65,33 @@ class CodeBase:
|
|||||||
def _load_ipc_files(self, uris: list):
|
def _load_ipc_files(self, uris: list):
|
||||||
active_view = self.controller_manager["source_views"].signal_mapper.active_view
|
active_view = self.controller_manager["source_views"].signal_mapper.active_view
|
||||||
active_view._on_uri_data_received(uris)
|
active_view._on_uri_data_received(uris)
|
||||||
|
|
||||||
|
def _get_current_buffer_pipe(self):
|
||||||
|
active_view = self.controller_manager["source_views"].signal_mapper.active_view
|
||||||
|
buffer = active_view.get_buffer()
|
||||||
|
|
||||||
|
return buffer.get_text(
|
||||||
|
buffer.get_start_iter(),
|
||||||
|
buffer.get_end_iter()
|
||||||
|
)
|
||||||
|
|
||||||
|
def _update_current_buffer_pipe(self, data: str):
|
||||||
|
if not data: return
|
||||||
|
|
||||||
|
def do_update_current_buffer_pipe(data: str):
|
||||||
|
data = base64.b64decode(data).decode()
|
||||||
|
active_view = self.controller_manager["source_views"].signal_mapper.active_view
|
||||||
|
buffer = active_view.get_buffer()
|
||||||
|
|
||||||
|
buffer.delete(
|
||||||
|
buffer.get_start_iter(),
|
||||||
|
buffer.get_end_iter()
|
||||||
|
)
|
||||||
|
|
||||||
|
buffer.insert(
|
||||||
|
buffer.get_start_iter(),
|
||||||
|
data,
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
|
||||||
|
GLib.idle_add(do_update_current_buffer_pipe, data)
|
||||||
|
|||||||
@@ -105,6 +105,20 @@ class IPCServer(Singleton):
|
|||||||
conn.close()
|
conn.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if "OPIPE" in msg:
|
||||||
|
data = event_system.emit_and_await("get-current-buffer-pipe")
|
||||||
|
conn.send(data)
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
if "IPIPE|" in msg:
|
||||||
|
data = msg.split("IPIPE|")[1].strip()
|
||||||
|
event_system.emit("update-current-buffer-pipe", data)
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
if msg in ['close connection', 'close server', 'Empty Data...']:
|
if msg in ['close connection', 'close server', 'Empty Data...']:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
Executable
+66
@@ -0,0 +1,66 @@
|
|||||||
|
#!/bin/env python
|
||||||
|
|
||||||
|
# Python imports
|
||||||
|
import sys
|
||||||
|
import base64
|
||||||
|
from multiprocessing.connection import Client
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
APP_NAME = "Newton"
|
||||||
|
address = f"/tmp/{APP_NAME}-ipc.sock"
|
||||||
|
authkey = f"{APP_NAME}-ipc".encode()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def send_command(command: str, receive: bool = False):
|
||||||
|
conn = Client(address, family = "AF_UNIX", authkey = authkey)
|
||||||
|
|
||||||
|
try:
|
||||||
|
conn.send(command)
|
||||||
|
if receive:
|
||||||
|
return conn.recv()
|
||||||
|
except EOFError:
|
||||||
|
print("Server disconnected", file=sys.stderr)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def do_commands():
|
||||||
|
for command in sys.argv[1:]:
|
||||||
|
if command.lower() in ("exit", "quit", "q"):
|
||||||
|
break
|
||||||
|
|
||||||
|
print("Command:", command)
|
||||||
|
response = send_command(
|
||||||
|
command,
|
||||||
|
receive = (command.lower() == "opipe")
|
||||||
|
)
|
||||||
|
|
||||||
|
if response is not None:
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
command = sys.stdin.read().strip()
|
||||||
|
encoded = base64.b64encode(command.encode()).decode()
|
||||||
|
|
||||||
|
if not encoded: return
|
||||||
|
|
||||||
|
response = send_command(f"IPIPE|{encoded}", receive = True)
|
||||||
|
if response is not None:
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
do_commands()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user