From 96606d2b0befb8893c6d9ed7e4f348295d1b4b85 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Thu, 8 Oct 2015 12:56:56 +0200 Subject: [PATCH] Add session list --- butterfly/__init__.py | 2 +- butterfly/bin/butterfly_help | 7 ++++--- butterfly/routes.py | 15 ++++++++++----- butterfly/sass/_layout.sass | 4 ++-- butterfly/static/ext.js | 32 ++++++++++++++++++++++++++++++-- butterfly/static/ext.min.js | 2 +- butterfly/static/main.css | 10 +++++----- butterfly/templates/list.html | 24 ------------------------ coffees/ext/sessions.coffee | 22 ++++++++++++++++++++++ coffees/ext/theme.coffee | 2 -- 10 files changed, 75 insertions(+), 45 deletions(-) delete mode 100644 butterfly/templates/list.html create mode 100644 coffees/ext/sessions.coffee diff --git a/butterfly/__init__.py b/butterfly/__init__.py index 921af14..adf6cd0 100644 --- a/butterfly/__init__.py +++ b/butterfly/__init__.py @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = '2.0.3' +__version__ = '2.0.5' import os diff --git a/butterfly/bin/butterfly_help b/butterfly/bin/butterfly_help index 8e73d0d..b9849e8 100755 --- a/butterfly/bin/butterfly_help +++ b/butterfly/bin/butterfly_help @@ -16,11 +16,12 @@ print(""" Butterfly is a xterm compliant terminal built with python and javascript. {title}Terminal functionalities:{reset} - {strong}[Alt] + [a] : {reset}Set an alarm which sends a notification when a modification is detected. (Ring on regexp match with [Shift]) - {strong}[Alt] + [s] : {reset}Open theme selection prompt. Use [Alt] + [Shift] + [s] to refresh current theme. - {strong}[Ctrl] + [Shift] + [Up] : {reset}Trigger visual selection mode. Hitting [Enter] inserts the selection in the prompt. {strong}[ScrollLock] : {reset}Lock the scrolling to the current position. Press again to release. {strong}[Ctrl] + [c] <> : {reset}Cut the output when [Ctrl] + [c] is not enough. + {strong}[Ctrl] + [Shift] + [Up] : {reset}Trigger visual selection mode. Hitting [Enter] inserts the selection in the prompt. + {strong}[Alt] + [a] : {reset}Set an alarm which sends a notification when a modification is detected. (Ring on regexp match with [Shift]) + {strong}[Alt] + [s] : {reset}Open theme selection prompt. Use [Alt] + [Shift] + [s] to refresh current theme. + {strong}[Alt] + [e] : {reset}List open user sessions. (Only available in secure mode) {strong}[Alt] + [z] : {reset}Escape: don't catch the next pressed key. Useful for using native search for example. ([Alt] + [z] then [Ctrl] + [f]). diff --git a/butterfly/routes.py b/butterfly/routes.py index b5db666..219ac31 100644 --- a/butterfly/routes.py +++ b/butterfly/routes.py @@ -291,9 +291,10 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler): sys.exit(0) -@url(r'/sessions') -class Sessions(Route): - """List available sessions""" +@url(r'/sessions/list.json') +class SessionsList(Route): + """Get the theme list""" + def get(self): if tornado.options.options.unsecure: raise tornado.web.HTTPError(403) @@ -304,8 +305,12 @@ class Sessions(Route): if not user: raise tornado.web.HTTPError(403) - return self.render( - 'list.html', sessions=TermWebSocket.sessions.get(user, [])) + self.set_header('Content-Type', 'application/json') + self.write(tornado.escape.json_encode({ + 'sessions': sorted( + TermWebSocket.sessions.get(user, [])), + 'user': user + })) @url(r'/themes/list.json') diff --git a/butterfly/sass/_layout.sass b/butterfly/sass/_layout.sass index 85505a5..e6a84df 100644 --- a/butterfly/sass/_layout.sass +++ b/butterfly/sass/_layout.sass @@ -49,14 +49,14 @@ body width: 100% height: 100% - form + form, > div padding: 1.5em background: $popup-bg color: $popup-fg font-size: $popup-fs h2 - margin: .5em + margin: 0 .5em .5em .5em select min-width: 300px padding: .5em diff --git a/butterfly/static/ext.js b/butterfly/static/ext.js index a9ec851..8602cbb 100644 --- a/butterfly/static/ext.js +++ b/butterfly/static/ext.js @@ -529,6 +529,36 @@ return sel.modify('extend', 'forward', 'character'); }); + document.addEventListener('keydown', function(e) { + var oReq; + if (!(e.altKey && e.keyCode === 69)) { + return true; + } + oReq = new XMLHttpRequest(); + oReq.addEventListener('load', function() { + var j, len1, out, ref, response, session; + response = JSON.parse(this.responseText); + out = '
'; + out += '

Session list

'; + if (response.sessions.length === 0) { + out += "No current session for user " + response.user; + } else { + out += '
    '; + ref = response.sessions; + for (j = 0, len1 = ref.length; j < len1; j++) { + session = ref[j]; + out += "
  • " + session + "
  • "; + } + out += '
'; + } + out += '
'; + return popup.open(out); + }); + oReq.open("GET", "/sessions/list.json"); + oReq.send(); + return cancel(e); + }); + _set_theme_href = function(href) { var img; document.getElementById('style').setAttribute('href', href); @@ -557,8 +587,6 @@ } }; - document.addEventListener('keydown', function(e) {}); - document.addEventListener('keydown', function(e) { var oReq, style; if (!(e.altKey && e.keyCode === 83)) { diff --git a/butterfly/static/ext.min.js b/butterfly/static/ext.min.js index 3b2e081..d6dac3c 100644 --- a/butterfly/static/ext.min.js +++ b/butterfly/static/ext.min.js @@ -1,4 +1,4 @@ /*! butterfly 2015-10-08 */ -(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};g=function(a){var b,c,d,e;if(a.indexOf("")<0)return a;for(c=-1,d="",e="normal";c=0&&c++,e="normal";break;case"csi":if("?>!$\" '".indexOf(b)>=0)break;if(b>="0"&&"9">=b)break;if(";"===b)break;e="normal";break;case"osc":(""===b||""===b)&&(""===b&&c++,e="normal")}return d},o=function(a,b){var c;return c=function(d){var e,f,h;return e=g(d.data),console.log(e),null===b||b.test(e)?(butterfly.body.classList.remove("alarm"),f="Butterfly ["+butterfly.title+"]",a?(h=new Notification(f,{body:e,icon:"/static/images/favicon.png"}),h.onclick=function(){return window.focus(),h.close()}):alert(f+"\n"+e),butterfly.ws.removeEventListener("message",c)):void 0},butterfly.ws.addEventListener("message",c),butterfly.body.classList.add("alarm")},f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},document.addEventListener("keydown",function(a){var b;if(!a.altKey||65!==a.keyCode)return!0;if(b=null,a.shiftKey){if(b=prompt("Ring alarm when encountering the following text: (can be a regexp)"),!b)return;b=new RegExp(b)}return Notification&&"default"===Notification.permission?Notification.requestPermission(function(){return o("granted"===Notification.permission,b)}):o("granted"===Notification.permission,b),f(a)}),addEventListener("copy",h=function(a){var b,c,d,e,f,g,h;for(butterfly.bell("copied"),a.clipboardData.clearData(),h=getSelection().toString().replace(/\u00A0/g," ").replace(/\u2007/g," "),b="",g=h.split("\n"),d=0,e=g.length;e>d;d++)f=g[d],"⏎"===f.slice(-1)?(c="",f=f.slice(0,-1)):c="\n",b+=f.replace(/\s*$/,"")+c;return a.clipboardData.setData("text/plain",b.slice(0,-1)),a.preventDefault()}),addEventListener("paste",function(a){var b;return butterfly.bell("pasted"),b=a.clipboardData.getData("text/plain"),b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r"),butterfly.send(b),a.preventDefault()}),addEventListener("beforeunload",function(a){return butterfly.body.classList.contains("dead")||location.href.indexOf("session")>-1?void 0:a.returnValue="This terminal is active and not in session. Are you sure you want to kill it?"}),a=function(){function a(){this.el=document.getElementById("popup"),this.bound_click_maybe_close=this.click_maybe_close.bind(this),this.bound_key_maybe_close=this.key_maybe_close.bind(this)}return a.prototype.open=function(a){return this.el.innerHTML=a,this.el.classList.remove("hidden"),addEventListener("click",this.bound_click_maybe_close),addEventListener("keydown",this.bound_key_maybe_close)},a.prototype.close=function(){return removeEventListener("click",this.bound_click_maybe_close),removeEventListener("keydown",this.bound_key_maybe_close),this.el.classList.add("hidden"),this.el.innerHTML=""},a.prototype.click_maybe_close=function(a){var b;for(b=a.target;b.parentElement;){if(Array.prototype.slice.call(this.el.children).indexOf(b)>-1)return!0;b=b.parentElement}return this.close(),f(a)},a.prototype.key_maybe_close=function(a){return 27!==a.keyCode?!0:(this.close(),f(a))},a}(),l=new a,n=null,f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},m=function(a){var b;for(b=a.previousSibling,b||(b=a.parentNode.previousSibling),b||(b=a.parentNode.parentNode.previousSibling);b.lastChild;)b=b.lastChild;return b},k=function(a){var b;for(b=a.nextSibling,b||(b=a.parentNode.nextSibling),b||(b=a.parentNode.parentNode.nextSibling);null!=b?b.firstChild:void 0;)b=b.firstChild;return b},b=function(){function a(){butterfly.body.classList.add("selection"),this.selection=getSelection()}return a.prototype.reset=function(){var a,b,c;for(this.selection=getSelection(),a=document.createRange(),a.setStart(this.selection.anchorNode,this.selection.anchorOffset),a.setEnd(this.selection.focusNode,this.selection.focusOffset),this.start={node:this.selection.anchorNode,offset:this.selection.anchorOffset},this.end={node:this.selection.focusNode,offset:this.selection.focusOffset},a.collapsed&&(b=[this.end,this.start],this.start=b[0],this.end=b[1]),this.startLine=this.start.node;!this.startLine.classList||q.call(this.startLine.classList,"line")<0;)this.startLine=this.startLine.parentNode;for(this.endLine=this.end.node,c=[];!this.endLine.classList||q.call(this.endLine.classList,"line")<0;)c.push(this.endLine=this.endLine.parentNode);return c},a.prototype.clear=function(){return this.selection.removeAllRanges()},a.prototype.destroy=function(){return butterfly.body.classList.remove("selection"),this.clear()},a.prototype.text=function(){return this.selection.toString().replace(/\u00A0/g," ").replace(/\u2007/g," ")},a.prototype.up=function(){return this.go(-1)},a.prototype.down=function(){return this.go(1)},a.prototype.go=function(a){var b;if(b=butterfly.children.indexOf(this.startLine)+a,b>=0&&b=0&&b0;)if(f[--d].match(b))return{node:e,offset:d+1};e=m(e),f=null!=e?e.textContent:void 0,d=f.length}else for(;e;){for(;d=0)return!0;if(a.shiftKey&&13===a.keyCode&&!n&&!getSelection().isCollapsed)return butterfly.send(getSelection().toString()),getSelection().removeAllRanges(),f(a);if(n){if(n.reset(),!a.ctrlKey&&a.shiftKey&&37<=(d=a.keyCode)&&40>=d)return!0;if(a.shiftKey&&a.ctrlKey)38===a.keyCode?n.up():40===a.keyCode&&n.down();else if(39===a.keyCode)n.shrinkLeft();else if(38===a.keyCode)n.expandLeft();else if(37===a.keyCode)n.shrinkRight();else{if(40!==a.keyCode)return f(a);n.expandRight()}return null!=n&&n.apply(),f(a)}return!n&&a.ctrlKey&&a.shiftKey&&38===a.keyCode?(n=new b,n.selectLine(butterfly.y-1),n.apply(),f(a)):!0}),document.addEventListener("keyup",function(a){var b,c;if(b=a.keyCode,q.call([16,17,18,19],b)>=0)return!0;if(n){if(13===a.keyCode)return butterfly.send(n.text()),n.destroy(),n=null,f(a);if(c=a.keyCode,q.call([37,38,39,40],c)<0)return n.destroy(),n=null,!0}return!0}),document.addEventListener("dblclick",function(a){var b,c,d,e,f;if(!(a.ctrlKey||a.altkey||(f=getSelection(),f.isCollapsed||f.toString().match(/\s/)))){for(e=document.createRange(),e.setStart(f.anchorNode,f.anchorOffset),e.setEnd(f.focusNode,f.focusOffset),e.collapsed&&(f.removeAllRanges(),d=document.createRange(),d.setStart(f.focusNode,f.focusOffset),d.setEnd(f.anchorNode,f.anchorOffset),f.addRange(d));!f.toString().match(/\s/)&&f.toString();)f.modify("extend","forward","character");for(f.modify("extend","backward","character"),b=f.anchorNode,c=f.anchorOffset,f.collapseToEnd(),f.extend(b,c);!f.toString().match(/\s/)&&f.toString();)f.modify("extend","backward","character");return f.modify("extend","forward","character")}}),c=function(a){var b;return document.getElementById("style").setAttribute("href",a),b=document.createElement("img"),b.onerror=function(){return setTimeout(function(){return"undefined"!=typeof butterfly&&null!==butterfly?butterfly.resize():void 0},50)},b.src=a},d="undefined"!=typeof localStorage&&null!==localStorage?localStorage.getItem("theme"):void 0,d&&c(d),this.set_theme=function(a){return d=a,"undefined"!=typeof localStorage&&null!==localStorage&&localStorage.setItem("theme",a),a?c(a):void 0},document.addEventListener("keydown",function(a){}),document.addEventListener("keydown",function(a){var b,e;return a.altKey&&83===a.keyCode?a.shiftKey?(e=document.getElementById("style").getAttribute("href"),e=e.split("?")[0],c(e+"?"+(new Date).getTime()),f(a)):(b=new XMLHttpRequest,b.addEventListener("load",function(){var a,b,c,e,f,g,h,i,j;if(f=JSON.parse(this.responseText),i=f.themes,0===i.length)return void alert("No themes found in "+f.dir+".\n Please install themes with butterfly.server.py --install-themes");for(a='
\n

Pick a theme:

\n \n \n
",l.open(a),h=document.getElementById("theme_list"),h.addEventListener("change",function(){return set_theme(h.value)})}),b.open("GET","/themes/list.json"),b.send(),f(a)):!0}),/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)&&(i=!1,e=!1,j=!0,p=document.createElement("input"),p.type="password",p.style.position="fixed",p.style.top=0,p.style.left=0,p.style.border="none",p.style.outline="none",p.style.opacity=0,p.value="0",document.body.appendChild(p),p.addEventListener("blur",function(){return setTimeout(function(a){return function(){return a.focus()}}(this),10)}),addEventListener("click",function(){return p.focus()}),addEventListener("touchstart",function(a){return 2===a.touches.length?i=!0:3===a.touches.length?(i=!1,e=!0):4===a.touches.length?(i=!0,e=!0):void 0}),p.addEventListener("keydown",function(a){return butterfly.keyDown(a),!0}),p.addEventListener("input",function(a){var b;return b=this.value.length,0===b?(a.keyCode=8,butterfly.keyDown(a),this.value="0",!0):(a.keyCode=this.value.charAt(1).charCodeAt(0),!i&&!e||j?(butterfly.keyPress(a),j=!1,this.value="0",!0):(a.keyCode=this.value.charAt(1).charCodeAt(0),a.ctrlKey=i,a.altKey=e,a.keyCode>=97&&a.keyCode<=122&&(a.keyCode-=32),butterfly.keyDown(a),this.value="0",i=e=!1,!0))}))}).call(this); +(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};g=function(a){var b,c,d,e;if(a.indexOf("")<0)return a;for(c=-1,d="",e="normal";c=0&&c++,e="normal";break;case"csi":if("?>!$\" '".indexOf(b)>=0)break;if(b>="0"&&"9">=b)break;if(";"===b)break;e="normal";break;case"osc":(""===b||""===b)&&(""===b&&c++,e="normal")}return d},o=function(a,b){var c;return c=function(d){var e,f,h;return e=g(d.data),console.log(e),null===b||b.test(e)?(butterfly.body.classList.remove("alarm"),f="Butterfly ["+butterfly.title+"]",a?(h=new Notification(f,{body:e,icon:"/static/images/favicon.png"}),h.onclick=function(){return window.focus(),h.close()}):alert(f+"\n"+e),butterfly.ws.removeEventListener("message",c)):void 0},butterfly.ws.addEventListener("message",c),butterfly.body.classList.add("alarm")},f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},document.addEventListener("keydown",function(a){var b;if(!a.altKey||65!==a.keyCode)return!0;if(b=null,a.shiftKey){if(b=prompt("Ring alarm when encountering the following text: (can be a regexp)"),!b)return;b=new RegExp(b)}return Notification&&"default"===Notification.permission?Notification.requestPermission(function(){return o("granted"===Notification.permission,b)}):o("granted"===Notification.permission,b),f(a)}),addEventListener("copy",h=function(a){var b,c,d,e,f,g,h;for(butterfly.bell("copied"),a.clipboardData.clearData(),h=getSelection().toString().replace(/\u00A0/g," ").replace(/\u2007/g," "),b="",g=h.split("\n"),d=0,e=g.length;e>d;d++)f=g[d],"⏎"===f.slice(-1)?(c="",f=f.slice(0,-1)):c="\n",b+=f.replace(/\s*$/,"")+c;return a.clipboardData.setData("text/plain",b.slice(0,-1)),a.preventDefault()}),addEventListener("paste",function(a){var b;return butterfly.bell("pasted"),b=a.clipboardData.getData("text/plain"),b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r"),butterfly.send(b),a.preventDefault()}),addEventListener("beforeunload",function(a){return butterfly.body.classList.contains("dead")||location.href.indexOf("session")>-1?void 0:a.returnValue="This terminal is active and not in session. Are you sure you want to kill it?"}),a=function(){function a(){this.el=document.getElementById("popup"),this.bound_click_maybe_close=this.click_maybe_close.bind(this),this.bound_key_maybe_close=this.key_maybe_close.bind(this)}return a.prototype.open=function(a){return this.el.innerHTML=a,this.el.classList.remove("hidden"),addEventListener("click",this.bound_click_maybe_close),addEventListener("keydown",this.bound_key_maybe_close)},a.prototype.close=function(){return removeEventListener("click",this.bound_click_maybe_close),removeEventListener("keydown",this.bound_key_maybe_close),this.el.classList.add("hidden"),this.el.innerHTML=""},a.prototype.click_maybe_close=function(a){var b;for(b=a.target;b.parentElement;){if(Array.prototype.slice.call(this.el.children).indexOf(b)>-1)return!0;b=b.parentElement}return this.close(),f(a)},a.prototype.key_maybe_close=function(a){return 27!==a.keyCode?!0:(this.close(),f(a))},a}(),l=new a,n=null,f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},m=function(a){var b;for(b=a.previousSibling,b||(b=a.parentNode.previousSibling),b||(b=a.parentNode.parentNode.previousSibling);b.lastChild;)b=b.lastChild;return b},k=function(a){var b;for(b=a.nextSibling,b||(b=a.parentNode.nextSibling),b||(b=a.parentNode.parentNode.nextSibling);null!=b?b.firstChild:void 0;)b=b.firstChild;return b},b=function(){function a(){butterfly.body.classList.add("selection"),this.selection=getSelection()}return a.prototype.reset=function(){var a,b,c;for(this.selection=getSelection(),a=document.createRange(),a.setStart(this.selection.anchorNode,this.selection.anchorOffset),a.setEnd(this.selection.focusNode,this.selection.focusOffset),this.start={node:this.selection.anchorNode,offset:this.selection.anchorOffset},this.end={node:this.selection.focusNode,offset:this.selection.focusOffset},a.collapsed&&(b=[this.end,this.start],this.start=b[0],this.end=b[1]),this.startLine=this.start.node;!this.startLine.classList||q.call(this.startLine.classList,"line")<0;)this.startLine=this.startLine.parentNode;for(this.endLine=this.end.node,c=[];!this.endLine.classList||q.call(this.endLine.classList,"line")<0;)c.push(this.endLine=this.endLine.parentNode);return c},a.prototype.clear=function(){return this.selection.removeAllRanges()},a.prototype.destroy=function(){return butterfly.body.classList.remove("selection"),this.clear()},a.prototype.text=function(){return this.selection.toString().replace(/\u00A0/g," ").replace(/\u2007/g," ")},a.prototype.up=function(){return this.go(-1)},a.prototype.down=function(){return this.go(1)},a.prototype.go=function(a){var b;if(b=butterfly.children.indexOf(this.startLine)+a,b>=0&&b=0&&b0;)if(f[--d].match(b))return{node:e,offset:d+1};e=m(e),f=null!=e?e.textContent:void 0,d=f.length}else for(;e;){for(;d=0)return!0;if(a.shiftKey&&13===a.keyCode&&!n&&!getSelection().isCollapsed)return butterfly.send(getSelection().toString()),getSelection().removeAllRanges(),f(a);if(n){if(n.reset(),!a.ctrlKey&&a.shiftKey&&37<=(d=a.keyCode)&&40>=d)return!0;if(a.shiftKey&&a.ctrlKey)38===a.keyCode?n.up():40===a.keyCode&&n.down();else if(39===a.keyCode)n.shrinkLeft();else if(38===a.keyCode)n.expandLeft();else if(37===a.keyCode)n.shrinkRight();else{if(40!==a.keyCode)return f(a);n.expandRight()}return null!=n&&n.apply(),f(a)}return!n&&a.ctrlKey&&a.shiftKey&&38===a.keyCode?(n=new b,n.selectLine(butterfly.y-1),n.apply(),f(a)):!0}),document.addEventListener("keyup",function(a){var b,c;if(b=a.keyCode,q.call([16,17,18,19],b)>=0)return!0;if(n){if(13===a.keyCode)return butterfly.send(n.text()),n.destroy(),n=null,f(a);if(c=a.keyCode,q.call([37,38,39,40],c)<0)return n.destroy(),n=null,!0}return!0}),document.addEventListener("dblclick",function(a){var b,c,d,e,f;if(!(a.ctrlKey||a.altkey||(f=getSelection(),f.isCollapsed||f.toString().match(/\s/)))){for(e=document.createRange(),e.setStart(f.anchorNode,f.anchorOffset),e.setEnd(f.focusNode,f.focusOffset),e.collapsed&&(f.removeAllRanges(),d=document.createRange(),d.setStart(f.focusNode,f.focusOffset),d.setEnd(f.anchorNode,f.anchorOffset),f.addRange(d));!f.toString().match(/\s/)&&f.toString();)f.modify("extend","forward","character");for(f.modify("extend","backward","character"),b=f.anchorNode,c=f.anchorOffset,f.collapseToEnd(),f.extend(b,c);!f.toString().match(/\s/)&&f.toString();)f.modify("extend","backward","character");return f.modify("extend","forward","character")}}),document.addEventListener("keydown",function(a){var b;return a.altKey&&69===a.keyCode?(b=new XMLHttpRequest,b.addEventListener("load",function(){var a,b,c,d,e,f;if(e=JSON.parse(this.responseText),c="
",c+="

Session list

",0===e.sessions.length)c+="No current session for user "+e.user;else{for(c+="
    ",d=e.sessions,a=0,b=d.length;b>a;a++)f=d[a],c+='
  • '+f+"
  • ";c+="
"}return c+="
",l.open(c)}),b.open("GET","/sessions/list.json"),b.send(),f(a)):!0}),c=function(a){var b;return document.getElementById("style").setAttribute("href",a),b=document.createElement("img"),b.onerror=function(){return setTimeout(function(){return"undefined"!=typeof butterfly&&null!==butterfly?butterfly.resize():void 0},50)},b.src=a},d="undefined"!=typeof localStorage&&null!==localStorage?localStorage.getItem("theme"):void 0,d&&c(d),this.set_theme=function(a){return d=a,"undefined"!=typeof localStorage&&null!==localStorage&&localStorage.setItem("theme",a),a?c(a):void 0},document.addEventListener("keydown",function(a){var b,e;return a.altKey&&83===a.keyCode?a.shiftKey?(e=document.getElementById("style").getAttribute("href"),e=e.split("?")[0],c(e+"?"+(new Date).getTime()),f(a)):(b=new XMLHttpRequest,b.addEventListener("load",function(){var a,b,c,e,f,g,h,i,j;if(f=JSON.parse(this.responseText),i=f.themes,0===i.length)return void alert("No themes found in "+f.dir+".\n Please install themes with butterfly.server.py --install-themes");for(a='
\n

Pick a theme:

\n \n \n
",l.open(a),h=document.getElementById("theme_list"),h.addEventListener("change",function(){return set_theme(h.value)})}),b.open("GET","/themes/list.json"),b.send(),f(a)):!0}),/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)&&(i=!1,e=!1,j=!0,p=document.createElement("input"),p.type="password",p.style.position="fixed",p.style.top=0,p.style.left=0,p.style.border="none",p.style.outline="none",p.style.opacity=0,p.value="0",document.body.appendChild(p),p.addEventListener("blur",function(){return setTimeout(function(a){return function(){return a.focus()}}(this),10)}),addEventListener("click",function(){return p.focus()}),addEventListener("touchstart",function(a){return 2===a.touches.length?i=!0:3===a.touches.length?(i=!1,e=!0):4===a.touches.length?(i=!0,e=!0):void 0}),p.addEventListener("keydown",function(a){return butterfly.keyDown(a),!0}),p.addEventListener("input",function(a){var b;return b=this.value.length,0===b?(a.keyCode=8,butterfly.keyDown(a),this.value="0",!0):(a.keyCode=this.value.charAt(1).charCodeAt(0),!i&&!e||j?(butterfly.keyPress(a),j=!1,this.value="0",!0):(a.keyCode=this.value.charAt(1).charCodeAt(0),a.ctrlKey=i,a.altKey=e,a.keyCode>=97&&a.keyCode<=122&&(a.keyCode-=32),butterfly.keyDown(a),this.value="0",i=e=!1,!0))}))}).call(this); //# sourceMappingURL=ext.min.js.map \ No newline at end of file diff --git a/butterfly/static/main.css b/butterfly/static/main.css index afb4f77..00864a0 100644 --- a/butterfly/static/main.css +++ b/butterfly/static/main.css @@ -2831,18 +2831,18 @@ body { justify-content: center; width: 100%; height: 100%; } - body #popup form { + body #popup form, body #popup > div { padding: 1.5em; background: rgba(127, 127, 127, 0.5); color: #f4ead5; font-size: 1em; } - body #popup form h2 { - margin: .5em; } - body #popup form select { + body #popup form h2, body #popup > div h2 { + margin: 0 0.5em 0.5em 0.5em; } + body #popup form select, body #popup > div select { min-width: 300px; padding: .5em; width: 100%; } - body #popup form label { + body #popup form label, body #popup > div label { display: block; padding: .5em; font-size: .75em; } diff --git a/butterfly/templates/list.html b/butterfly/templates/list.html deleted file mode 100644 index e6a79dd..0000000 --- a/butterfly/templates/list.html +++ /dev/null @@ -1,24 +0,0 @@ - -{% from tornado.options import options %} - - - - - - - - - - Butterfly - - - - -

Currently open butterfly sessions :

- - - diff --git a/coffees/ext/sessions.coffee b/coffees/ext/sessions.coffee new file mode 100644 index 0000000..753117d --- /dev/null +++ b/coffees/ext/sessions.coffee @@ -0,0 +1,22 @@ +document.addEventListener 'keydown', (e) -> + return true unless e.altKey and e.keyCode is 69 + oReq = new XMLHttpRequest() + oReq.addEventListener 'load', -> + response = JSON.parse(@responseText) + out = '
' + out += '

Session list

' + if response.sessions.length is 0 + out += "No current session for user #{response.user}" + else + out += '
    ' + for session in response.sessions + out += "
  • #{session}
  • " + out += '
' + + out += '
' + + popup.open out + + oReq.open("GET", "/sessions/list.json") + oReq.send() + cancel e diff --git a/coffees/ext/theme.coffee b/coffees/ext/theme.coffee index 5bcb0c7..57cf10c 100644 --- a/coffees/ext/theme.coffee +++ b/coffees/ext/theme.coffee @@ -13,8 +13,6 @@ _set_theme_href(_theme) if _theme localStorage?.setItem('theme', theme) _set_theme_href(theme) if theme -document.addEventListener 'keydown', (e) -> - document.addEventListener 'keydown', (e) -> return true unless e.altKey and e.keyCode is 83 if e.shiftKey