From 8f407f74ae80baa2d0ff294d6de46298dc03d34e Mon Sep 17 00:00:00 2001 From: Mortdecai Date: Thu, 26 Mar 2026 19:34:23 -0400 Subject: [PATCH] fix: toolbar buttons now send actual control chars via xterm _core API Buttons were sending literal 'n'/'p' instead of Ctrl-A+n/p because the hex escape decode was failing. Now uses real control characters in data-k attributes and sends via triggerDataEvent() which hooks directly into ttyd's websocket transport. --- static/toolbar.js | 55 ++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/static/toolbar.js b/static/toolbar.js index 16ef820..2dc5995 100644 --- a/static/toolbar.js +++ b/static/toolbar.js @@ -28,37 +28,46 @@ bar.id='mb'; bar.innerHTML= '
'+ - ''+ - ''+ - ''+ + ''+ + ''+ + ''+ '
'+ - ''+ - ''+ - ''+ + ''+ + ''+ + ''+ '
'+ - ''+ - ''+ - ''+ - ''+ + ''+ + ''+ + ''+ + ''+ '
'+ '
'+ ''+ ''+ - ''+ + ''+ ''+ '
'+ - ''+ - ''+ - ''+ - ''+ + ''+ + ''+ + ''+ + ''+ '
'; document.body.appendChild(bar); + // Send data to terminal via xterm's _core (bypasses any .input() issues) function send(k){ if(document.body.classList.contains('selmode')) toggleSel(); - k=k.replace(/\\x([0-9a-f]{2})/gi,function(_,h){return String.fromCharCode(parseInt(h,16));}); - k=k.replace(/\\t/g,'\t'); - if(window.term){window.term.input(k);window.term.focus();} + var t=window.term; + if(!t) return; + // Try _core.triggerDataEvent first (fires onData which ttyd hooks) + if(t._core && t._core.coreService && t._core.coreService.triggerDataEvent){ + t._core.coreService.triggerDataEvent(k); + } else if(t._core && t._core._onData){ + t._core._onData.fire(k); + } else if(t.input){ + t.input(k); + } + t.focus(); } function toggleSel(){ @@ -79,18 +88,14 @@ return; } navigator.clipboard.readText().then(function(text){ - if(text && window.term){ - window.term.input(text); - window.term.focus(); - } + if(text) send(text); }).catch(function(e){ alert('Clipboard read failed: '+e.message); }); } function doSave(){ - // Trigger tmux capture-pane via the keybinding Ctrl-A S - send('\\x01S'); + send('\x01S'); var btn=document.querySelector('[data-save]'); btn.classList.add('on'); btn.textContent='\u2713'; @@ -106,7 +111,7 @@ if(btn.dataset.k) send(btn.dataset.k); }); - // Shrink terminal for toolbar on mobile (2 rows now) + // Shrink terminal for toolbar on mobile (2 rows) var obs=new MutationObserver(function(){ var el=document.querySelector('.xterm'); if(el && window.innerWidth<=900){