Add session list

This commit is contained in:
Florian Mounier
2015-10-08 12:56:56 +02:00
parent 7501aab797
commit 96606d2b0b
10 changed files with 75 additions and 45 deletions

View File

@@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '2.0.3'
__version__ = '2.0.5'
import os

View File

@@ -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] <<hold>> : {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]).

View File

@@ -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')

View File

@@ -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

View File

@@ -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 = '<div>';
out += '<h2>Session list</h2>';
if (response.sessions.length === 0) {
out += "No current session for user " + response.user;
} else {
out += '<ul>';
ref = response.sessions;
for (j = 0, len1 = ref.length; j < len1; j++) {
session = ref[j];
out += "<li><a href=\"/session/" + session + "\">" + session + "</a></li>";
}
out += '</ul>';
}
out += '</div>';
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)) {

File diff suppressed because one or more lines are too long

View File

@@ -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; }

View File

@@ -1,24 +0,0 @@
<!DOCTYPE html>
{% from tornado.options import options %}
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Butterfly - A web terminal based on websocket and tornado">
<meta name="author" content="Mounier Florian">
<link rel="shortcut icon" href="{{ static_url('images/favicon.png') }}">
<title>Butterfly</title>
<link href="/style.css" rel="stylesheet">
</head>
<body>
<h1>Currently open butterfly sessions :</h1>
<ul>
{% for session in sessions %}
<li><h2><a target="_blank" href="/session/{{ session }}">{{ session }}</a></h2></li>
{% end %}
</ul>
</body>
</html>

View File

@@ -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 = '<div>'
out += '<h2>Session list</h2>'
if response.sessions.length is 0
out += "No current session for user #{response.user}"
else
out += '<ul>'
for session in response.sessions
out += "<li><a href=\"/session/#{session}\">#{session}</a></li>"
out += '</ul>'
out += '</div>'
popup.open out
oReq.open("GET", "/sessions/list.json")
oReq.send()
cancel e

View File

@@ -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