Skip to content

Commit fbbafa9

Browse files
committed
v0.0.6: Implement basic persist
1 parent cd57574 commit fbbafa9

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

.binary_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.4
1+
v0.0.6

binary.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from simple_websocket_server import WebSocket
1717
from simple_websocket_server import WebSocketServer
1818

19-
BUILD_VERSION = "v0.0.4"
19+
BUILD_VERSION = "v0.0.6"
2020
TEMP_FILEPATH = os.path.join(tempfile.gettempdir(), "nvim-ghost.nvim.port")
2121
WINDOWS = os.name == "nt"
2222
LOCALHOST = "127.0.0.1" if WINDOWS else "localhost"
@@ -108,6 +108,8 @@ def __init__(self):
108108
}
109109
self.argument_handlers_nodata = {
110110
"--start-server": self._start,
111+
"--nopersist": self._nopersist,
112+
"--persist": self._persist,
111113
"--version": self._version,
112114
"--focus": self._focus,
113115
"--help": self._help,
@@ -146,6 +148,16 @@ def _start(self):
146148
global START_SERVER
147149
START_SERVER = True
148150

151+
def _persist(self):
152+
global PERSIST
153+
PERSIST = True
154+
self.server_requests.append("/persist")
155+
156+
def _nopersist(self):
157+
global PERSIST
158+
PERSIST = False
159+
self.server_requests.append("/nopersist")
160+
149161
def _port(self, port: str):
150162
if not port.isdigit():
151163
sys.exit("Invalid port")
@@ -184,6 +196,8 @@ def do_GET(self):
184196
"/version": self._version_responder,
185197
"/exit": self._exit_responder,
186198
"/kill": self._exit_responder,
199+
"/persist": self._persist_responder,
200+
"/nopersist": self._nopersist_responder,
187201
"/is_ghost_binary": self._sanityCheck_responder,
188202
}
189203

@@ -224,6 +238,22 @@ def _exit_responder(self):
224238
global RUNNING
225239
RUNNING = False
226240

241+
def _persist_responder(self):
242+
global PERSIST
243+
PERSIST = True
244+
self.send_response(200)
245+
self.send_header("Content-Type", "text/plain")
246+
self.end_headers()
247+
self.wfile.write(f"PERSIST={PERSIST}".encode("utf-8"))
248+
249+
def _nopersist_responder(self):
250+
global PERSIST
251+
PERSIST = False
252+
self.send_response(200)
253+
self.send_header("Content-Type", "text/plain")
254+
self.end_headers()
255+
self.wfile.write(f"PERSIST={PERSIST}".encode("utf-8"))
256+
227257
def _sanityCheck_responder(self):
228258
self.send_response(200)
229259
self.send_header("Content-Type", "text/plain")
@@ -255,9 +285,10 @@ def _session_closed_responder(self, query_string):
255285
self.end_headers()
256286
self.wfile.write(address.encode("utf-8"))
257287
global WEBSOCKETS_PER_NEOVIM_SOCKET_ADDRESS
258-
for item in WEBSOCKETS_PER_NEOVIM_SOCKET_ADDRESS[address]:
259-
item.close()
260-
del WEBSOCKETS_PER_NEOVIM_SOCKET_ADDRESS[address]
288+
if WEBSOCKET_PER_BUFFER_PER_NEOVIM_ADDRESS.__contains__(address):
289+
for item in WEBSOCKETS_PER_NEOVIM_SOCKET_ADDRESS[address]:
290+
item.close()
291+
del WEBSOCKETS_PER_NEOVIM_SOCKET_ADDRESS[address]
261292
if not PERSIST and len(WEBSOCKETS_PER_NEOVIM_SOCKET_ADDRESS) == 0:
262293
global RUNNING
263294
RUNNING = False

0 commit comments

Comments
 (0)