pi-sync-system-theme 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.ts +16 -7
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -216,8 +216,9 @@ let fd;
216
216
  try { fd = fs.openSync('/dev/tty', fs.constants.O_RDWR | fs.constants.O_NOCTTY | O_NONBLOCK); }
217
217
  catch { process.exit(1); }
218
218
 
219
- // Send OSC 11 query (BEL terminator is widely supported)
220
- try { fs.writeSync(fd, '\x1b]11;?\x07'); }
219
+ // Send OSC 11 query.
220
+ // Use ST terminator for better compatibility with tmux passthrough.
221
+ try { fs.writeSync(fd, '\x1b]11;?\x1b\\'); }
221
222
  catch { try { fs.closeSync(fd); } catch {} process.exit(1); }
222
223
 
223
224
  const buf = Buffer.alloc(1024);
@@ -239,13 +240,21 @@ function tryRead() {
239
240
  }
240
241
  }
241
242
 
243
+ function to8Bit(hex) {
244
+ if (!hex) return 0;
245
+ const h = String(hex);
246
+ if (h.length <= 2) return parseInt(h.padEnd(2, h[h.length - 1] || '0'), 16);
247
+ return parseInt(h.slice(0, 2), 16);
248
+ }
249
+
242
250
  function done() {
243
251
  try { fs.closeSync(fd); } catch {}
244
- const m = response.match(/\x1b\]11;rgb:([0-9a-fA-F]+)\\/([0-9a-fA-F]+)\\/([0-9a-fA-F]+)(?:\x07|\x1b\\\\)/);
252
+ // Keep parser permissive: tmux may wrap control sequences, but rgb payload remains stable.
253
+ const m = response.match(/rgb:([0-9a-fA-F]{2,4})\\/([0-9a-fA-F]{2,4})\\/([0-9a-fA-F]{2,4})/);
245
254
  if (m) {
246
- const r = parseInt(m[1].slice(0, 2), 16);
247
- const g = parseInt(m[2].slice(0, 2), 16);
248
- const b = parseInt(m[3].slice(0, 2), 16);
255
+ const r = to8Bit(m[1]);
256
+ const g = to8Bit(m[2]);
257
+ const b = to8Bit(m[3]);
249
258
  const luminance = 0.299 * r + 0.587 * g + 0.114 * b;
250
259
  process.stdout.write(luminance < 128 ? 'dark' : 'light');
251
260
  }
@@ -254,7 +263,7 @@ function done() {
254
263
 
255
264
  function poll() {
256
265
  tryRead();
257
- if (response.includes('\x1b]11;') || Date.now() > deadline) return done();
266
+ if (response.includes('rgb:') || Date.now() > deadline) return done();
258
267
  setTimeout(poll, 16);
259
268
  }
260
269
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-sync-system-theme",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Sync pi theme with system appearance — works locally and over SSH via OSC 11 terminal queries",
5
5
  "keywords": [
6
6
  "pi-package",