powerline/scripts/powerline-render
Kim Silkebækken a122e73b9b Add files from @kovidgoyal's powerline-daemon repo
Minor changes have been applied:

- Removed copyright info and GPL 3 license since Powerline is MIT (needs
  confirmation from kovidgoyal before merge)
- The `powerline-client` script is renamed to `powerline`, and calls the
  daemon or `powerline-render` (the previous `powerline`) to render
  a statusline
- Minor coding style corrections to match the rest of the project
- Python 3 support is removed for now due to setuptools failing with
  binary scripts

Todo:

- Automatically attempt to launch powerline-daemon the first time
  powerline is run if the daemon isn't already running?
- pip install -e fails with binary files (it appears that pip recodes
  the powerline binary to ASCII, the compiled powerline script must be
  copied manually to ~/.local/bin after pip install -e has been run)
2014-08-02 18:45:18 +04:00

44 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
'''Powerline prompt and statusline script.'''
import sys
import os
try:
from powerline.shell import ShellPowerline, get_argparser, finish_args
except ImportError:
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(__file__)))))
from powerline.shell import ShellPowerline, get_argparser, finish_args # NOQA
def write(output):
try:
sys.stdout.write(output)
except UnicodeEncodeError:
sys.stdout.write(output.encode('utf-8'))
if __name__ == '__main__':
args = get_argparser(description=__doc__).parse_args()
finish_args(args)
powerline = ShellPowerline(args, run_once=True)
segment_info = {'args': args, 'environ': os.environ}
if args.renderer_arg:
segment_info.update(args.renderer_arg)
if args.side.startswith('above'):
for line in powerline.render_above_lines(
width=args.width,
segment_info=segment_info,
mode=os.environ.get('_POWERLINE_MODE'),
):
write(line)
sys.stdout.write('\n')
args.side = args.side[len('above'):]
if args.side:
rendered = powerline.render(
width=args.width,
side=args.side,
segment_info=segment_info,
mode=os.environ.get('_POWERLINE_MODE'),
)
write(rendered)