-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexicon-toggle.sh
More file actions
executable file
·38 lines (33 loc) · 914 Bytes
/
Copy pathlexicon-toggle.sh
File metadata and controls
executable file
·38 lines (33 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
#
# lexicon-toggle — toggle the Lexicon overlay.
#
# Sends a message to the Spine (ZeroMQ) to toggle visibility.
# Falls back to HTTP POST if ZeroMQ isn't available.
#
# Usage:
# ./lexicon-toggle # via ZeroMQ (fast, <1ms)
# ./lexicon-toggle --http # via curl fallback
#
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND="$SCRIPT_DIR/lexicon-backend"
SPINE_PORT=5557
HTTP_PORT=8765
# ── Try ZeroMQ first (preferred — fastest path) ──
if [ "$1" != "--http" ]; then
# Use Python + pyzmq from the backend venv
# PUSH/PULL pattern — no slow-joiner, guaranteed delivery
if "$BACKEND/.venv/bin/python" -c "
import zmq
ctx = zmq.Context()
sock = ctx.socket(zmq.PUSH)
sock.connect('tcp://127.0.0.1:$SPINE_PORT')
sock.send_string('lexicon/toggle')
sock.close()
ctx.term()
" 2>/dev/null; then
exit 0
fi
fi
# ── Fallback: HTTP POST ──