Style fix, new font (with bold). This now should work in firefox

This commit is contained in:
Florian Mounier
2014-01-24 11:52:15 +01:00
parent 92408c8f8f
commit 9b53ea67e6
18 changed files with 1265 additions and 1099 deletions

View File

@@ -1,35 +1,25 @@
import pty
import os
import io
import sys
import struct
import fcntl
import mimetypes
import termios
import tornado.websocket
import tornado.process
import tornado.ioloop
from subprocess import Popen
import tornado.options
from app import url, Route
ioloop = tornado.ioloop.IOLoop.instance()
@url(r'/')
@url(r'/(?:(wd/.+))?')
class Index(Route):
def get(self):
def get(self, path):
return self.render('index.html')
@url(r'/file/(.+)')
class File(Route):
def get(self, file):
self.add_header('Content-Type', mimetypes.guess_type(file)[0])
with open(file, 'rb') as fd:
self.write(fd.read())
@url(r'/ws')
@url(r'/ws(?:(/.+))?')
class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
def pty(self):
@@ -44,13 +34,16 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
env["TERM"] = "xterm-256color"
env["COLORTERM"] = "wsterm"
command = os.getenv('SHELL')
env["LOCATION"] = "http://%s:%d/" % (
tornado.options.options.host, tornado.options.options.port)
env["WSTERMDIR"] = os.getcwd()
env["SHELL"] = command
env["PATH"] = "%s:%s" % (
os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', 'bin')), env["PATH"])
p = Popen(command, env=env)
p.wait()
sys.exit(0)
os.chdir(self.path or os.path.expanduser("~"))
os.execvpe(command, [''], env)
else:
self.log.debug('Adding handler')
fcntl.fcntl(self.fd, fcntl.F_SETFL, os.O_NONBLOCK)
@@ -76,9 +69,10 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
)
ioloop.add_handler(self.fd, self.shell, ioloop.READ | ioloop.ERROR)
def open(self):
def open(self, path):
self.log.info('Websocket opened')
self.set_nodelay(True)
self.path = path
self.pty()
def on_message(self, message):
@@ -108,14 +102,24 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
if events & ioloop.ERROR:
self.log.info('Closing due to ioloop fd handler error')
ioloop.remove_handler(self.fd)
# Terminated
self.close()
def on_close(self):
if self.pid == 0:
return
self.writer.write('')
self.writer.flush()
os.close(self.fd)
os.waitpid(self.pid, 0)
try:
self.writer.write('')
self.writer.flush()
except OSError:
pass
try:
os.close(self.fd)
except OSError:
pass
try:
os.waitpid(self.pid, 0)
except OSError:
pass
self.log.info('Websocket closed')

View File

@@ -2,8 +2,10 @@ term = ws = null
cols = rows = null
$ ->
ws = new WebSocket 'ws://' + document.location.host + '/ws'
ws_url = 'ws://' + document.location.host + '/ws'
if location.pathname.indexOf('/wd') == 0
ws_url += location.pathname.slice 3
ws = new WebSocket ws_url
ws.onopen = ->
console.log "WebSocket open", arguments
term = new Terminal(
@@ -36,16 +38,18 @@ $ ->
$(window).resize ->
$main = $('main')
$termtest = $('<div>').addClass('terminal')
$test = $('<div>').css(display: 'inline').text('0123456789')
$test = $('<div>').text('0123456789')
$termtest.append($test)
$main.append($termtest)
ew = $test.outerWidth() / 10
eh = $test.outerHeight()
$test.css(display: 'inline-block')
ew = $test.outerWidth() / 10
$termtest.remove()
w = $main.outerWidth()
h = $main.outerHeight()
cols = Math.floor(w / ew) - 1
rows = Math.floor(h / eh) - 1
cols = Math.floor(w / ew)
rows = Math.floor(h / eh)
console.log "Computed #{cols} cols and #{rows} rows from main size #{w}, #{h} and div #{ew}, #{eh}"
term.resize cols, rows
ws.send "RS|#{cols},#{rows}"

View File

@@ -1,5 +1,6 @@
http_path = "/"
http_path = "/static/"
css_dir = "stylesheets"
fonts_dir = "fonts"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"

View File

@@ -0,0 +1,43 @@
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -6,7 +6,12 @@ term = ws = null;
cols = rows = null;
$(function() {
ws = new WebSocket('ws://' + document.location.host + '/ws');
var ws_url;
ws_url = 'ws://' + document.location.host + '/ws';
if (location.pathname.indexOf('/wd') === 0) {
ws_url += location.pathname.slice(3);
}
ws = new WebSocket(ws_url);
ws.onopen = function() {
console.log("WebSocket open", arguments);
term = new Terminal({
@@ -41,18 +46,20 @@ $(function() {
var $main, $termtest, $test, eh, ew, h, w;
$main = $('main');
$termtest = $('<div>').addClass('terminal');
$test = $('<div>').css({
display: 'inline'
}).text('0123456789');
$test = $('<div>').text('0123456789');
$termtest.append($test);
$main.append($termtest);
ew = $test.outerWidth() / 10;
eh = $test.outerHeight();
$test.css({
display: 'inline-block'
});
ew = $test.outerWidth() / 10;
$termtest.remove();
w = $main.outerWidth();
h = $main.outerHeight();
cols = Math.floor(w / ew) - 1;
rows = Math.floor(h / eh) - 1;
cols = Math.floor(w / ew);
rows = Math.floor(h / eh);
console.log("Computed " + cols + " cols and " + rows + " rows from main size " + w + ", " + h + " and div " + ew + ", " + eh);
term.resize(cols, rows);
return ws.send("RS|" + cols + "," + rows);
});

View File

@@ -1,3 +1,13 @@
@import compass/css3
+font-face("SourceCodePro", font-files("SourceCodePro-ExtraLight.otf"), "", 100, normal)
+font-face("SourceCodePro", font-files("SourceCodePro-Light.otf"), "", 300, normal)
+font-face("SourceCodePro", font-files("SourceCodePro-Regular.otf"), "", 400, normal)
+font-face("SourceCodePro", font-files("SourceCodePro-Medium.otf"), "", 500, normal)
+font-face("SourceCodePro", font-files("SourceCodePro-Semibold.otf"), "", 600, normal)
+font-face("SourceCodePro", font-files("SourceCodePro-Bold.otf"), "", 700, normal)
+font-face("SourceCodePro", font-files("SourceCodePro-Black.otf"), "", 900, normal)
$bg: #110f13
$fg: #f4ead5
@@ -7,26 +17,35 @@ $shadow-alpha: .5
html, body
height: 100%
font-family: "SourceCodePro"
body
main
display: flex
height: 100%
flex-direction: column
background-color: black
overflow: hidden
white-space: nowrap
.terminal
/* margin: .5em
flex: 1
font-family: 'Droid Sans Mono', monospace
outline: none
background-color: $bg
color: $fg
text-shadow: 0 0 $shadow rgba($fg, $shadow-alpha)
.cursor
box-shadow: 0 0 $shadow rgba($fg, $shadow-alpha)
::selection
background-color: black
box-shadow: 0 0 10px inset white
::-moz-selection
background-color: black
box-shadow: 0 0 10px inset white
.cursor.reverse-video
box-shadow: 0 0 10px $fg
/* Terminal styles
.bold
@@ -41,7 +60,7 @@ body
.invisible
visibility: hidden
.reverse-video, .cursor
.reverse-video
color: $bg
background-color: $fg

File diff suppressed because it is too large Load Diff

29
bin/ils
View File

@@ -1,19 +1,34 @@
#!/usr/bin/env python
#Depends: pillow
#Broken: Too slow !
from PIL import Image
import os
import mimetypes
import base64
import io
print('\x1b]99;')
out = ''
i = 0
for f in os.listdir(os.getcwd()):
if 'image' in (mimetypes.guess_type(f)[0] or ''):
out += '<img src="/file/%s" alt="%s" width="100px" height="100px" />' % (
os.path.abspath(f), f)
i += 1
if i % 5 == 0:
out += '\n'
mime = mimetypes.guess_type(f)[0]
if 'image' in (mime or ''):
try:
im = Image.open(f)
im.thumbnail((100, 100), Image.ANTIALIAS)
buf = io.BytesIO()
im.save(buf, im.format)
buf.seek(0)
out += '<img src="data:%s;base64,%s" alt="%s" />' % (
mime,
base64.b64encode(buf.read()).decode('ascii'),
f)
i += 1
if i % 5 == 0:
out += '\n'
except:
pass
print(out)

4
bin/nt Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env python
import os
import webbrowser
webbrowser.open('%swd%s' % (os.getenv('LOCATION'), os.getcwd()))

View File

@@ -19,7 +19,7 @@ tornado.options.parse_command_line()
from logging import getLogger
for logger in ('tornado.access', 'tornado.application',
'tornado.general', 'wsterm'):
'tornado.general', 'wsterm'):
getLogger(logger).setLevel(10 if tornado.options.options.debug else 30)
log = getLogger('wsterm')