Add some help and rewrite bcat

This commit is contained in:
Florian Mounier
2015-04-29 16:59:18 +02:00
parent 5bdcc8dd71
commit 2b5ea8dc9a
10 changed files with 62 additions and 68 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/env python
#!/usr/bin/env python
import sys
import os
rows, cols = map(int, os.popen('stty size', 'r').read().split())

View File

@@ -1,8 +1,32 @@
#!/usr/bin/env python
import sys
import os
import base64
import mimetypes
import subprocess
from butterfly.escapes import image
import argparse
with image():
with open(sys.argv[1], 'rb') as f:
print(base64.b64encode(f.read()).decode('ascii'))
parser = argparse.ArgumentParser(description='Butterfly cat wrapper.')
parser.add_argument('-o', action="store_true",
dest='original', help='Force original cat')
parser.add_argument(
'files', metavar='FILES', nargs='+',
help='Force original cat')
args, remaining = parser.parse_known_args()
if args.original:
os.execvp('/usr/bin/cat', remaining + args.files)
for file in args.files:
if (not os.path.exists(sys.argv[1])):
print('%s: No such file' % file)
else:
mime = mimetypes.guess_type(file)[0]
if mime and 'image' in mime:
with image(mime):
with open(file, 'rb') as f:
print(base64.b64encode(f.read()).decode('ascii'))
else:
subprocess.call(['cat'] + remaining + [file])

22
bin/butterfly_help Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env python
from butterfly.escapes import image
import os
import base64
print("Welcome to the butterfly help.")
with image('image/png'):
with open(
os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'../butterfly/static/images/favicon.png'), 'rb') as i:
print(base64.b64encode(i.read()).decode('ascii'))
print("""
Butterfly is a xterm compliant terminal built with python and javascript.
Terminal functionalities:
[Alt] + [a] : Set an alarm which sends a notification when a modification is detected.
[Ctrl] + [Shift] + [Up] : Trigger visual selection mode. Hitting [Enter] inserts the selection in the prompt.
[ScrollLock] : Lock the scrolling to the current position. Press again to release.
[Alt] + [z] : Escape: don't catch the next pressed key. Useful for using native search for example. ([Alt] + [z] then [Ctrl] + [f]).
[Ctrl] + [c] <<hold>> : Cut the output when [Ctrl] + [c] is not enough.
""")

32
bin/ils
View File

@@ -1,32 +0,0 @@
#!/usr/bin/env python
#Depends: pillow
#Broken: Too slow !
from PIL import Image
import os
import mimetypes
import base64
import io
print('\x1bP;HTML|')
out = ''
for f in os.listdir(os.getcwd()):
mime = mimetypes.guess_type(f)[0]
if 'image' in (mime or ''):
# try:
with open(f, 'rb') as buf:
# im = Image.open(f)
# im.thumbnail((100, 100), Image.ANTIALIAS)
# buf = io.BytesIO()
# im.save(buf, im.format)
# buf.seek(0)
out += '<img width="200" height="100" src="data:%s;base64,%s" alt="%s" />' % (
mime,
base64.b64encode(buf.read()).decode('ascii'),
f)
# except Exception:
# pass
print(out)
print('\x1bP')

View File

@@ -9,8 +9,8 @@ def html():
@contextmanager
def image():
print('\x1bP;IMAGE|')
def image(mime='image'):
print('\x1bP;IMAGE|%s;' % mime)
yield
print('\x1bP')

View File

@@ -71,6 +71,8 @@ B ` '
R Y Y AFrom:R
! ! G%sX
For more information type: $ butterfly_help
'''
.replace('G', '\x1b[3%d;1m' % (
1 if tornado.options.options.unsecure else 2))

View File

@@ -728,7 +728,7 @@
};
Terminal.prototype.write = function(data) {
var attr, c, ch, content, cs, i, k, l, len, line, m, num, pt, ref, ref1, ref2, ref3, type, valid;
var attr, b64, c, ch, content, cs, i, k, l, len, line, m, mime, num, pt, ref, ref1, ref2, ref3, ref4, type, valid;
i = 0;
l = data.length;
while (i < l) {
@@ -1178,8 +1178,9 @@
this.screen[this.y + this.shift][1] = true;
break;
case "IMAGE":
ref4 = content.split(';', 2), mime = ref4[0], b64 = ref4[1];
attr = this.cloneAttr(this.curAttr);
attr.html = "<img class=\"inline-image\" src=\"data:image;base64," + content + "\" />";
attr.html = "<img class=\"inline-image\" src=\"data:" + mime + ";base64," + b64 + "\" />";
this.screen[this.y + this.shift][0][this.x] = attr;
this.screen[this.y + this.shift][1] = true;
break;

File diff suppressed because one or more lines are too long

View File

@@ -1,24 +0,0 @@
document.addEventListener 'DOMContentLoaded', ->
return
req = null
butterfly.native_scroll_to = (scroll=-1) ->
e = butterfly.parent
cancelAnimationFrame req if req
if scroll is -1 or (
scroll > e.scrollHeight - e.getBoundingClientRect().height)
scroll = e.scrollHeight - e.getBoundingClientRect().height
diff = scroll - e.scrollTop
return if diff is 0
step = diff / 25
scroll_step = ->
if Math.abs(e.scrollTop - scroll) < Math.abs(step)
e.scrollTop = scroll
else
e.scrollTop += step
req = requestAnimationFrame scroll_step
req = requestAnimationFrame scroll_step

View File

@@ -1086,10 +1086,11 @@ class Terminal
@screen[@y + @shift][1] = true
when "IMAGE"
[mime, b64] = content.split(';', 2)
attr = @cloneAttr @curAttr
attr.html = (
"<img class=\"inline-image\" src=\"data:image;base64,#{
content}\" />")
"<img class=\"inline-image\" src=\"data:#{mime};base64,#{
b64}\" />")
@screen[@y + @shift][0][@x] = attr
@screen[@y + @shift][1] = true