コード例 #1
0
ファイル: cat.py プロジェクト: abandonrules/butterfly
import mimetypes
import os
import subprocess
import sys

from butterfly.escapes import image

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])
コード例 #2
0
ファイル: cat.py プロジェクト: yusronarif/butterfly
import mimetypes
import subprocess
from butterfly.escapes import image
import argparse

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])
コード例 #3
0
ファイル: help.py プロジェクト: zzhgithub/butterfly
#!/usr/bin/env python
import base64
import os
import subprocess

import butterfly
from butterfly.escapes import image
from butterfly.utils import ansi_colors

print(ansi_colors.white + "Welcome to the butterfly help." + ansi_colors.reset)
path = os.getenv('BUTTERFLY_PATH')
if path:
    path = os.path.join(path, '../static/images/favicon.png')

if path and os.path.exists(path):
    with image('image/png'):
        with open(path, 'rb') as i:
            print(base64.b64encode(i.read()).decode('ascii'))
print("""
Butterfly is a xterm compliant terminal built with python and javascript.

{title}Terminal functionalities:{reset}
  {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] + [o]             : {reset}Open new terminal (As a popup)
  {strong}[Alt] + [z]             : {reset}Escape: don't catch the next pressed key.
                            Useful for using native search for example. ([Alt] + [z] then [Ctrl] + [f]).
コード例 #4
0
ファイル: help.py プロジェクト: Acidburn0zzz/butterfly
#!/usr/bin/env python
from butterfly.escapes import image
from butterfly.utils import ansi_colors
import os
import base64
import shutil

print(ansi_colors.white + "Welcome to the butterfly help." + ansi_colors.reset)
path = os.getenv('BUTTERFLY_PATH')
if path:
    path = os.path.join(path, '../static/images/favicon.png')

if path and os.path.exists(path):
    with image('image/png'):
        with open(path, 'rb') as i:
            print(base64.b64encode(i.read()).decode('ascii'))
print("""
Butterfly is a xterm compliant terminal built with python and javascript.

{title}Terminal functionalities:{reset}
  {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] + [o]             : {reset}Open new terminal (As a popup)
  {strong}[Alt] + [z]             : {reset}Escape: don't catch the next pressed key.
                            Useful for using native search for example. ([Alt] + [z] then [Ctrl] + [f]).