#!/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)
with image('image/png'):
    with open(
            os.path.join(
                os.path.abspath(os.path.dirname(__file__)),
                '../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.

{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] + [z]             : {reset}Escape: don't catch the next pressed key.
                            Useful for using native search for example. ([Alt] + [z] then [Ctrl] + [f]).


{title}Butterfly programs:{reset}
  {strong}bcat     : {reset}A wrapper around cat allowing to display images as <img> instead of binary.
  {strong}bopen    : {reset}Open a new terminal at specified location.
  {strong}bsession : {reset}Open or rattach a butterfly session. Multiplexing is supported.
  {strong}b16M     : {reset}Test the 16M colors support in terminal.
  {strong}bhr      : {reset}Put a html hr. This is a test for html output.
  {strong}bcal     : {reset}Display current month using html. This is also a test for html output.


{title}Styling butterfly:{reset}
  To style butterfly in sass, you need to have the libsass python library installed.
  Install official themes with {code}butterfly.server.py --install-themes{reset}

  Theming is done by overiding the default sass files located in {code}{main}{reset} in a theme directory.
  This directory can include images and custom fonts.
  Please take a look at official themes here:  https://github.com/paradoxxxzero/butterfly-themes
  and submit your best themes as pull request!

  \x1b[{rcol}G\x1b[3m{dark}butterfly @ 2015 Mounier Florian{reset}\
""".format(
    title=ansi_colors.light_blue,
    dark=ansi_colors.light_black,
    strong=ansi_colors.white,
    code=ansi_colors.light_yellow,
    comment=ansi_colors.light_magenta,
    reset=ansi_colors.reset,
    rcol=shutil.get_terminal_size()[0] - 31,
    main=os.path.normpath(os.path.join(
                os.path.abspath(os.path.dirname(__file__)),
                '../sass/'))))
