powerline
This commit is contained in:
parent
eebe86231d
commit
9b94239841
0
.aliases.ps1
Executable file → Normal file
0
.aliases.ps1
Executable file → Normal file
0
.gitignore
vendored
Executable file → Normal file
0
.gitignore
vendored
Executable file → Normal file
0
.gitmodules
vendored
Executable file → Normal file
0
.gitmodules
vendored
Executable file → Normal file
0
.poshrc.ps1
Executable file → Normal file
0
.poshrc.ps1
Executable file → Normal file
0
.psrc.ps1
Executable file → Normal file
0
.psrc.ps1
Executable file → Normal file
0
.tmux/.tmux-powerlinerc
Executable file → Normal file
0
.tmux/.tmux-powerlinerc
Executable file → Normal file
0
htop/htoprc
Executable file → Normal file
0
htop/htoprc
Executable file → Normal file
0
micro/buffers/history
Executable file → Normal file
0
micro/buffers/history
Executable file → Normal file
0
micro/settings.json
Executable file → Normal file
0
micro/settings.json
Executable file → Normal file
0
neofetch/config.conf
Executable file → Normal file
0
neofetch/config.conf
Executable file → Normal file
BIN
powerline-bin/bin/powerline
Normal file
BIN
powerline-bin/bin/powerline
Normal file
Binary file not shown.
22
powerline-bin/bin/powerline-config
Normal file
22
powerline-bin/bin/powerline-config
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/opt/python/bin/python3
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from powerline.commands.config import get_argparser
|
||||||
|
except ImportError:
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(__file__)))))
|
||||||
|
from powerline.commands.config import get_argparser
|
||||||
|
|
||||||
|
import powerline.bindings.config as config
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = get_argparser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
pl = config.create_powerline_logger(args)
|
||||||
|
|
||||||
|
args.function(pl, args)
|
495
powerline-bin/bin/powerline-daemon
Normal file
495
powerline-bin/bin/powerline-daemon
Normal file
@ -0,0 +1,495 @@
|
|||||||
|
#!/opt/python/bin/python3
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import socket
|
||||||
|
import os
|
||||||
|
import errno
|
||||||
|
import sys
|
||||||
|
import fcntl
|
||||||
|
import atexit
|
||||||
|
import stat
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from select import select
|
||||||
|
from signal import signal, SIGTERM
|
||||||
|
from time import sleep
|
||||||
|
from functools import partial
|
||||||
|
from io import BytesIO
|
||||||
|
from threading import Event
|
||||||
|
from itertools import chain
|
||||||
|
from logging import StreamHandler
|
||||||
|
|
||||||
|
from powerline.shell import ShellPowerline
|
||||||
|
from powerline.commands.main import finish_args, write_output
|
||||||
|
from powerline.lib.monotonic import monotonic
|
||||||
|
from powerline.lib.encoding import get_preferred_output_encoding, get_preferred_arguments_encoding, get_unicode_writer
|
||||||
|
from powerline.bindings.wm import wm_threads
|
||||||
|
|
||||||
|
from powerline.commands.main import get_argparser as get_main_argparser
|
||||||
|
from powerline.commands.daemon import get_argparser as get_daemon_argparser
|
||||||
|
|
||||||
|
|
||||||
|
USE_FILESYSTEM = not sys.platform.lower().startswith('linux')
|
||||||
|
|
||||||
|
|
||||||
|
class NonInteractiveArgParser(ArgumentParser):
|
||||||
|
def print_usage(self, file=None):
|
||||||
|
raise Exception(self.format_usage())
|
||||||
|
|
||||||
|
def print_help(self, file=None):
|
||||||
|
raise Exception(self.format_help())
|
||||||
|
|
||||||
|
def exit(self, status=0, message=None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def error(self, message):
|
||||||
|
raise Exception(self.format_usage())
|
||||||
|
|
||||||
|
|
||||||
|
EOF = b'EOF\0\0'
|
||||||
|
|
||||||
|
|
||||||
|
class State(object):
|
||||||
|
__slots__ = ('powerlines', 'logger', 'config_loader', 'started_wm_threads',
|
||||||
|
'ts_shutdown_event')
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.logger = None
|
||||||
|
self.config_loader = None
|
||||||
|
self.started_wm_threads = {}
|
||||||
|
self.powerlines = {}
|
||||||
|
self.ts_shutdown_event = Event()
|
||||||
|
|
||||||
|
|
||||||
|
HOME = os.path.expanduser('~')
|
||||||
|
|
||||||
|
|
||||||
|
class NonDaemonShellPowerline(ShellPowerline):
|
||||||
|
def get_log_handler(self):
|
||||||
|
return StreamHandler()
|
||||||
|
|
||||||
|
|
||||||
|
def start_wm(args, environ, cwd, is_daemon, state):
|
||||||
|
wm_name = args.ext[0][3:]
|
||||||
|
if wm_name in state.started_wm_threads:
|
||||||
|
return b''
|
||||||
|
thread_shutdown_event = Event()
|
||||||
|
thread = wm_threads[wm_name](
|
||||||
|
thread_shutdown_event=thread_shutdown_event,
|
||||||
|
pl_shutdown_event=state.ts_shutdown_event,
|
||||||
|
pl_config_loader=state.config_loader,
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
state.started_wm_threads[wm_name] = (thread, thread_shutdown_event)
|
||||||
|
return b''
|
||||||
|
|
||||||
|
|
||||||
|
def render(args, environ, cwd, is_daemon, state):
|
||||||
|
segment_info = {
|
||||||
|
'getcwd': lambda: cwd,
|
||||||
|
'home': environ.get('HOME', HOME),
|
||||||
|
'environ': environ,
|
||||||
|
'args': args,
|
||||||
|
}
|
||||||
|
key = (
|
||||||
|
args.ext[0],
|
||||||
|
args.renderer_module,
|
||||||
|
tuple(args.config_override) if args.config_override else None,
|
||||||
|
tuple(args.theme_override) if args.theme_override else None,
|
||||||
|
tuple(args.config_path) if args.config_path else None,
|
||||||
|
environ.get('POWERLINE_THEME_OVERRIDES', ''),
|
||||||
|
environ.get('POWERLINE_CONFIG_OVERRIDES', ''),
|
||||||
|
environ.get('POWERLINE_CONFIG_PATHS', ''),
|
||||||
|
)
|
||||||
|
|
||||||
|
PowerlineClass = ShellPowerline if is_daemon else NonDaemonShellPowerline
|
||||||
|
powerline = None
|
||||||
|
try:
|
||||||
|
powerline = state.powerlines[key]
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
powerline = state.powerlines[key] = PowerlineClass(
|
||||||
|
args,
|
||||||
|
logger=state.logger,
|
||||||
|
config_loader=state.config_loader,
|
||||||
|
run_once=False,
|
||||||
|
shutdown_event=state.ts_shutdown_event,
|
||||||
|
)
|
||||||
|
if state.logger is None:
|
||||||
|
state.logger = powerline.logger
|
||||||
|
if state.config_loader is None:
|
||||||
|
state.config_loader = powerline.config_loader
|
||||||
|
except SystemExit:
|
||||||
|
# Somebody thought raising system exit was a good idea,
|
||||||
|
return ''
|
||||||
|
except Exception as e:
|
||||||
|
if powerline:
|
||||||
|
powerline.pl.exception('Failed to render {0}: {1}', str(key), str(e))
|
||||||
|
else:
|
||||||
|
return 'Failed to render {0}: {1}'.format(str(key), str(e))
|
||||||
|
s = BytesIO()
|
||||||
|
write_output(args, powerline, segment_info, get_unicode_writer(stream=s))
|
||||||
|
s.seek(0)
|
||||||
|
return s.read()
|
||||||
|
|
||||||
|
|
||||||
|
def eintr_retry_call(func, *args, **kwargs):
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
except EnvironmentError as e:
|
||||||
|
if getattr(e, 'errno', None) == errno.EINTR:
|
||||||
|
continue
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def do_read(conn, timeout=2.0):
|
||||||
|
''' Read data from the client. If the client fails to send data within
|
||||||
|
timeout seconds, abort. '''
|
||||||
|
read = []
|
||||||
|
end_time = monotonic() + timeout
|
||||||
|
while not read or not read[-1].endswith(b'\0\0'):
|
||||||
|
r, w, e = select((conn,), (), (conn,), timeout)
|
||||||
|
if e:
|
||||||
|
return
|
||||||
|
if monotonic() > end_time:
|
||||||
|
return
|
||||||
|
if not r:
|
||||||
|
continue
|
||||||
|
x = eintr_retry_call(conn.recv, 4096)
|
||||||
|
if x:
|
||||||
|
read.append(x)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return b''.join(read)
|
||||||
|
|
||||||
|
|
||||||
|
def do_write(conn, result):
|
||||||
|
try:
|
||||||
|
eintr_retry_call(conn.sendall, result)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def safe_bytes(o, encoding=get_preferred_output_encoding()):
|
||||||
|
'''Return bytes instance without ever throwing an exception.'''
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
# We are assuming that o is a unicode object
|
||||||
|
return o.encode(encoding, 'replace')
|
||||||
|
except Exception:
|
||||||
|
# Object may have defined __bytes__ (python 3) or __str__ method
|
||||||
|
# (python 2)
|
||||||
|
# This also catches problem with non_ascii_bytes.encode('utf-8')
|
||||||
|
# that first tries to decode to UTF-8 using ascii codec (and fails
|
||||||
|
# in this case) and then encode to given encoding: errors= argument
|
||||||
|
# is not used in the first stage.
|
||||||
|
return bytes(o)
|
||||||
|
except Exception as e:
|
||||||
|
return safe_bytes(str(e), encoding)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args(req, parser, encoding=get_preferred_arguments_encoding()):
|
||||||
|
args = [x.decode(encoding) for x in req.split(b'\0') if x]
|
||||||
|
numargs = int(args[0], 16)
|
||||||
|
shell_args = parser.parse_args(args[1:numargs + 1])
|
||||||
|
cwd = args[numargs + 1]
|
||||||
|
environ = dict(((k, v) for k, v in (x.partition('=')[0::2] for x in args[numargs + 2:])))
|
||||||
|
cwd = cwd or environ.get('PWD', '/')
|
||||||
|
return shell_args, environ, cwd
|
||||||
|
|
||||||
|
|
||||||
|
def get_answer(req, is_daemon, argparser, state):
|
||||||
|
try:
|
||||||
|
args, environ, cwd = parse_args(req, argparser)
|
||||||
|
finish_args(argparser, environ, args, is_daemon=True)
|
||||||
|
if args.ext[0].startswith('wm.'):
|
||||||
|
return safe_bytes(start_wm(args, environ, cwd, is_daemon, state))
|
||||||
|
else:
|
||||||
|
return safe_bytes(render(args, environ, cwd, is_daemon, state))
|
||||||
|
except Exception as e:
|
||||||
|
return safe_bytes(str(e))
|
||||||
|
|
||||||
|
|
||||||
|
def do_one(sock, read_sockets, write_sockets, result_map, is_daemon, argparser,
|
||||||
|
state):
|
||||||
|
r, w, e = select(
|
||||||
|
tuple(read_sockets) + (sock,),
|
||||||
|
tuple(write_sockets),
|
||||||
|
tuple(read_sockets) + tuple(write_sockets) + (sock,),
|
||||||
|
60.0
|
||||||
|
)
|
||||||
|
|
||||||
|
if sock in e:
|
||||||
|
# We cannot accept any more connections, so we exit
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
for s in e:
|
||||||
|
# Discard all broken connections to clients
|
||||||
|
s.close()
|
||||||
|
read_sockets.discard(s)
|
||||||
|
write_sockets.discard(s)
|
||||||
|
|
||||||
|
for s in r:
|
||||||
|
if s == sock:
|
||||||
|
# A client wants to connect
|
||||||
|
conn, _ = eintr_retry_call(sock.accept)
|
||||||
|
read_sockets.add(conn)
|
||||||
|
else:
|
||||||
|
# A client has sent some data
|
||||||
|
read_sockets.discard(s)
|
||||||
|
req = do_read(s)
|
||||||
|
if req == EOF:
|
||||||
|
raise SystemExit(0)
|
||||||
|
elif req:
|
||||||
|
ans = get_answer(req, is_daemon, argparser, state)
|
||||||
|
result_map[s] = ans
|
||||||
|
write_sockets.add(s)
|
||||||
|
else:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
for s in w:
|
||||||
|
# A client is ready to receive the result
|
||||||
|
write_sockets.discard(s)
|
||||||
|
result = result_map.pop(s)
|
||||||
|
try:
|
||||||
|
do_write(s, result)
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
|
def shutdown(sock, read_sockets, write_sockets, state):
|
||||||
|
'''Perform operations necessary for nicely shutting down daemon
|
||||||
|
|
||||||
|
Specifically it
|
||||||
|
|
||||||
|
#. Closes all sockets.
|
||||||
|
#. Notifies segments based on
|
||||||
|
:py:class:`powerline.lib.threaded.ThreadedSegment` and WM-specific
|
||||||
|
threads that daemon is shutting down.
|
||||||
|
#. Waits for threads to finish, but no more then 2 seconds total.
|
||||||
|
#. Waits so that total execution time of this function is 2 seconds in order
|
||||||
|
to allow ThreadedSegments to finish.
|
||||||
|
'''
|
||||||
|
total_wait_time = 2
|
||||||
|
shutdown_start_time = monotonic()
|
||||||
|
|
||||||
|
for s in chain((sock,), read_sockets, write_sockets):
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
# Notify ThreadedSegments
|
||||||
|
state.ts_shutdown_event.set()
|
||||||
|
for thread, shutdown_event in state.started_wm_threads.values():
|
||||||
|
shutdown_event.set()
|
||||||
|
|
||||||
|
for thread, shutdown_event in state.started_wm_threads.values():
|
||||||
|
wait_time = total_wait_time - (monotonic() - shutdown_start_time)
|
||||||
|
if wait_time > 0:
|
||||||
|
thread.join(wait_time)
|
||||||
|
|
||||||
|
wait_time = total_wait_time - (monotonic() - shutdown_start_time)
|
||||||
|
sleep(wait_time)
|
||||||
|
|
||||||
|
|
||||||
|
def main_loop(sock, is_daemon):
|
||||||
|
sock.listen(128)
|
||||||
|
sock.setblocking(0)
|
||||||
|
|
||||||
|
read_sockets, write_sockets = set(), set()
|
||||||
|
result_map = {}
|
||||||
|
parser = get_main_argparser(NonInteractiveArgParser)
|
||||||
|
state = State()
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
do_one(
|
||||||
|
sock, read_sockets, write_sockets, result_map,
|
||||||
|
is_daemon=is_daemon,
|
||||||
|
argparser=parser,
|
||||||
|
state=state,
|
||||||
|
)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
raise SystemExit(0)
|
||||||
|
except SystemExit as e:
|
||||||
|
shutdown(sock, read_sockets, write_sockets, state)
|
||||||
|
raise e
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def daemonize(stdin=os.devnull, stdout=os.devnull, stderr=os.devnull):
|
||||||
|
try:
|
||||||
|
pid = os.fork()
|
||||||
|
if pid > 0:
|
||||||
|
# exit first parent
|
||||||
|
raise SystemExit(0)
|
||||||
|
except OSError as e:
|
||||||
|
sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
# decouple from parent environment
|
||||||
|
os.chdir("/")
|
||||||
|
os.setsid()
|
||||||
|
os.umask(0)
|
||||||
|
|
||||||
|
# do second fork
|
||||||
|
try:
|
||||||
|
pid = os.fork()
|
||||||
|
if pid > 0:
|
||||||
|
# exit from second parent
|
||||||
|
raise SystemExit(0)
|
||||||
|
except OSError as e:
|
||||||
|
sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
# Redirect standard file descriptors.
|
||||||
|
si = open(stdin, 'rb')
|
||||||
|
so = open(stdout, 'a+b')
|
||||||
|
se = open(stderr, 'a+b', 0)
|
||||||
|
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||||
|
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||||
|
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def check_existing(address):
|
||||||
|
if USE_FILESYSTEM:
|
||||||
|
# We cannot bind if the socket file already exists so remove it, we
|
||||||
|
# already have a lock on pidfile, so this should be safe.
|
||||||
|
try:
|
||||||
|
os.unlink(address)
|
||||||
|
except EnvironmentError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
sock = socket.socket(family=socket.AF_UNIX)
|
||||||
|
try:
|
||||||
|
sock.bind(address)
|
||||||
|
except socket.error as e:
|
||||||
|
if getattr(e, 'errno', None) == errno.EADDRINUSE:
|
||||||
|
return None
|
||||||
|
raise
|
||||||
|
return sock
|
||||||
|
|
||||||
|
|
||||||
|
def kill_daemon(address):
|
||||||
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
eintr_retry_call(sock.connect, address)
|
||||||
|
except socket.error:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
eintr_retry_call(sock.sendall, EOF)
|
||||||
|
finally:
|
||||||
|
sock.close()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_lockfile(pidfile, fd, *args):
|
||||||
|
try:
|
||||||
|
# Remove the directory entry for the lock file
|
||||||
|
os.unlink(pidfile)
|
||||||
|
# Close the file descriptor
|
||||||
|
os.close(fd)
|
||||||
|
except EnvironmentError:
|
||||||
|
pass
|
||||||
|
if args:
|
||||||
|
# Called in signal handler
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def lockpidfile(pidfile):
|
||||||
|
fd = os.open(
|
||||||
|
pidfile,
|
||||||
|
os.O_WRONLY | os.O_CREAT,
|
||||||
|
stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
except EnvironmentError:
|
||||||
|
os.close(fd)
|
||||||
|
return None
|
||||||
|
os.lseek(fd, 0, os.SEEK_SET)
|
||||||
|
os.ftruncate(fd, 0)
|
||||||
|
os.write(fd, ('%d' % os.getpid()).encode('ascii'))
|
||||||
|
os.fsync(fd)
|
||||||
|
cleanup = partial(cleanup_lockfile, pidfile, fd)
|
||||||
|
signal(SIGTERM, cleanup)
|
||||||
|
atexit.register(cleanup)
|
||||||
|
return fd
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = get_daemon_argparser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
is_daemon = False
|
||||||
|
address = None
|
||||||
|
pidfile = None
|
||||||
|
|
||||||
|
if args.socket:
|
||||||
|
address = args.socket
|
||||||
|
if not USE_FILESYSTEM:
|
||||||
|
address = '\0' + address
|
||||||
|
else:
|
||||||
|
if USE_FILESYSTEM:
|
||||||
|
address = '/tmp/powerline-ipc-%d'
|
||||||
|
else:
|
||||||
|
# Use the abstract namespace for sockets rather than the filesystem
|
||||||
|
# (Available only in linux)
|
||||||
|
address = '\0powerline-ipc-%d'
|
||||||
|
|
||||||
|
address = address % os.getuid()
|
||||||
|
|
||||||
|
if USE_FILESYSTEM:
|
||||||
|
pidfile = address + '.pid'
|
||||||
|
|
||||||
|
if args.kill:
|
||||||
|
if args.foreground or args.replace:
|
||||||
|
parser.error('--kill and --foreground/--replace cannot be used together')
|
||||||
|
if kill_daemon(address):
|
||||||
|
if not args.quiet:
|
||||||
|
print ('Kill command sent to daemon, if it does not die in a couple of seconds use kill to kill it')
|
||||||
|
raise SystemExit(0)
|
||||||
|
else:
|
||||||
|
if not args.quiet:
|
||||||
|
print ('No running daemon found')
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
if args.replace:
|
||||||
|
while kill_daemon(address):
|
||||||
|
if not args.quiet:
|
||||||
|
print ('Kill command sent to daemon, waiting for daemon to exit, press Ctrl-C to terminate wait and exit')
|
||||||
|
sleep(2)
|
||||||
|
|
||||||
|
if USE_FILESYSTEM and not args.foreground:
|
||||||
|
# We must daemonize before creating the locked pidfile, unfortunately,
|
||||||
|
# this means further print statements are discarded
|
||||||
|
is_daemon = daemonize()
|
||||||
|
|
||||||
|
if USE_FILESYSTEM:
|
||||||
|
# Create a locked pid file containing the daemon’s PID
|
||||||
|
if lockpidfile(pidfile) is None:
|
||||||
|
if not args.quiet:
|
||||||
|
sys.stderr.write(
|
||||||
|
'The daemon is already running. Use %s -k to kill it.\n' % (
|
||||||
|
os.path.basename(sys.argv[0])))
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
# Bind to address or bail if we cannot bind
|
||||||
|
sock = check_existing(address)
|
||||||
|
if sock is None:
|
||||||
|
if not args.quiet:
|
||||||
|
sys.stderr.write(
|
||||||
|
'The daemon is already running. Use %s -k to kill it.\n' % (
|
||||||
|
os.path.basename(sys.argv[0])))
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
if not USE_FILESYSTEM and not args.foreground:
|
||||||
|
# We daemonize on linux
|
||||||
|
is_daemon = daemonize()
|
||||||
|
|
||||||
|
return main_loop(sock, is_daemon)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
13
powerline-bin/bin/powerline-lint
Normal file
13
powerline-bin/bin/powerline-lint
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#!/opt/python/bin/python3
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from powerline.lint import check
|
||||||
|
from powerline.commands.lint import get_argparser
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = get_argparser().parse_args()
|
||||||
|
sys.exit(check(args.config_path, args.debug))
|
31
powerline-bin/bin/powerline-render
Normal file
31
powerline-bin/bin/powerline-render
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#!/opt/python/bin/python3
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
try:
|
||||||
|
from powerline.shell import ShellPowerline
|
||||||
|
except ImportError:
|
||||||
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(__file__)))))
|
||||||
|
from powerline.shell import ShellPowerline
|
||||||
|
|
||||||
|
from powerline.commands.main import get_argparser, finish_args, write_output
|
||||||
|
from powerline.lib.encoding import get_unicode_writer
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
write = sys.stdout.write
|
||||||
|
else:
|
||||||
|
write = sys.stdout.buffer.write
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = get_argparser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
finish_args(parser, os.environ, args)
|
||||||
|
powerline = ShellPowerline(args, run_once=True)
|
||||||
|
segment_info = {'args': args, 'environ': os.environ}
|
||||||
|
write_output(args, powerline, segment_info, get_unicode_writer())
|
991
powerline-bin/powerline/__init__.py
Normal file
991
powerline-bin/powerline/__init__.py
Normal file
@ -0,0 +1,991 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from threading import Lock, Event
|
||||||
|
|
||||||
|
from powerline.colorscheme import Colorscheme
|
||||||
|
from powerline.lib.config import ConfigLoader
|
||||||
|
from powerline.lib.unicode import unicode, safe_unicode, FailedUnicode
|
||||||
|
from powerline.config import DEFAULT_SYSTEM_CONFIG_DIR
|
||||||
|
from powerline.lib.dict import mergedicts
|
||||||
|
from powerline.lib.encoding import get_preferred_output_encoding
|
||||||
|
from powerline.lib.path import join
|
||||||
|
|
||||||
|
|
||||||
|
class NotInterceptedError(BaseException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _config_loader_condition(path):
|
||||||
|
if path and os.path.isfile(path):
|
||||||
|
return path
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _find_config_files(search_paths, config_file, config_loader=None, loader_callback=None):
|
||||||
|
config_file += '.json'
|
||||||
|
found = False
|
||||||
|
for path in search_paths:
|
||||||
|
config_file_path = join(path, config_file)
|
||||||
|
if os.path.isfile(config_file_path):
|
||||||
|
yield config_file_path
|
||||||
|
found = True
|
||||||
|
elif config_loader:
|
||||||
|
config_loader.register_missing(_config_loader_condition, loader_callback, config_file_path)
|
||||||
|
if not found:
|
||||||
|
raise IOError('Config file not found in search paths ({0}): {1}'.format(
|
||||||
|
', '.join(search_paths),
|
||||||
|
config_file
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
class PowerlineLogger(object):
|
||||||
|
'''Proxy class for logging.Logger instance
|
||||||
|
|
||||||
|
It emits messages in format ``{ext}:{prefix}:{message}`` where
|
||||||
|
|
||||||
|
``{ext}``
|
||||||
|
is a used powerline extension (e.g. “vim”, “shell”, “ipython”).
|
||||||
|
``{prefix}``
|
||||||
|
is a local prefix, usually a segment name.
|
||||||
|
``{message}``
|
||||||
|
is the original message passed to one of the logging methods.
|
||||||
|
|
||||||
|
Each of the methods (``critical``, ``exception``, ``info``, ``error``,
|
||||||
|
``warn``, ``debug``) expects to receive message in an ``str.format`` format,
|
||||||
|
not in printf-like format.
|
||||||
|
|
||||||
|
Log is saved to the location :ref:`specified by user <config-common-log>`.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, use_daemon_threads, logger, ext):
|
||||||
|
self.logger = logger
|
||||||
|
self.ext = ext
|
||||||
|
self.use_daemon_threads = use_daemon_threads
|
||||||
|
self.prefix = ''
|
||||||
|
self.last_msgs = {}
|
||||||
|
|
||||||
|
def _log(self, attr, msg, *args, **kwargs):
|
||||||
|
prefix = kwargs.get('prefix') or self.prefix
|
||||||
|
prefix = self.ext + ((':' + prefix) if prefix else '')
|
||||||
|
msg = safe_unicode(msg)
|
||||||
|
if args or kwargs:
|
||||||
|
args = [safe_unicode(s) if isinstance(s, bytes) else s for s in args]
|
||||||
|
kwargs = dict((
|
||||||
|
(k, safe_unicode(v) if isinstance(v, bytes) else v)
|
||||||
|
for k, v in kwargs.items()
|
||||||
|
))
|
||||||
|
msg = msg.format(*args, **kwargs)
|
||||||
|
msg = prefix + ':' + msg
|
||||||
|
key = attr + ':' + prefix
|
||||||
|
if msg != self.last_msgs.get(key):
|
||||||
|
getattr(self.logger, attr)(msg)
|
||||||
|
self.last_msgs[key] = msg
|
||||||
|
|
||||||
|
def critical(self, msg, *args, **kwargs):
|
||||||
|
self._log('critical', msg, *args, **kwargs)
|
||||||
|
|
||||||
|
def exception(self, msg, *args, **kwargs):
|
||||||
|
self._log('exception', msg, *args, **kwargs)
|
||||||
|
|
||||||
|
def info(self, msg, *args, **kwargs):
|
||||||
|
self._log('info', msg, *args, **kwargs)
|
||||||
|
|
||||||
|
def error(self, msg, *args, **kwargs):
|
||||||
|
self._log('error', msg, *args, **kwargs)
|
||||||
|
|
||||||
|
def warn(self, msg, *args, **kwargs):
|
||||||
|
self._log('warning', msg, *args, **kwargs)
|
||||||
|
|
||||||
|
def debug(self, msg, *args, **kwargs):
|
||||||
|
self._log('debug', msg, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
_fallback_logger = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_fallback_logger(stream=None):
|
||||||
|
global _fallback_logger
|
||||||
|
if _fallback_logger:
|
||||||
|
return _fallback_logger
|
||||||
|
|
||||||
|
log_format = '%(asctime)s:%(levelname)s:%(message)s'
|
||||||
|
formatter = logging.Formatter(log_format)
|
||||||
|
|
||||||
|
level = logging.WARNING
|
||||||
|
handler = logging.StreamHandler(stream)
|
||||||
|
handler.setLevel(level)
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
|
||||||
|
logger = logging.Logger('powerline')
|
||||||
|
logger.setLevel(level)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
_fallback_logger = PowerlineLogger(None, logger, '_fallback_')
|
||||||
|
return _fallback_logger
|
||||||
|
|
||||||
|
|
||||||
|
def _generate_change_callback(lock, key, dictionary):
|
||||||
|
def on_file_change(path):
|
||||||
|
with lock:
|
||||||
|
dictionary[key] = True
|
||||||
|
return on_file_change
|
||||||
|
|
||||||
|
|
||||||
|
def get_config_paths():
|
||||||
|
'''Get configuration paths from environment variables.
|
||||||
|
|
||||||
|
Uses $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS according to the XDG specification.
|
||||||
|
|
||||||
|
:return: list of paths
|
||||||
|
'''
|
||||||
|
config_home = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config'))
|
||||||
|
config_path = join(config_home, 'powerline')
|
||||||
|
config_paths = [config_path]
|
||||||
|
config_dirs = os.environ.get('XDG_CONFIG_DIRS', DEFAULT_SYSTEM_CONFIG_DIR)
|
||||||
|
if config_dirs is not None:
|
||||||
|
config_paths[:0] = reversed([join(d, 'powerline') for d in config_dirs.split(':')])
|
||||||
|
plugin_path = join(os.path.realpath(os.path.dirname(__file__)), 'config_files')
|
||||||
|
config_paths.insert(0, plugin_path)
|
||||||
|
return config_paths
|
||||||
|
|
||||||
|
|
||||||
|
def generate_config_finder(get_config_paths=get_config_paths):
|
||||||
|
'''Generate find_config_files function
|
||||||
|
|
||||||
|
This function will find .json file given its path.
|
||||||
|
|
||||||
|
:param function get_config_paths:
|
||||||
|
Function that being called with no arguments will return a list of paths
|
||||||
|
that should be searched for configuration files.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
Function that being given configuration file name will return full path
|
||||||
|
to it or raise IOError if it failed to find the file.
|
||||||
|
'''
|
||||||
|
config_paths = get_config_paths()
|
||||||
|
return lambda *args: _find_config_files(config_paths, *args)
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(cfg_path, find_config_files, config_loader, loader_callback=None):
|
||||||
|
'''Load configuration file and setup watches
|
||||||
|
|
||||||
|
Watches are only set up if loader_callback is not None.
|
||||||
|
|
||||||
|
:param str cfg_path:
|
||||||
|
Path for configuration file that should be loaded.
|
||||||
|
:param function find_config_files:
|
||||||
|
Function that finds configuration file. Check out the description of
|
||||||
|
the return value of ``generate_config_finder`` function.
|
||||||
|
:param ConfigLoader config_loader:
|
||||||
|
Configuration file loader class instance.
|
||||||
|
:param function loader_callback:
|
||||||
|
Function that will be called by config_loader when change to
|
||||||
|
configuration file is detected.
|
||||||
|
|
||||||
|
:return: Configuration file contents.
|
||||||
|
'''
|
||||||
|
found_files = find_config_files(cfg_path, config_loader, loader_callback)
|
||||||
|
ret = None
|
||||||
|
for path in found_files:
|
||||||
|
if loader_callback:
|
||||||
|
config_loader.register(loader_callback, path)
|
||||||
|
if ret is None:
|
||||||
|
ret = config_loader.load(path)
|
||||||
|
else:
|
||||||
|
mergedicts(ret, config_loader.load(path))
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def _set_log_handlers(common_config, logger, get_module_attr, stream=None):
|
||||||
|
'''Set log handlers
|
||||||
|
|
||||||
|
:param dict common_config:
|
||||||
|
Configuration dictionary used to create handler.
|
||||||
|
:param logging.Logger logger:
|
||||||
|
Logger to which handlers will be attached.
|
||||||
|
:param func get_module_attr:
|
||||||
|
:py:func:`gen_module_attr_getter` output.
|
||||||
|
:param file stream:
|
||||||
|
Stream to use by default for :py:class:`logging.StreamHandler` in place
|
||||||
|
of :py:attr:`sys.stderr`. May be ``None``.
|
||||||
|
'''
|
||||||
|
log_targets = common_config['log_file']
|
||||||
|
num_handlers = 0
|
||||||
|
for log_target in log_targets:
|
||||||
|
if log_target is None:
|
||||||
|
log_target = ['logging.StreamHandler', []]
|
||||||
|
elif isinstance(log_target, unicode):
|
||||||
|
log_target = os.path.expanduser(log_target)
|
||||||
|
log_dir = os.path.dirname(log_target)
|
||||||
|
if log_dir and not os.path.isdir(log_dir):
|
||||||
|
os.mkdir(log_dir)
|
||||||
|
log_target = ['logging.FileHandler', [[log_target]]]
|
||||||
|
module, handler_class_name = log_target[0].rpartition('.')[::2]
|
||||||
|
module = module or 'logging.handlers'
|
||||||
|
try:
|
||||||
|
handler_class_args = log_target[1][0]
|
||||||
|
except IndexError:
|
||||||
|
if module == 'logging' and handler_class_name == 'StreamHandler':
|
||||||
|
handler_class_args = [stream]
|
||||||
|
else:
|
||||||
|
handler_class_args = ()
|
||||||
|
try:
|
||||||
|
handler_class_kwargs = log_target[1][1]
|
||||||
|
except IndexError:
|
||||||
|
handler_class_kwargs = {}
|
||||||
|
module = str(module)
|
||||||
|
handler_class_name = str(handler_class_name)
|
||||||
|
handler_class = get_module_attr(module, handler_class_name)
|
||||||
|
if not handler_class:
|
||||||
|
continue
|
||||||
|
handler = handler_class(*handler_class_args, **handler_class_kwargs)
|
||||||
|
try:
|
||||||
|
handler_level_name = log_target[2]
|
||||||
|
except IndexError:
|
||||||
|
handler_level_name = common_config['log_level']
|
||||||
|
try:
|
||||||
|
handler_format = log_target[3]
|
||||||
|
except IndexError:
|
||||||
|
handler_format = common_config['log_format']
|
||||||
|
handler.setLevel(getattr(logging, handler_level_name))
|
||||||
|
handler.setFormatter(logging.Formatter(handler_format))
|
||||||
|
logger.addHandler(handler)
|
||||||
|
num_handlers += 1
|
||||||
|
if num_handlers == 0 and log_targets:
|
||||||
|
raise ValueError('Failed to set up any handlers')
|
||||||
|
|
||||||
|
|
||||||
|
def create_logger(common_config, use_daemon_threads=True, ext='__unknown__',
|
||||||
|
import_paths=None, imported_modules=None, stream=None):
|
||||||
|
'''Create logger according to provided configuration
|
||||||
|
|
||||||
|
:param dict common_config:
|
||||||
|
Common configuration, from :py:func:`finish_common_config`.
|
||||||
|
:param bool use_daemon_threads:
|
||||||
|
Whether daemon threads should be used. Argument to
|
||||||
|
:py:class:`PowerlineLogger` constructor.
|
||||||
|
:param str ext:
|
||||||
|
Used extension. Argument to :py:class:`PowerlineLogger` constructor.
|
||||||
|
:param set imported_modules:
|
||||||
|
Set where imported modules are saved. Argument to
|
||||||
|
:py:func:`gen_module_attr_getter`. May be ``None``, in this case new
|
||||||
|
empty set is used.
|
||||||
|
:param file stream:
|
||||||
|
Stream to use by default for :py:class:`logging.StreamHandler` in place
|
||||||
|
of :py:attr:`sys.stderr`. May be ``None``.
|
||||||
|
|
||||||
|
:return: Three objects:
|
||||||
|
|
||||||
|
#. :py:class:`logging.Logger` instance.
|
||||||
|
#. :py:class:`PowerlineLogger` instance.
|
||||||
|
#. Function, output of :py:func:`gen_module_attr_getter`.
|
||||||
|
'''
|
||||||
|
logger = logging.Logger('powerline')
|
||||||
|
level = getattr(logging, common_config['log_level'])
|
||||||
|
logger.setLevel(level)
|
||||||
|
|
||||||
|
pl = PowerlineLogger(use_daemon_threads, logger, ext)
|
||||||
|
get_module_attr = gen_module_attr_getter(
|
||||||
|
pl, common_config['paths'],
|
||||||
|
set() if imported_modules is None else imported_modules)
|
||||||
|
|
||||||
|
_set_log_handlers(common_config, logger, get_module_attr, stream)
|
||||||
|
|
||||||
|
return logger, pl, get_module_attr
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_theme(is_unicode=True):
|
||||||
|
'''Get default theme used by powerline
|
||||||
|
|
||||||
|
:param bool is_unicode:
|
||||||
|
If true, return theme for unicode environments, otherwise return theme
|
||||||
|
that is supposed to be ASCII-only.
|
||||||
|
|
||||||
|
:return: theme name.
|
||||||
|
'''
|
||||||
|
return 'powerline_terminus' if is_unicode else 'ascii'
|
||||||
|
|
||||||
|
|
||||||
|
def finish_common_config(encoding, common_config):
|
||||||
|
'''Add default values to common config and expand ~ in paths
|
||||||
|
|
||||||
|
:param dict common_config:
|
||||||
|
Common configuration, as it was just loaded.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
Copy of common configuration with all configuration keys and expanded
|
||||||
|
paths.
|
||||||
|
'''
|
||||||
|
encoding = encoding.lower()
|
||||||
|
default_top_theme = get_default_theme(
|
||||||
|
encoding.startswith('utf') or encoding.startswith('ucs'))
|
||||||
|
|
||||||
|
common_config = common_config.copy()
|
||||||
|
common_config.setdefault('default_top_theme', default_top_theme)
|
||||||
|
common_config.setdefault('paths', [])
|
||||||
|
common_config.setdefault('watcher', 'auto')
|
||||||
|
common_config.setdefault('log_level', 'WARNING')
|
||||||
|
common_config.setdefault('log_format', '%(asctime)s:%(levelname)s:%(message)s')
|
||||||
|
common_config.setdefault('term_truecolor', False)
|
||||||
|
common_config.setdefault('term_escape_style', 'auto')
|
||||||
|
common_config.setdefault('ambiwidth', 1)
|
||||||
|
common_config.setdefault('additional_escapes', None)
|
||||||
|
common_config.setdefault('reload_config', True)
|
||||||
|
common_config.setdefault('interval', None)
|
||||||
|
common_config.setdefault('log_file', [None])
|
||||||
|
|
||||||
|
if not isinstance(common_config['log_file'], list):
|
||||||
|
common_config['log_file'] = [common_config['log_file']]
|
||||||
|
|
||||||
|
common_config['paths'] = [
|
||||||
|
os.path.expanduser(path) for path in common_config['paths']
|
||||||
|
]
|
||||||
|
|
||||||
|
return common_config
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
# `raise exception[0], None, exception[1]` is a SyntaxError in python-3*
|
||||||
|
# Not using ('''…''') because this syntax does not work in python-2.6
|
||||||
|
exec((
|
||||||
|
'def reraise(exception):\n'
|
||||||
|
' if type(exception) is tuple:\n'
|
||||||
|
' raise exception[0], None, exception[1]\n'
|
||||||
|
' else:\n'
|
||||||
|
' raise exception\n'
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
def reraise(exception):
|
||||||
|
if type(exception) is tuple:
|
||||||
|
raise exception[0].with_traceback(exception[1])
|
||||||
|
else:
|
||||||
|
raise exception
|
||||||
|
|
||||||
|
|
||||||
|
def gen_module_attr_getter(pl, import_paths, imported_modules):
|
||||||
|
def get_module_attr(module, attr, prefix='powerline'):
|
||||||
|
'''Import module and get its attribute.
|
||||||
|
|
||||||
|
Replaces ``from {module} import {attr}``.
|
||||||
|
|
||||||
|
:param str module:
|
||||||
|
Module name, will be passed as first argument to ``__import__``.
|
||||||
|
:param str attr:
|
||||||
|
Module attribute, will be passed to ``__import__`` as the only value
|
||||||
|
in ``fromlist`` tuple.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
Attribute value or ``None``. Note: there is no way to distinguish
|
||||||
|
between successfull import of attribute equal to ``None`` and
|
||||||
|
unsuccessfull import.
|
||||||
|
'''
|
||||||
|
oldpath = sys.path
|
||||||
|
sys.path = import_paths + sys.path
|
||||||
|
module = str(module)
|
||||||
|
attr = str(attr)
|
||||||
|
try:
|
||||||
|
imported_modules.add(module)
|
||||||
|
return getattr(__import__(module, fromlist=(attr,)), attr)
|
||||||
|
except Exception as e:
|
||||||
|
pl.exception('Failed to import attr {0} from module {1}: {2}', attr, module, str(e), prefix=prefix)
|
||||||
|
return None
|
||||||
|
finally:
|
||||||
|
sys.path = oldpath
|
||||||
|
|
||||||
|
return get_module_attr
|
||||||
|
|
||||||
|
|
||||||
|
LOG_KEYS = set(('log_format', 'log_level', 'log_file', 'paths'))
|
||||||
|
'''List of keys related to logging
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
def _get_log_keys(common_config):
|
||||||
|
'''Return a common configuration copy with only log-related config left
|
||||||
|
|
||||||
|
:param dict common_config:
|
||||||
|
Common configuration.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
:py:class:`dict` instance which has only keys from
|
||||||
|
:py:attr:`powerline.LOG_KEYS` left.
|
||||||
|
'''
|
||||||
|
return dict((
|
||||||
|
(k, v) for k, v in common_config.items() if k in LOG_KEYS
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_UPDATE_INTERVAL = 2
|
||||||
|
'''Default value for :ref:`update_interval <config-ext-update_interval>`
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
class Powerline(object):
|
||||||
|
'''Main powerline class, entrance point for all powerline uses. Sets
|
||||||
|
powerline up and loads the configuration.
|
||||||
|
|
||||||
|
:param str ext:
|
||||||
|
extension used. Determines where configuration files will
|
||||||
|
searched and what renderer module will be used. Affected: used ``ext``
|
||||||
|
dictionary from :file:`powerline/config.json`, location of themes and
|
||||||
|
colorschemes, render module (``powerline.renders.{ext}``).
|
||||||
|
:param str renderer_module:
|
||||||
|
Overrides renderer module (defaults to ``ext``). Should be the name of
|
||||||
|
the package imported like this: ``powerline.renderers.{render_module}``.
|
||||||
|
If this parameter contains a dot ``powerline.renderers.`` is not
|
||||||
|
prepended. There is also a special case for renderers defined in
|
||||||
|
toplevel modules: ``foo.`` (note: dot at the end) tries to get renderer
|
||||||
|
from module ``foo`` (because ``foo`` (without dot) tries to get renderer
|
||||||
|
from module ``powerline.renderers.foo``). When ``.foo`` (with leading
|
||||||
|
dot) variant is used ``renderer_module`` will be
|
||||||
|
``powerline.renderers.{ext}{renderer_module}``.
|
||||||
|
:param bool run_once:
|
||||||
|
Determines whether :py:meth:`render` method will be run only once
|
||||||
|
during python session.
|
||||||
|
:param Logger logger:
|
||||||
|
If present no new logger will be created and the provided logger will be
|
||||||
|
used.
|
||||||
|
:param bool use_daemon_threads:
|
||||||
|
When creating threads make them daemon ones.
|
||||||
|
:param Event shutdown_event:
|
||||||
|
Use this Event as shutdown_event instead of creating new event.
|
||||||
|
:param ConfigLoader config_loader:
|
||||||
|
Instance of the class that manages (re)loading of the configuration.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.init_args = (args, kwargs)
|
||||||
|
self.init(*args, **kwargs)
|
||||||
|
|
||||||
|
def init(self,
|
||||||
|
ext,
|
||||||
|
renderer_module=None,
|
||||||
|
run_once=False,
|
||||||
|
logger=None,
|
||||||
|
use_daemon_threads=True,
|
||||||
|
shutdown_event=None,
|
||||||
|
config_loader=None):
|
||||||
|
'''Do actual initialization.
|
||||||
|
|
||||||
|
__init__ function only stores the arguments and runs this function. This
|
||||||
|
function exists for powerline to be able to reload itself: it is easier
|
||||||
|
to make ``__init__`` store arguments and call overriddable ``init`` than
|
||||||
|
tell developers that each time they override Powerline.__init__ in
|
||||||
|
subclasses they must store actual arguments.
|
||||||
|
'''
|
||||||
|
self.ext = ext
|
||||||
|
self.run_once = run_once
|
||||||
|
self.logger = logger
|
||||||
|
self.had_logger = bool(self.logger)
|
||||||
|
self.use_daemon_threads = use_daemon_threads
|
||||||
|
|
||||||
|
if not renderer_module:
|
||||||
|
self.renderer_module = 'powerline.renderers.' + ext
|
||||||
|
elif '.' not in renderer_module:
|
||||||
|
self.renderer_module = 'powerline.renderers.' + renderer_module
|
||||||
|
elif renderer_module.startswith('.'):
|
||||||
|
self.renderer_module = 'powerline.renderers.' + ext + renderer_module
|
||||||
|
elif renderer_module.endswith('.'):
|
||||||
|
self.renderer_module = renderer_module[:-1]
|
||||||
|
else:
|
||||||
|
self.renderer_module = renderer_module
|
||||||
|
|
||||||
|
self.find_config_files = generate_config_finder(self.get_config_paths)
|
||||||
|
|
||||||
|
self.cr_kwargs_lock = Lock()
|
||||||
|
self.cr_kwargs = {}
|
||||||
|
self.cr_callbacks = {}
|
||||||
|
for key in ('main', 'colors', 'colorscheme', 'theme'):
|
||||||
|
self.cr_kwargs['load_' + key] = True
|
||||||
|
self.cr_callbacks[key] = _generate_change_callback(
|
||||||
|
self.cr_kwargs_lock,
|
||||||
|
'load_' + key,
|
||||||
|
self.cr_kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
self.shutdown_event = shutdown_event or Event()
|
||||||
|
self.config_loader = config_loader or ConfigLoader(shutdown_event=self.shutdown_event, run_once=run_once)
|
||||||
|
self.run_loader_update = False
|
||||||
|
|
||||||
|
self.renderer_options = {}
|
||||||
|
|
||||||
|
self.prev_common_config = None
|
||||||
|
self.prev_ext_config = None
|
||||||
|
self.pl = None
|
||||||
|
self.setup_args = ()
|
||||||
|
self.setup_kwargs = {}
|
||||||
|
self.imported_modules = set()
|
||||||
|
self.update_interval = DEFAULT_UPDATE_INTERVAL
|
||||||
|
|
||||||
|
get_encoding = staticmethod(get_preferred_output_encoding)
|
||||||
|
'''Get encoding used by the current application
|
||||||
|
|
||||||
|
Usually returns encoding of the current locale.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def create_logger(self):
|
||||||
|
'''Create logger
|
||||||
|
|
||||||
|
This function is used to create logger unless it was already specified
|
||||||
|
at initialization.
|
||||||
|
|
||||||
|
:return: Three objects:
|
||||||
|
|
||||||
|
#. :py:class:`logging.Logger` instance.
|
||||||
|
#. :py:class:`PowerlineLogger` instance.
|
||||||
|
#. Function, output of :py:func:`gen_module_attr_getter`.
|
||||||
|
'''
|
||||||
|
return create_logger(
|
||||||
|
common_config=self.common_config,
|
||||||
|
use_daemon_threads=self.use_daemon_threads,
|
||||||
|
ext=self.ext,
|
||||||
|
imported_modules=self.imported_modules,
|
||||||
|
stream=self.default_log_stream,
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_renderer(self, load_main=False, load_colors=False, load_colorscheme=False, load_theme=False):
|
||||||
|
'''(Re)create renderer object. Can be used after Powerline object was
|
||||||
|
successfully initialized. If any of the below parameters except
|
||||||
|
``load_main`` is True renderer object will be recreated.
|
||||||
|
|
||||||
|
:param bool load_main:
|
||||||
|
Determines whether main configuration file (:file:`config.json`)
|
||||||
|
should be loaded. If appropriate configuration changes implies
|
||||||
|
``load_colorscheme`` and ``load_theme`` and recreation of renderer
|
||||||
|
object. Won’t trigger recreation if only unrelated configuration
|
||||||
|
changed.
|
||||||
|
:param bool load_colors:
|
||||||
|
Determines whether colors configuration from :file:`colors.json`
|
||||||
|
should be (re)loaded.
|
||||||
|
:param bool load_colorscheme:
|
||||||
|
Determines whether colorscheme configuration should be (re)loaded.
|
||||||
|
:param bool load_theme:
|
||||||
|
Determines whether theme configuration should be reloaded.
|
||||||
|
'''
|
||||||
|
common_config_differs = False
|
||||||
|
ext_config_differs = False
|
||||||
|
if load_main:
|
||||||
|
self._purge_configs('main')
|
||||||
|
config = self.load_main_config()
|
||||||
|
self.common_config = finish_common_config(self.get_encoding(), config['common'])
|
||||||
|
if self.common_config != self.prev_common_config:
|
||||||
|
common_config_differs = True
|
||||||
|
|
||||||
|
load_theme = (load_theme
|
||||||
|
or not self.prev_common_config
|
||||||
|
or self.prev_common_config['default_top_theme'] != self.common_config['default_top_theme'])
|
||||||
|
|
||||||
|
log_keys_differ = (not self.prev_common_config or (
|
||||||
|
_get_log_keys(self.prev_common_config) != _get_log_keys(self.common_config)
|
||||||
|
))
|
||||||
|
|
||||||
|
self.prev_common_config = self.common_config
|
||||||
|
|
||||||
|
if log_keys_differ:
|
||||||
|
if self.had_logger:
|
||||||
|
self.pl = PowerlineLogger(self.use_daemon_threads, self.logger, self.ext)
|
||||||
|
self.get_module_attr = gen_module_attr_getter(
|
||||||
|
self.pl, self.common_config['paths'], self.imported_modules)
|
||||||
|
else:
|
||||||
|
self.logger, self.pl, self.get_module_attr = self.create_logger()
|
||||||
|
self.config_loader.pl = self.pl
|
||||||
|
|
||||||
|
if not self.run_once:
|
||||||
|
self.config_loader.set_watcher(self.common_config['watcher'])
|
||||||
|
|
||||||
|
mergedicts(self.renderer_options, dict(
|
||||||
|
pl=self.pl,
|
||||||
|
term_truecolor=self.common_config['term_truecolor'],
|
||||||
|
term_escape_style=self.common_config['term_escape_style'],
|
||||||
|
ambiwidth=self.common_config['ambiwidth'],
|
||||||
|
tmux_escape=self.common_config['additional_escapes'] == 'tmux',
|
||||||
|
screen_escape=self.common_config['additional_escapes'] == 'screen',
|
||||||
|
theme_kwargs={
|
||||||
|
'ext': self.ext,
|
||||||
|
'common_config': self.common_config,
|
||||||
|
'run_once': self.run_once,
|
||||||
|
'shutdown_event': self.shutdown_event,
|
||||||
|
'get_module_attr': self.get_module_attr,
|
||||||
|
},
|
||||||
|
))
|
||||||
|
|
||||||
|
if not self.run_once and self.common_config['reload_config']:
|
||||||
|
interval = self.common_config['interval']
|
||||||
|
self.config_loader.set_interval(interval)
|
||||||
|
self.run_loader_update = (interval is None)
|
||||||
|
if interval is not None and not self.config_loader.is_alive():
|
||||||
|
self.config_loader.start()
|
||||||
|
|
||||||
|
self.ext_config = config['ext'][self.ext]
|
||||||
|
|
||||||
|
top_theme = (
|
||||||
|
self.ext_config.get('top_theme')
|
||||||
|
or self.common_config['default_top_theme']
|
||||||
|
)
|
||||||
|
self.theme_levels = (
|
||||||
|
os.path.join('themes', top_theme),
|
||||||
|
os.path.join('themes', self.ext, '__main__'),
|
||||||
|
)
|
||||||
|
self.renderer_options['theme_kwargs']['top_theme'] = top_theme
|
||||||
|
|
||||||
|
if self.ext_config != self.prev_ext_config:
|
||||||
|
ext_config_differs = True
|
||||||
|
if (
|
||||||
|
not self.prev_ext_config
|
||||||
|
or self.ext_config.get('components') != self.prev_ext_config.get('components')
|
||||||
|
):
|
||||||
|
self.setup_components(self.ext_config.get('components'))
|
||||||
|
if (
|
||||||
|
not self.prev_ext_config
|
||||||
|
or self.ext_config.get('local_themes') != self.prev_ext_config.get('local_themes')
|
||||||
|
):
|
||||||
|
self.renderer_options['local_themes'] = self.get_local_themes(self.ext_config.get('local_themes'))
|
||||||
|
self.update_interval = self.ext_config.get('update_interval', 2)
|
||||||
|
load_colorscheme = (
|
||||||
|
load_colorscheme
|
||||||
|
or not self.prev_ext_config
|
||||||
|
or self.prev_ext_config['colorscheme'] != self.ext_config['colorscheme']
|
||||||
|
)
|
||||||
|
load_theme = (
|
||||||
|
load_theme
|
||||||
|
or not self.prev_ext_config
|
||||||
|
or self.prev_ext_config['theme'] != self.ext_config['theme']
|
||||||
|
)
|
||||||
|
self.prev_ext_config = self.ext_config
|
||||||
|
|
||||||
|
create_renderer = load_colors or load_colorscheme or load_theme or common_config_differs or ext_config_differs
|
||||||
|
|
||||||
|
if load_colors:
|
||||||
|
self._purge_configs('colors')
|
||||||
|
self.colors_config = self.load_colors_config()
|
||||||
|
|
||||||
|
if load_colorscheme or load_colors:
|
||||||
|
self._purge_configs('colorscheme')
|
||||||
|
if load_colorscheme:
|
||||||
|
self.colorscheme_config = self.load_colorscheme_config(self.ext_config['colorscheme'])
|
||||||
|
self.renderer_options['theme_kwargs']['colorscheme'] = (
|
||||||
|
Colorscheme(self.colorscheme_config, self.colors_config))
|
||||||
|
|
||||||
|
if load_theme:
|
||||||
|
self._purge_configs('theme')
|
||||||
|
self.renderer_options['theme_config'] = self.load_theme_config(self.ext_config.get('theme', 'default'))
|
||||||
|
|
||||||
|
if create_renderer:
|
||||||
|
Renderer = self.get_module_attr(self.renderer_module, 'renderer')
|
||||||
|
if not Renderer:
|
||||||
|
if hasattr(self, 'renderer'):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise ImportError('Failed to obtain renderer')
|
||||||
|
|
||||||
|
# Renderer updates configuration file via segments’ .startup thus it
|
||||||
|
# should be locked to prevent state when configuration was updated,
|
||||||
|
# but .render still uses old renderer.
|
||||||
|
try:
|
||||||
|
renderer = Renderer(**self.renderer_options)
|
||||||
|
except Exception as e:
|
||||||
|
self.exception('Failed to construct renderer object: {0}', str(e))
|
||||||
|
if not hasattr(self, 'renderer'):
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
self.renderer = renderer
|
||||||
|
|
||||||
|
default_log_stream = sys.stdout
|
||||||
|
'''Default stream for default log handler
|
||||||
|
|
||||||
|
Usually it is ``sys.stderr``, but there is sometimes a reason to prefer
|
||||||
|
``sys.stdout`` or a custom file-like object. It is not supposed to be used
|
||||||
|
to write to some file.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def setup_components(self, components):
|
||||||
|
'''Run component-specific setup
|
||||||
|
|
||||||
|
:param set components:
|
||||||
|
Set of the enabled componets or None.
|
||||||
|
|
||||||
|
Should be overridden by subclasses.
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_config_paths():
|
||||||
|
'''Get configuration paths.
|
||||||
|
|
||||||
|
Should be overridden in subclasses in order to provide a way to override
|
||||||
|
used paths.
|
||||||
|
|
||||||
|
:return: list of paths
|
||||||
|
'''
|
||||||
|
return get_config_paths()
|
||||||
|
|
||||||
|
def load_config(self, cfg_path, cfg_type):
|
||||||
|
'''Load configuration and setup watches
|
||||||
|
|
||||||
|
:param str cfg_path:
|
||||||
|
Path to the configuration file without any powerline configuration
|
||||||
|
directory or ``.json`` suffix.
|
||||||
|
:param str cfg_type:
|
||||||
|
Configuration type. May be one of ``main`` (for ``config.json``
|
||||||
|
file), ``colors``, ``colorscheme``, ``theme``.
|
||||||
|
|
||||||
|
:return: dictionary with loaded configuration.
|
||||||
|
'''
|
||||||
|
return load_config(
|
||||||
|
cfg_path,
|
||||||
|
self.find_config_files,
|
||||||
|
self.config_loader,
|
||||||
|
self.cr_callbacks[cfg_type]
|
||||||
|
)
|
||||||
|
|
||||||
|
def _purge_configs(self, cfg_type):
|
||||||
|
function = self.cr_callbacks[cfg_type]
|
||||||
|
self.config_loader.unregister_functions(set((function,)))
|
||||||
|
self.config_loader.unregister_missing(set(((self.find_config_files, function),)))
|
||||||
|
|
||||||
|
def load_main_config(self):
|
||||||
|
'''Get top-level configuration.
|
||||||
|
|
||||||
|
:return: dictionary with :ref:`top-level configuration <config-main>`.
|
||||||
|
'''
|
||||||
|
return self.load_config('config', 'main')
|
||||||
|
|
||||||
|
def _load_hierarhical_config(self, cfg_type, levels, ignore_levels):
|
||||||
|
'''Load and merge multiple configuration files
|
||||||
|
|
||||||
|
:param str cfg_type:
|
||||||
|
Type of the loaded configuration files (e.g. ``colorscheme``,
|
||||||
|
``theme``).
|
||||||
|
:param list levels:
|
||||||
|
Configuration names resembling levels in hierarchy, sorted by
|
||||||
|
priority. Configuration file names with higher priority should go
|
||||||
|
last.
|
||||||
|
:param set ignore_levels:
|
||||||
|
If only files listed in this variable are present then configuration
|
||||||
|
file is considered not loaded: at least one file on the level not
|
||||||
|
listed in this variable must be present.
|
||||||
|
'''
|
||||||
|
config = {}
|
||||||
|
loaded = 0
|
||||||
|
exceptions = []
|
||||||
|
for i, cfg_path in enumerate(levels):
|
||||||
|
try:
|
||||||
|
lvl_config = self.load_config(cfg_path, cfg_type)
|
||||||
|
except IOError as e:
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
tb = sys.exc_info()[2]
|
||||||
|
exceptions.append((e, tb))
|
||||||
|
else:
|
||||||
|
exceptions.append(e)
|
||||||
|
else:
|
||||||
|
if i not in ignore_levels:
|
||||||
|
loaded += 1
|
||||||
|
mergedicts(config, lvl_config)
|
||||||
|
if not loaded:
|
||||||
|
for exception in exceptions:
|
||||||
|
if type(exception) is tuple:
|
||||||
|
e = exception[0]
|
||||||
|
else:
|
||||||
|
e = exception
|
||||||
|
self.exception('Failed to load %s: {0}' % cfg_type, e, exception=exception)
|
||||||
|
raise e
|
||||||
|
return config
|
||||||
|
|
||||||
|
def load_colorscheme_config(self, name):
|
||||||
|
'''Get colorscheme.
|
||||||
|
|
||||||
|
:param str name:
|
||||||
|
Name of the colorscheme to load.
|
||||||
|
|
||||||
|
:return: dictionary with :ref:`colorscheme configuration <config-colorschemes>`.
|
||||||
|
'''
|
||||||
|
levels = (
|
||||||
|
os.path.join('colorschemes', name),
|
||||||
|
os.path.join('colorschemes', self.ext, '__main__'),
|
||||||
|
os.path.join('colorschemes', self.ext, name),
|
||||||
|
)
|
||||||
|
return self._load_hierarhical_config('colorscheme', levels, (1,))
|
||||||
|
|
||||||
|
def load_theme_config(self, name):
|
||||||
|
'''Get theme configuration.
|
||||||
|
|
||||||
|
:param str name:
|
||||||
|
Name of the theme to load.
|
||||||
|
|
||||||
|
:return: dictionary with :ref:`theme configuration <config-themes>`
|
||||||
|
'''
|
||||||
|
levels = self.theme_levels + (
|
||||||
|
os.path.join('themes', self.ext, name),
|
||||||
|
)
|
||||||
|
return self._load_hierarhical_config('theme', levels, (0, 1,))
|
||||||
|
|
||||||
|
def load_colors_config(self):
|
||||||
|
'''Get colorscheme.
|
||||||
|
|
||||||
|
:return: dictionary with :ref:`colors configuration <config-colors>`.
|
||||||
|
'''
|
||||||
|
return self.load_config('colors', 'colors')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_local_themes(local_themes):
|
||||||
|
'''Get local themes. No-op here, to be overridden in subclasses if
|
||||||
|
required.
|
||||||
|
|
||||||
|
:param dict local_themes:
|
||||||
|
Usually accepts ``{matcher_name : theme_name}``. May also receive
|
||||||
|
None in case there is no local_themes configuration.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
anything accepted by ``self.renderer.get_theme`` and processable by
|
||||||
|
``self.renderer.add_local_theme``. Renderer module is determined by
|
||||||
|
``__init__`` arguments, refer to its documentation.
|
||||||
|
'''
|
||||||
|
return None
|
||||||
|
|
||||||
|
def update_renderer(self):
|
||||||
|
'''Updates/creates a renderer if needed.'''
|
||||||
|
if self.run_loader_update:
|
||||||
|
self.config_loader.update()
|
||||||
|
cr_kwargs = None
|
||||||
|
with self.cr_kwargs_lock:
|
||||||
|
if self.cr_kwargs:
|
||||||
|
cr_kwargs = self.cr_kwargs.copy()
|
||||||
|
if cr_kwargs:
|
||||||
|
try:
|
||||||
|
self.create_renderer(**cr_kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
self.exception('Failed to create renderer: {0}', str(e))
|
||||||
|
if hasattr(self, 'renderer'):
|
||||||
|
with self.cr_kwargs_lock:
|
||||||
|
self.cr_kwargs.clear()
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
with self.cr_kwargs_lock:
|
||||||
|
self.cr_kwargs.clear()
|
||||||
|
|
||||||
|
def render(self, *args, **kwargs):
|
||||||
|
'''Update/create renderer if needed and pass all arguments further to
|
||||||
|
``self.renderer.render()``.
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
self.update_renderer()
|
||||||
|
return self.renderer.render(*args, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
exc = e
|
||||||
|
try:
|
||||||
|
self.exception('Failed to render: {0}', str(e))
|
||||||
|
except Exception as e:
|
||||||
|
exc = e
|
||||||
|
ret = FailedUnicode(safe_unicode(exc))
|
||||||
|
if kwargs.get('output_width', False):
|
||||||
|
ret = ret, len(ret)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def render_above_lines(self, *args, **kwargs):
|
||||||
|
'''Like .render(), but for ``self.renderer.render_above_lines()``
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
self.update_renderer()
|
||||||
|
for line in self.renderer.render_above_lines(*args, **kwargs):
|
||||||
|
yield line
|
||||||
|
except Exception as e:
|
||||||
|
exc = e
|
||||||
|
try:
|
||||||
|
self.exception('Failed to render: {0}', str(e))
|
||||||
|
except Exception as e:
|
||||||
|
exc = e
|
||||||
|
yield FailedUnicode(safe_unicode(exc))
|
||||||
|
|
||||||
|
def setup(self, *args, **kwargs):
|
||||||
|
'''Setup the environment to use powerline.
|
||||||
|
|
||||||
|
Must not be overridden by subclasses. This one only saves setup
|
||||||
|
arguments for :py:meth:`reload` method and calls :py:meth:`do_setup`.
|
||||||
|
'''
|
||||||
|
self.shutdown_event.clear()
|
||||||
|
self.setup_args = args
|
||||||
|
self.setup_kwargs.update(kwargs)
|
||||||
|
self.do_setup(*args, **kwargs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def do_setup():
|
||||||
|
'''Function that does initialization
|
||||||
|
|
||||||
|
Should be overridden by subclasses. May accept any number of regular or
|
||||||
|
keyword arguments.
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
'''Reload powerline after update.
|
||||||
|
|
||||||
|
Should handle most (but not all) powerline updates.
|
||||||
|
|
||||||
|
Purges out all powerline modules and modules imported by powerline for
|
||||||
|
segment and matcher functions. Requires defining ``setup`` function that
|
||||||
|
updates reference to main powerline object.
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
Not guaranteed to work properly, use it at your own risk. It
|
||||||
|
may break your python code.
|
||||||
|
'''
|
||||||
|
import sys
|
||||||
|
modules = self.imported_modules | set((module for module in sys.modules if module.startswith('powerline')))
|
||||||
|
modules_holder = []
|
||||||
|
for module in modules:
|
||||||
|
try:
|
||||||
|
# Needs to hold module to prevent garbage collecting until they
|
||||||
|
# are all reloaded.
|
||||||
|
modules_holder.append(sys.modules.pop(module))
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
PowerlineClass = getattr(__import__(self.__module__, fromlist=(self.__class__.__name__,)), self.__class__.__name__)
|
||||||
|
self.shutdown(set_event=True)
|
||||||
|
init_args, init_kwargs = self.init_args
|
||||||
|
powerline = PowerlineClass(*init_args, **init_kwargs)
|
||||||
|
powerline.setup(*self.setup_args, **self.setup_kwargs)
|
||||||
|
|
||||||
|
def shutdown(self, set_event=True):
|
||||||
|
'''Shut down all background threads.
|
||||||
|
|
||||||
|
:param bool set_event:
|
||||||
|
Set ``shutdown_event`` and call ``renderer.shutdown`` which should
|
||||||
|
shut down all threads. Set it to False unless you are exiting an
|
||||||
|
application.
|
||||||
|
|
||||||
|
If set to False this does nothing more then resolving reference
|
||||||
|
cycle ``powerline → config_loader → bound methods → powerline`` by
|
||||||
|
unsubscribing from config_loader events.
|
||||||
|
'''
|
||||||
|
if set_event:
|
||||||
|
self.shutdown_event.set()
|
||||||
|
try:
|
||||||
|
self.renderer.shutdown()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
functions = tuple(self.cr_callbacks.values())
|
||||||
|
self.config_loader.unregister_functions(set(functions))
|
||||||
|
self.config_loader.unregister_missing(set(((self.find_config_files, function) for function in functions)))
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *args):
|
||||||
|
self.shutdown()
|
||||||
|
|
||||||
|
def exception(self, msg, *args, **kwargs):
|
||||||
|
if 'prefix' not in kwargs:
|
||||||
|
kwargs['prefix'] = 'powerline'
|
||||||
|
exception = kwargs.pop('exception', None)
|
||||||
|
pl = getattr(self, 'pl', None) or get_fallback_logger(self.default_log_stream)
|
||||||
|
if exception:
|
||||||
|
try:
|
||||||
|
reraise(exception)
|
||||||
|
except Exception:
|
||||||
|
return pl.exception(msg, *args, **kwargs)
|
||||||
|
return pl.exception(msg, *args, **kwargs)
|
BIN
powerline-bin/powerline/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/colorscheme.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/colorscheme.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/config.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/config.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/ipython.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/ipython.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/lemonbar.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/lemonbar.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/pdb.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/pdb.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/renderer.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/renderer.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/segment.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/segment.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/shell.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/shell.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/theme.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/theme.cpython-312.pyc
Normal file
Binary file not shown.
BIN
powerline-bin/powerline/__pycache__/vim.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/__pycache__/vim.cpython-312.pyc
Normal file
Binary file not shown.
0
powerline-bin/powerline/bindings/__init__.py
Normal file
0
powerline-bin/powerline/bindings/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
BIN
powerline-bin/powerline/bindings/awesome/__pycache__/powerline-awesome.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/bindings/awesome/__pycache__/powerline-awesome.cpython-312.pyc
Normal file
Binary file not shown.
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from powerline.bindings.wm import DEFAULT_UPDATE_INTERVAL
|
||||||
|
from powerline.bindings.wm.awesome import run
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
try:
|
||||||
|
interval = float(sys.argv[1])
|
||||||
|
except IndexError:
|
||||||
|
interval = DEFAULT_UPDATE_INTERVAL
|
||||||
|
run(interval=interval)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
15
powerline-bin/powerline/bindings/awesome/powerline.lua
Normal file
15
powerline-bin/powerline/bindings/awesome/powerline.lua
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
local wibox = require('wibox')
|
||||||
|
local awful = require('awful')
|
||||||
|
|
||||||
|
powerline_widget = wibox.widget.textbox()
|
||||||
|
powerline_widget:set_align('right')
|
||||||
|
|
||||||
|
function powerline(mode, widget) end
|
||||||
|
|
||||||
|
if string.find(awesome.version, 'v4') then
|
||||||
|
awful.spawn.with_shell('powerline-daemon -q')
|
||||||
|
awful.spawn.with_shell('powerline wm.awesome')
|
||||||
|
else
|
||||||
|
awful.util.spawn_with_shell('powerline-daemon -q')
|
||||||
|
awful.util.spawn_with_shell('powerline wm.awesome')
|
||||||
|
end
|
Binary file not shown.
60
powerline-bin/powerline/bindings/bar/powerline-bar.py
Normal file
60
powerline-bin/powerline/bindings/bar/powerline-bar.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
from threading import Lock, Timer
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
from powerline.lemonbar import LemonbarPowerline
|
||||||
|
from powerline.lib.encoding import get_unicode_writer
|
||||||
|
from powerline.bindings.wm import DEFAULT_UPDATE_INTERVAL
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = ArgumentParser(description='Powerline lemonbar bindings.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--i3', action='store_true',
|
||||||
|
help='Subscribe for i3 events.'
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
powerline = LemonbarPowerline()
|
||||||
|
powerline.update_renderer()
|
||||||
|
powerline.pl.warn("The 'bar' bindings are deprecated, please switch to 'lemonbar'")
|
||||||
|
lock = Lock()
|
||||||
|
modes = ['default']
|
||||||
|
write = get_unicode_writer(encoding='utf-8')
|
||||||
|
|
||||||
|
def render(reschedule=False):
|
||||||
|
if reschedule:
|
||||||
|
Timer(DEFAULT_UPDATE_INTERVAL, render, kwargs={'reschedule': True}).start()
|
||||||
|
|
||||||
|
global lock
|
||||||
|
with lock:
|
||||||
|
write(powerline.render(mode=modes[0]))
|
||||||
|
write('\n')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
def update(evt):
|
||||||
|
modes[0] = evt.change
|
||||||
|
render()
|
||||||
|
|
||||||
|
render(reschedule=True)
|
||||||
|
|
||||||
|
if args.i3:
|
||||||
|
try:
|
||||||
|
import i3ipc
|
||||||
|
except ImportError:
|
||||||
|
import i3
|
||||||
|
i3.Subscription(lambda evt, data, sub: print(render()), 'workspace')
|
||||||
|
else:
|
||||||
|
conn = i3ipc.Connection()
|
||||||
|
conn.on('workspace::focus', lambda conn, evt: render())
|
||||||
|
conn.on('mode', lambda conn, evt: update(evt))
|
||||||
|
conn.main()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(1e8)
|
153
powerline-bin/powerline/bindings/bash/powerline.sh
Normal file
153
powerline-bin/powerline/bindings/bash/powerline.sh
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
_powerline_columns_fallback() {
|
||||||
|
if which stty &>/dev/null ; then
|
||||||
|
local cols="$(stty size 2>/dev/null)"
|
||||||
|
if ! test -z "$cols" ; then
|
||||||
|
echo "${cols#* }"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo 0
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_pane() {
|
||||||
|
echo "${TMUX_PANE:-`TMUX="$_POWERLINE_TMUX" tmux display -p "#D"`}" | \
|
||||||
|
tr -d ' %'
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_setenv() {
|
||||||
|
TMUX="$_POWERLINE_TMUX" tmux setenv -g TMUX_"$1"_`_powerline_tmux_pane` "$2"
|
||||||
|
TMUX="$_POWERLINE_TMUX" tmux refresh -S
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_set_pwd() {
|
||||||
|
if test "$_POWERLINE_SAVED_PWD" != "$PWD" ; then
|
||||||
|
_POWERLINE_SAVED_PWD="$PWD"
|
||||||
|
_powerline_tmux_setenv PWD "$PWD"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_return() {
|
||||||
|
return $1
|
||||||
|
}
|
||||||
|
|
||||||
|
_POWERLINE_HAS_PIPESTATUS="$(
|
||||||
|
_powerline_return 0 | _powerline_return 43
|
||||||
|
test "${PIPESTATUS[*]}" = "0 43"
|
||||||
|
echo "$?"
|
||||||
|
)"
|
||||||
|
|
||||||
|
_powerline_has_pipestatus() {
|
||||||
|
return $_POWERLINE_HAS_PIPESTATUS
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_status_wrapper() {
|
||||||
|
local last_exit_code=$? last_pipe_status=( "${PIPESTATUS[@]}" )
|
||||||
|
|
||||||
|
if ! _powerline_has_pipestatus \
|
||||||
|
|| test "${#last_pipe_status[@]}" -eq "0" \
|
||||||
|
|| test "$last_exit_code" != "${last_pipe_status[$(( ${#last_pipe_status[@]} - 1 ))]}" ; then
|
||||||
|
last_pipe_status=()
|
||||||
|
fi
|
||||||
|
"$@" $last_exit_code "${last_pipe_status[*]}"
|
||||||
|
return $last_exit_code
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_add_status_wrapped_command() {
|
||||||
|
local action="$1" ; shift
|
||||||
|
local cmd="$1" ; shift
|
||||||
|
full_cmd="_powerline_status_wrapper $cmd"
|
||||||
|
if test "$action" = "append" ; then
|
||||||
|
PROMPT_COMMAND="$PROMPT_COMMAND"$'\n'"$full_cmd"
|
||||||
|
else
|
||||||
|
PROMPT_COMMAND="$full_cmd"$'\n'"$PROMPT_COMMAND"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_set_columns() {
|
||||||
|
_powerline_tmux_setenv COLUMNS "${COLUMNS:-`_powerline_columns_fallback`}"
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_init_tmux_support() {
|
||||||
|
if test -n "$TMUX" && tmux refresh -S &>/dev/null ; then
|
||||||
|
# TMUX variable may be unset to create new tmux session inside this one
|
||||||
|
_POWERLINE_TMUX="$TMUX"
|
||||||
|
|
||||||
|
trap '_powerline_tmux_set_columns' WINCH
|
||||||
|
_powerline_tmux_set_columns
|
||||||
|
|
||||||
|
test "$PROMPT_COMMAND" != "${PROMPT_COMMAND/_powerline_tmux_set_pwd}" \
|
||||||
|
|| _powerline_add_status_wrapped_command append _powerline_tmux_set_pwd
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_local_prompt() {
|
||||||
|
# Arguments:
|
||||||
|
# 1: side
|
||||||
|
# 2: renderer_module arg
|
||||||
|
# 3: last_exit_code
|
||||||
|
# 4: last_pipe_status
|
||||||
|
# 5: jobnum
|
||||||
|
# 6: local theme
|
||||||
|
"$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS shell $1 \
|
||||||
|
$2 \
|
||||||
|
--last-exit-code=$3 \
|
||||||
|
--last-pipe-status="$4" \
|
||||||
|
--jobnum=$5 \
|
||||||
|
--renderer-arg="client_id=$$" \
|
||||||
|
--renderer-arg="local_theme=$6"
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_prompt() {
|
||||||
|
# Arguments:
|
||||||
|
# 1: side
|
||||||
|
# 2: last_exit_code
|
||||||
|
# 3: last_pipe_status
|
||||||
|
# 4: jobnum
|
||||||
|
"$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS shell $1 \
|
||||||
|
--width="${COLUMNS:-$(_powerline_columns_fallback)}" \
|
||||||
|
-r.bash \
|
||||||
|
--last-exit-code=$2 \
|
||||||
|
--last-pipe-status="$3" \
|
||||||
|
--jobnum=$4 \
|
||||||
|
--renderer-arg="client_id=$$"
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_set_prompt() {
|
||||||
|
local last_exit_code=$1 ; shift
|
||||||
|
local last_pipe_status=$1 ; shift
|
||||||
|
local jobnum="$(jobs -p|wc -l)"
|
||||||
|
PS1="$(_powerline_prompt aboveleft $last_exit_code "$last_pipe_status" $jobnum)"
|
||||||
|
if test -n "$POWERLINE_SHELL_CONTINUATION$POWERLINE_BASH_CONTINUATION" ; then
|
||||||
|
PS2="$(_powerline_local_prompt left -r.bash $last_exit_code "$last_pipe_status" $jobnum continuation)"
|
||||||
|
fi
|
||||||
|
if test -n "$POWERLINE_SHELL_SELECT$POWERLINE_BASH_SELECT" ; then
|
||||||
|
PS3="$(_powerline_local_prompt left '' $last_exit_code "$last_pipe_status" $jobnum select)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_setup_prompt() {
|
||||||
|
VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||||
|
if test -z "${POWERLINE_COMMAND}" ; then
|
||||||
|
POWERLINE_COMMAND="$("$POWERLINE_CONFIG_COMMAND" shell command)"
|
||||||
|
fi
|
||||||
|
test "$PROMPT_COMMAND" != "${PROMPT_COMMAND%_powerline_set_prompt*}" \
|
||||||
|
|| _powerline_add_status_wrapped_command prepend _powerline_set_prompt
|
||||||
|
PS2="$(_powerline_local_prompt left -r.bash 0 0 0 continuation)"
|
||||||
|
PS3="$(_powerline_local_prompt left '' 0 0 0 select)"
|
||||||
|
}
|
||||||
|
|
||||||
|
if test -z "${POWERLINE_CONFIG_COMMAND}" ; then
|
||||||
|
if which powerline-config >/dev/null ; then
|
||||||
|
POWERLINE_CONFIG_COMMAND=powerline-config
|
||||||
|
else
|
||||||
|
POWERLINE_CONFIG_COMMAND="$(dirname "$BASH_SOURCE")/../../../scripts/powerline-config"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if "${POWERLINE_CONFIG_COMMAND}" shell --shell=bash uses prompt ; then
|
||||||
|
_powerline_setup_prompt
|
||||||
|
fi
|
||||||
|
if "${POWERLINE_CONFIG_COMMAND}" shell --shell=bash uses tmux ; then
|
||||||
|
_powerline_init_tmux_support
|
||||||
|
fi
|
286
powerline-bin/powerline/bindings/config.py
Normal file
286
powerline-bin/powerline/bindings/config.py
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
|
||||||
|
from powerline.config import POWERLINE_ROOT, TMUX_CONFIG_DIRECTORY
|
||||||
|
from powerline.lib.config import ConfigLoader
|
||||||
|
from powerline import generate_config_finder, load_config, create_logger, finish_common_config
|
||||||
|
from powerline.shell import ShellPowerline
|
||||||
|
from powerline.lib.shell import which
|
||||||
|
from powerline.bindings.tmux import (TmuxVersionInfo, run_tmux_command, set_tmux_environment, get_tmux_version,
|
||||||
|
source_tmux_file)
|
||||||
|
from powerline.lib.encoding import get_preferred_output_encoding
|
||||||
|
from powerline.renderers.tmux import attrs_to_tmux_attrs
|
||||||
|
from powerline.commands.main import finish_args
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_FILE_NAME = re.compile(r'powerline_tmux_(?P<major>\d+)\.(?P<minor>\d+)(?P<suffix>[a-z]+)?(?:_(?P<mod>plus|minus))?\.conf')
|
||||||
|
CONFIG_MATCHERS = {
|
||||||
|
None: (lambda a, b: a.major == b.major and a.minor == b.minor),
|
||||||
|
'plus': (lambda a, b: a[:2] <= b[:2]),
|
||||||
|
'minus': (lambda a, b: a[:2] >= b[:2]),
|
||||||
|
}
|
||||||
|
CONFIG_PRIORITY = {
|
||||||
|
None: 3,
|
||||||
|
'plus': 2,
|
||||||
|
'minus': 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def list_all_tmux_configs():
|
||||||
|
'''List all version-specific tmux configuration files'''
|
||||||
|
for root, dirs, files in os.walk(TMUX_CONFIG_DIRECTORY):
|
||||||
|
dirs[:] = ()
|
||||||
|
for fname in files:
|
||||||
|
match = CONFIG_FILE_NAME.match(fname)
|
||||||
|
if match:
|
||||||
|
assert match.group('suffix') is None
|
||||||
|
yield (
|
||||||
|
os.path.join(root, fname),
|
||||||
|
CONFIG_MATCHERS[match.group('mod')],
|
||||||
|
CONFIG_PRIORITY[match.group('mod')],
|
||||||
|
TmuxVersionInfo(
|
||||||
|
int(match.group('major')),
|
||||||
|
int(match.group('minor')),
|
||||||
|
match.group('suffix'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_tmux_configs(version):
|
||||||
|
'''Get tmux configuration suffix given parsed tmux version
|
||||||
|
|
||||||
|
:param TmuxVersionInfo version: Parsed tmux version.
|
||||||
|
'''
|
||||||
|
for fname, matcher, priority, file_version in list_all_tmux_configs():
|
||||||
|
if matcher(file_version, version):
|
||||||
|
yield (fname, priority + file_version.minor * 10 + file_version.major * 10000)
|
||||||
|
|
||||||
|
|
||||||
|
def source_tmux_files(pl, args, tmux_version=None, source_tmux_file=source_tmux_file):
|
||||||
|
'''Source relevant version-specific tmux configuration files
|
||||||
|
|
||||||
|
Files are sourced in the following order:
|
||||||
|
* First relevant files with older versions are sourced.
|
||||||
|
* If files for same versions are to be sourced then first _minus files are
|
||||||
|
sourced, then _plus files and then files without _minus or _plus suffixes.
|
||||||
|
'''
|
||||||
|
tmux_version = tmux_version or get_tmux_version(pl)
|
||||||
|
source_tmux_file(os.path.join(TMUX_CONFIG_DIRECTORY, 'powerline-base.conf'))
|
||||||
|
for fname, priority in sorted(get_tmux_configs(tmux_version), key=(lambda v: v[1])):
|
||||||
|
source_tmux_file(fname)
|
||||||
|
if not os.environ.get('POWERLINE_COMMAND'):
|
||||||
|
cmd = deduce_command()
|
||||||
|
if cmd:
|
||||||
|
set_tmux_environment('POWERLINE_COMMAND', deduce_command(), remove=False)
|
||||||
|
try:
|
||||||
|
run_tmux_command('refresh-client')
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
# On tmux-2.0 this command may fail for whatever reason. Since it is
|
||||||
|
# critical just ignore the failure.
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class EmptyArgs(object):
|
||||||
|
def __init__(self, ext, config_path):
|
||||||
|
self.ext = [ext]
|
||||||
|
self.side = 'left'
|
||||||
|
self.config_path = None
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def init_tmux_environment(pl, args, set_tmux_environment=set_tmux_environment):
|
||||||
|
'''Initialize tmux environment from tmux configuration
|
||||||
|
'''
|
||||||
|
powerline = ShellPowerline(finish_args(None, os.environ, EmptyArgs('tmux', args.config_path)))
|
||||||
|
# TODO Move configuration files loading out of Powerline object and use it
|
||||||
|
# directly
|
||||||
|
powerline.update_renderer()
|
||||||
|
# FIXME Use something more stable then `theme_kwargs`
|
||||||
|
colorscheme = powerline.renderer_options['theme_kwargs']['colorscheme']
|
||||||
|
|
||||||
|
def get_highlighting(group):
|
||||||
|
return colorscheme.get_highlighting([group], None)
|
||||||
|
|
||||||
|
for varname, highlight_group in (
|
||||||
|
('_POWERLINE_BACKGROUND_COLOR', 'background'),
|
||||||
|
('_POWERLINE_ACTIVE_WINDOW_STATUS_COLOR', 'active_window_status'),
|
||||||
|
('_POWERLINE_WINDOW_STATUS_COLOR', 'window_status'),
|
||||||
|
('_POWERLINE_ACTIVITY_STATUS_COLOR', 'activity_status'),
|
||||||
|
('_POWERLINE_BELL_STATUS_COLOR', 'bell_status'),
|
||||||
|
('_POWERLINE_WINDOW_COLOR', 'window'),
|
||||||
|
('_POWERLINE_WINDOW_DIVIDER_COLOR', 'window:divider'),
|
||||||
|
('_POWERLINE_WINDOW_CURRENT_COLOR', 'window:current'),
|
||||||
|
('_POWERLINE_WINDOW_NAME_COLOR', 'window_name'),
|
||||||
|
('_POWERLINE_SESSION_COLOR', 'session'),
|
||||||
|
):
|
||||||
|
highlight = get_highlighting(highlight_group)
|
||||||
|
set_tmux_environment(varname, powerline.renderer.hlstyle(**highlight)[2:-1])
|
||||||
|
for varname, prev_group, next_group in (
|
||||||
|
('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR', 'window', 'window:current'),
|
||||||
|
('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR', 'window:current', 'window'),
|
||||||
|
('_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR', 'session', 'background'),
|
||||||
|
):
|
||||||
|
prev_highlight = get_highlighting(prev_group)
|
||||||
|
next_highlight = get_highlighting(next_group)
|
||||||
|
set_tmux_environment(
|
||||||
|
varname,
|
||||||
|
powerline.renderer.hlstyle(
|
||||||
|
fg=prev_highlight['bg'],
|
||||||
|
bg=next_highlight['bg'],
|
||||||
|
attrs=0,
|
||||||
|
)[2:-1]
|
||||||
|
)
|
||||||
|
for varname, attr, group in (
|
||||||
|
('_POWERLINE_ACTIVE_WINDOW_FG', 'fg', 'active_window_status'),
|
||||||
|
('_POWERLINE_WINDOW_STATUS_FG', 'fg', 'window_status'),
|
||||||
|
('_POWERLINE_ACTIVITY_STATUS_FG', 'fg', 'activity_status'),
|
||||||
|
('_POWERLINE_ACTIVITY_STATUS_ATTR', 'attrs', 'activity_status'),
|
||||||
|
('_POWERLINE_BELL_STATUS_FG', 'fg', 'bell_status'),
|
||||||
|
('_POWERLINE_BELL_STATUS_ATTR', 'attrs', 'bell_status'),
|
||||||
|
('_POWERLINE_BACKGROUND_FG', 'fg', 'background'),
|
||||||
|
('_POWERLINE_BACKGROUND_BG', 'bg', 'background'),
|
||||||
|
('_POWERLINE_SESSION_FG', 'fg', 'session'),
|
||||||
|
('_POWERLINE_SESSION_BG', 'bg', 'session'),
|
||||||
|
('_POWERLINE_SESSION_ATTR', 'attrs', 'session'),
|
||||||
|
('_POWERLINE_SESSION_PREFIX_FG', 'fg', 'session:prefix'),
|
||||||
|
('_POWERLINE_SESSION_PREFIX_BG', 'bg', 'session:prefix'),
|
||||||
|
('_POWERLINE_SESSION_PREFIX_ATTR', 'attrs', 'session:prefix'),
|
||||||
|
):
|
||||||
|
if attr == 'attrs':
|
||||||
|
attrs = attrs_to_tmux_attrs(get_highlighting(group)[attr])
|
||||||
|
set_tmux_environment(varname, ']#['.join(attrs))
|
||||||
|
set_tmux_environment(varname + '_LEGACY', (','.join(
|
||||||
|
# Tmux-1.6 does not accept no… attributes in
|
||||||
|
# window-status-…-attr options.
|
||||||
|
(attr for attr in attrs if not attr.startswith('no')))
|
||||||
|
# But it does not support empty attributes as well.
|
||||||
|
or 'none'))
|
||||||
|
else:
|
||||||
|
if powerline.common_config['term_truecolor']:
|
||||||
|
set_tmux_environment(varname, '#{0:06x}'.format(get_highlighting(group)[attr][1]))
|
||||||
|
else:
|
||||||
|
set_tmux_environment(varname, 'colour' + str(get_highlighting(group)[attr][0]))
|
||||||
|
|
||||||
|
left_dividers = powerline.renderer.theme.dividers['left']
|
||||||
|
set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER', left_dividers['hard'])
|
||||||
|
set_tmux_environment('_POWERLINE_LEFT_SOFT_DIVIDER', left_dividers['soft'])
|
||||||
|
set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER_SPACES', (
|
||||||
|
' ' * powerline.renderer.strwidth(left_dividers['hard'])))
|
||||||
|
|
||||||
|
|
||||||
|
TMUX_VAR_RE = re.compile('\$(_POWERLINE_\w+)')
|
||||||
|
|
||||||
|
|
||||||
|
def tmux_setup(pl, args):
|
||||||
|
tmux_environ = {}
|
||||||
|
tmux_version = get_tmux_version(pl)
|
||||||
|
|
||||||
|
def set_tmux_environment_nosource(varname, value, remove=True):
|
||||||
|
tmux_environ[varname] = value
|
||||||
|
|
||||||
|
def replace_cb(match):
|
||||||
|
return tmux_environ[match.group(1)]
|
||||||
|
|
||||||
|
def replace_env(s):
|
||||||
|
return TMUX_VAR_RE.subn(replace_cb, s)[0]
|
||||||
|
|
||||||
|
def source_tmux_file_nosource(fname):
|
||||||
|
with open(fname) as fd:
|
||||||
|
for line in fd:
|
||||||
|
if line.startswith('#') or line == '\n':
|
||||||
|
continue
|
||||||
|
args = shlex.split(line)
|
||||||
|
args = [args[0]] + [replace_env(arg) for arg in args[1:]]
|
||||||
|
run_tmux_command(*args)
|
||||||
|
|
||||||
|
if args.source is None:
|
||||||
|
args.source = tmux_version < (1, 9)
|
||||||
|
|
||||||
|
if args.source:
|
||||||
|
ste = set_tmux_environment
|
||||||
|
stf = source_tmux_file
|
||||||
|
else:
|
||||||
|
ste = set_tmux_environment_nosource
|
||||||
|
stf = source_tmux_file_nosource
|
||||||
|
|
||||||
|
init_tmux_environment(pl, args, set_tmux_environment=ste)
|
||||||
|
source_tmux_files(pl, args, tmux_version=tmux_version, source_tmux_file=stf)
|
||||||
|
|
||||||
|
|
||||||
|
def get_main_config(args):
|
||||||
|
find_config_files = generate_config_finder()
|
||||||
|
config_loader = ConfigLoader(run_once=True)
|
||||||
|
return load_config('config', find_config_files, config_loader)
|
||||||
|
|
||||||
|
|
||||||
|
def create_powerline_logger(args):
|
||||||
|
config = get_main_config(args)
|
||||||
|
common_config = finish_common_config(get_preferred_output_encoding(), config['common'])
|
||||||
|
logger, pl, get_module_attr = create_logger(common_config)
|
||||||
|
return pl
|
||||||
|
|
||||||
|
|
||||||
|
def check_command(cmd):
|
||||||
|
if which(cmd):
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
|
def deduce_command():
|
||||||
|
'''Deduce which command to use for ``powerline``
|
||||||
|
|
||||||
|
Candidates:
|
||||||
|
|
||||||
|
* ``powerline``. Present only when installed system-wide.
|
||||||
|
* ``{powerline_root}/scripts/powerline``. Present after ``pip install -e``
|
||||||
|
was run and C client was compiled (in this case ``pip`` does not install
|
||||||
|
binary file).
|
||||||
|
* ``{powerline_root}/client/powerline.sh``. Useful when ``sh``, ``sed`` and
|
||||||
|
``socat`` are present, but ``pip`` or ``setup.py`` was not run.
|
||||||
|
* ``{powerline_root}/client/powerline.py``. Like above, but when one of
|
||||||
|
``sh``, ``sed`` and ``socat`` was not present.
|
||||||
|
* ``powerline-render``. Should not really ever be used.
|
||||||
|
* ``{powerline_root}/scripts/powerline-render``. Same.
|
||||||
|
'''
|
||||||
|
return (
|
||||||
|
None
|
||||||
|
or check_command('powerline')
|
||||||
|
or check_command(os.path.join(POWERLINE_ROOT, 'scripts', 'powerline'))
|
||||||
|
or ((which('sh') and which('sed') and which('socat'))
|
||||||
|
and check_command(os.path.join(POWERLINE_ROOT, 'client', 'powerline.sh')))
|
||||||
|
or check_command(os.path.join(POWERLINE_ROOT, 'client', 'powerline.py'))
|
||||||
|
or check_command('powerline-render')
|
||||||
|
or check_command(os.path.join(POWERLINE_ROOT, 'scripts', 'powerline-render'))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def shell_command(pl, args):
|
||||||
|
cmd = deduce_command()
|
||||||
|
if cmd:
|
||||||
|
print(cmd)
|
||||||
|
else:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def uses(pl, args):
|
||||||
|
component = args.component
|
||||||
|
if not component:
|
||||||
|
raise ValueError('Must specify component')
|
||||||
|
shell = args.shell
|
||||||
|
template = 'POWERLINE_NO_{shell}_{component}'
|
||||||
|
for sh in (shell, 'shell') if shell else ('shell'):
|
||||||
|
varname = template.format(shell=sh.upper(), component=component.upper())
|
||||||
|
if os.environ.get(varname):
|
||||||
|
sys.exit(1)
|
||||||
|
config = get_main_config(args)
|
||||||
|
if component in config.get('ext', {}).get('shell', {}).get('components', ('tmux', 'prompt')):
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
sys.exit(1)
|
109
powerline-bin/powerline/bindings/fish/powerline-setup.fish
Normal file
109
powerline-bin/powerline/bindings/fish/powerline-setup.fish
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
function powerline-setup
|
||||||
|
function _powerline_columns_fallback
|
||||||
|
if which stty >/dev/null
|
||||||
|
if stty size >/dev/null
|
||||||
|
stty size | cut -d' ' -f2
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
echo 0
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function _powerline_columns
|
||||||
|
# Hack: `test "" -eq 0` is true, as well as `test 0 -eq 0`
|
||||||
|
# Note: at fish startup `$COLUMNS` is equal to zero, meaning that it may
|
||||||
|
# not be used.
|
||||||
|
if test "$COLUMNS" -eq 0
|
||||||
|
_powerline_columns_fallback
|
||||||
|
else
|
||||||
|
echo "$COLUMNS"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -z "$POWERLINE_CONFIG_COMMAND"
|
||||||
|
if which powerline-config >/dev/null
|
||||||
|
set -g POWERLINE_CONFIG_COMMAND powerline-config
|
||||||
|
else
|
||||||
|
set -g POWERLINE_CONFIG_COMMAND (dirname (status -f))/../../../scripts/powerline-config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if env $POWERLINE_CONFIG_COMMAND shell --shell=fish uses prompt
|
||||||
|
if test -z "$POWERLINE_COMMAND"
|
||||||
|
set -g POWERLINE_COMMAND (env $POWERLINE_CONFIG_COMMAND shell command)
|
||||||
|
end
|
||||||
|
function _powerline_set_default_mode --on-variable fish_key_bindings
|
||||||
|
if test $fish_key_bindings != fish_vi_key_bindings
|
||||||
|
set -g _POWERLINE_DEFAULT_MODE default
|
||||||
|
else
|
||||||
|
set -g -e _POWERLINE_DEFAULT_MODE
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function _powerline_update --on-variable POWERLINE_COMMAND
|
||||||
|
set -l addargs "--last-exit-code=\$status"
|
||||||
|
set -l addargs "$addargs --last-pipe-status=\$status"
|
||||||
|
set -l addargs "$addargs --jobnum=(jobs -p | wc -l)"
|
||||||
|
# One random value has an 1/32767 = 0.0031% probability of having
|
||||||
|
# the same value in two shells
|
||||||
|
set -l addargs "$addargs --renderer-arg=client_id="(random)
|
||||||
|
set -l addargs "$addargs --width=\$_POWERLINE_COLUMNS"
|
||||||
|
set -l addargs "$addargs --renderer-arg=mode=\$fish_bind_mode"
|
||||||
|
set -l addargs "$addargs --renderer-arg=default_mode=\$_POWERLINE_DEFAULT_MODE"
|
||||||
|
set -l promptside
|
||||||
|
set -l rpromptpast
|
||||||
|
set -l columnsexpr
|
||||||
|
if test -z "$POWERLINE_NO_FISH_ABOVE$POWERLINE_NO_SHELL_ABOVE"
|
||||||
|
set promptside aboveleft
|
||||||
|
set rpromptpast 'echo -n " "'
|
||||||
|
set columnsexpr '(math (_powerline_columns) - 1)'
|
||||||
|
else
|
||||||
|
set promptside left
|
||||||
|
set rpromptpast
|
||||||
|
set columnsexpr '(_powerline_columns)'
|
||||||
|
end
|
||||||
|
echo "
|
||||||
|
function fish_prompt
|
||||||
|
env \$POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell $promptside $addargs
|
||||||
|
end
|
||||||
|
function fish_right_prompt
|
||||||
|
env \$POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell right $addargs
|
||||||
|
$rpromptpast
|
||||||
|
end
|
||||||
|
function _powerline_set_columns --on-signal WINCH
|
||||||
|
set -g _POWERLINE_COLUMNS $columnsexpr
|
||||||
|
end
|
||||||
|
" | source
|
||||||
|
_powerline_set_columns
|
||||||
|
end
|
||||||
|
_powerline_set_default_mode
|
||||||
|
_powerline_update
|
||||||
|
end
|
||||||
|
if env $POWERLINE_CONFIG_COMMAND shell --shell=fish uses tmux
|
||||||
|
if test -n "$TMUX"
|
||||||
|
if tmux refresh -S ^/dev/null
|
||||||
|
set -g _POWERLINE_TMUX "$TMUX"
|
||||||
|
function _powerline_tmux_pane
|
||||||
|
if test -z "$TMUX_PANE"
|
||||||
|
env TMUX="$_POWERLINE_TMUX" tmux display -p "#D" | tr -d ' %'
|
||||||
|
else
|
||||||
|
echo "$TMUX_PANE" | tr -d ' %'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function _powerline_tmux_setenv
|
||||||
|
env TMUX="$_POWERLINE_TMUX" tmux setenv -g TMUX_$argv[1]_(_powerline_tmux_pane) "$argv[2]"
|
||||||
|
env TMUX="$_POWERLINE_TMUX" tmux refresh -S
|
||||||
|
end
|
||||||
|
function _powerline_tmux_set_pwd --on-variable PWD
|
||||||
|
_powerline_tmux_setenv PWD "$PWD"
|
||||||
|
end
|
||||||
|
function _powerline_tmux_set_columns --on-signal WINCH
|
||||||
|
_powerline_tmux_setenv COLUMNS (_powerline_columns)
|
||||||
|
end
|
||||||
|
_powerline_tmux_set_columns
|
||||||
|
_powerline_tmux_set_pwd
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# vim: ft=fish
|
Binary file not shown.
52
powerline-bin/powerline/bindings/i3/powerline-i3.py
Normal file
52
powerline-bin/powerline/bindings/i3/powerline-i3.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
|
from powerline.bindings.wm import get_i3_connection, i3_subscribe
|
||||||
|
|
||||||
|
from powerline import Powerline
|
||||||
|
from powerline.lib.monotonic import monotonic
|
||||||
|
|
||||||
|
|
||||||
|
class I3Powerline(Powerline):
|
||||||
|
'''Powerline child for i3bar
|
||||||
|
|
||||||
|
Currently only changes the default log target.
|
||||||
|
'''
|
||||||
|
default_log_stream = sys.stderr
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
name = 'wm'
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
name = sys.argv[1]
|
||||||
|
|
||||||
|
powerline = I3Powerline(name, renderer_module='i3bar')
|
||||||
|
powerline.update_renderer()
|
||||||
|
|
||||||
|
interval = 0.5
|
||||||
|
|
||||||
|
print ('{"version": 1}')
|
||||||
|
print ('[')
|
||||||
|
print ('[]')
|
||||||
|
|
||||||
|
lock = Lock()
|
||||||
|
|
||||||
|
def render(event=None, data=None, sub=None):
|
||||||
|
global lock
|
||||||
|
with lock:
|
||||||
|
print (',[' + powerline.render()[:-1] + ']')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
i3 = get_i3_connection()
|
||||||
|
i3_subscribe(i3, 'workspace', render)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
start_time = monotonic()
|
||||||
|
render()
|
||||||
|
time.sleep(max(interval - (monotonic() - start_time), 0.1))
|
0
powerline-bin/powerline/bindings/ipython/__init__.py
Normal file
0
powerline-bin/powerline/bindings/ipython/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
123
powerline-bin/powerline/bindings/ipython/post_0_11.py
Normal file
123
powerline-bin/powerline/bindings/ipython/post_0_11.py
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
from weakref import ref
|
||||||
|
from warnings import warn
|
||||||
|
|
||||||
|
try:
|
||||||
|
from IPython.core.prompts import PromptManager
|
||||||
|
has_prompt_manager = True
|
||||||
|
except ImportError:
|
||||||
|
has_prompt_manager = False
|
||||||
|
from IPython.core.magic import Magics, magics_class, line_magic
|
||||||
|
|
||||||
|
from powerline.ipython import IPythonPowerline, IPythonInfo
|
||||||
|
|
||||||
|
if has_prompt_manager:
|
||||||
|
from powerline.ipython import RewriteResult
|
||||||
|
|
||||||
|
|
||||||
|
@magics_class
|
||||||
|
class PowerlineMagics(Magics):
|
||||||
|
def __init__(self, ip, powerline):
|
||||||
|
super(PowerlineMagics, self).__init__(ip)
|
||||||
|
self._powerline = powerline
|
||||||
|
|
||||||
|
@line_magic
|
||||||
|
def powerline(self, line):
|
||||||
|
if line == 'reload':
|
||||||
|
self._powerline.reload()
|
||||||
|
else:
|
||||||
|
raise ValueError('Expected `reload`, but got {0}'.format(line))
|
||||||
|
|
||||||
|
|
||||||
|
old_prompt_manager = None
|
||||||
|
|
||||||
|
|
||||||
|
class ShutdownHook(object):
|
||||||
|
def __init__(self, ip):
|
||||||
|
self.powerline = lambda: None
|
||||||
|
ip.hooks.shutdown_hook.add(self)
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
from IPython.core.hooks import TryNext
|
||||||
|
powerline = self.powerline()
|
||||||
|
if powerline is not None:
|
||||||
|
powerline.shutdown()
|
||||||
|
raise TryNext()
|
||||||
|
|
||||||
|
|
||||||
|
if has_prompt_manager:
|
||||||
|
class PowerlinePromptManager(PromptManager):
|
||||||
|
def __init__(self, powerline, shell):
|
||||||
|
self.powerline = powerline
|
||||||
|
self.powerline_segment_info = IPythonInfo(shell)
|
||||||
|
self.shell = shell
|
||||||
|
|
||||||
|
def render(self, name, color=True, *args, **kwargs):
|
||||||
|
res = self.powerline.render(
|
||||||
|
is_prompt=name.startswith('in'),
|
||||||
|
side='left',
|
||||||
|
output_width=True,
|
||||||
|
output_raw=not color,
|
||||||
|
matcher_info=name,
|
||||||
|
segment_info=self.powerline_segment_info,
|
||||||
|
)
|
||||||
|
self.txtwidth = res[-1]
|
||||||
|
self.width = res[-1]
|
||||||
|
ret = res[0] if color else res[1]
|
||||||
|
if name == 'rewrite':
|
||||||
|
return RewriteResult(ret)
|
||||||
|
else:
|
||||||
|
return ret
|
||||||
|
|
||||||
|
class ConfigurableIPythonPowerline(IPythonPowerline):
|
||||||
|
def init(self, ip):
|
||||||
|
config = ip.config.Powerline
|
||||||
|
self.config_overrides = config.get('config_overrides')
|
||||||
|
self.theme_overrides = config.get('theme_overrides', {})
|
||||||
|
self.config_paths = config.get('config_paths')
|
||||||
|
if has_prompt_manager:
|
||||||
|
renderer_module = '.pre_5'
|
||||||
|
else:
|
||||||
|
renderer_module = '.since_5'
|
||||||
|
super(ConfigurableIPythonPowerline, self).init(
|
||||||
|
renderer_module=renderer_module)
|
||||||
|
|
||||||
|
def do_setup(self, ip, shutdown_hook):
|
||||||
|
global old_prompt_manager
|
||||||
|
|
||||||
|
if old_prompt_manager is None:
|
||||||
|
old_prompt_manager = ip.prompt_manager
|
||||||
|
prompt_manager = PowerlinePromptManager(
|
||||||
|
powerline=self,
|
||||||
|
shell=ip.prompt_manager.shell,
|
||||||
|
)
|
||||||
|
ip.prompt_manager = prompt_manager
|
||||||
|
|
||||||
|
magics = PowerlineMagics(ip, self)
|
||||||
|
shutdown_hook.powerline = ref(self)
|
||||||
|
ip.register_magics(magics)
|
||||||
|
|
||||||
|
|
||||||
|
def load_ipython_extension(ip):
|
||||||
|
if has_prompt_manager:
|
||||||
|
shutdown_hook = ShutdownHook(ip)
|
||||||
|
powerline = ConfigurableIPythonPowerline(ip)
|
||||||
|
powerline.setup(ip, shutdown_hook)
|
||||||
|
else:
|
||||||
|
from powerline.bindings.ipython.since_5 import PowerlinePrompts
|
||||||
|
ip.prompts_class = PowerlinePrompts
|
||||||
|
ip.prompts = PowerlinePrompts(ip)
|
||||||
|
warn(DeprecationWarning(
|
||||||
|
'post_0_11 extension is deprecated since IPython 5, use\n'
|
||||||
|
' from powerline.bindings.ipython.since_5 import PowerlinePrompts\n'
|
||||||
|
' c.TerminalInteractiveShell.prompts_class = PowerlinePrompts\n'
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
def unload_ipython_extension(ip):
|
||||||
|
global old_prompt_manager
|
||||||
|
if old_prompt_manager is not None:
|
||||||
|
ip.prompt_manager = old_prompt_manager
|
||||||
|
old_prompt_manager = None
|
146
powerline-bin/powerline/bindings/ipython/pre_0_11.py
Normal file
146
powerline-bin/powerline/bindings/ipython/pre_0_11.py
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
from weakref import ref
|
||||||
|
|
||||||
|
from IPython.Prompts import BasePrompt
|
||||||
|
from IPython.ipapi import get as get_ipython
|
||||||
|
from IPython.ipapi import TryNext
|
||||||
|
|
||||||
|
from powerline.ipython import IPythonPowerline, RewriteResult
|
||||||
|
from powerline.lib.unicode import string
|
||||||
|
|
||||||
|
|
||||||
|
class IPythonInfo(object):
|
||||||
|
def __init__(self, cache):
|
||||||
|
self._cache = cache
|
||||||
|
|
||||||
|
@property
|
||||||
|
def prompt_count(self):
|
||||||
|
return self._cache.prompt_count
|
||||||
|
|
||||||
|
|
||||||
|
class PowerlinePrompt(BasePrompt):
|
||||||
|
def __init__(self, powerline, powerline_last_in, old_prompt):
|
||||||
|
self.powerline = powerline
|
||||||
|
self.powerline_last_in = powerline_last_in
|
||||||
|
self.powerline_segment_info = IPythonInfo(old_prompt.cache)
|
||||||
|
self.cache = old_prompt.cache
|
||||||
|
if hasattr(old_prompt, 'sep'):
|
||||||
|
self.sep = old_prompt.sep
|
||||||
|
self.pad_left = False
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
self.set_p_str()
|
||||||
|
return string(self.p_str)
|
||||||
|
|
||||||
|
def set_p_str(self):
|
||||||
|
self.p_str, self.p_str_nocolor, self.powerline_prompt_width = (
|
||||||
|
self.powerline.render(
|
||||||
|
is_prompt=self.powerline_is_prompt,
|
||||||
|
side='left',
|
||||||
|
output_raw=True,
|
||||||
|
output_width=True,
|
||||||
|
segment_info=self.powerline_segment_info,
|
||||||
|
matcher_info=self.powerline_prompt_type,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def set_colors():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class PowerlinePrompt1(PowerlinePrompt):
|
||||||
|
powerline_prompt_type = 'in'
|
||||||
|
powerline_is_prompt = True
|
||||||
|
rspace = re.compile(r'(\s*)$')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
self.cache.prompt_count += 1
|
||||||
|
self.set_p_str()
|
||||||
|
self.cache.last_prompt = self.p_str_nocolor.split('\n')[-1]
|
||||||
|
return string(self.p_str)
|
||||||
|
|
||||||
|
def set_p_str(self):
|
||||||
|
super(PowerlinePrompt1, self).set_p_str()
|
||||||
|
self.nrspaces = len(self.rspace.search(self.p_str_nocolor).group())
|
||||||
|
self.powerline_last_in['nrspaces'] = self.nrspaces
|
||||||
|
|
||||||
|
def auto_rewrite(self):
|
||||||
|
return RewriteResult(self.powerline.render(
|
||||||
|
is_prompt=False,
|
||||||
|
side='left',
|
||||||
|
matcher_info='rewrite',
|
||||||
|
segment_info=self.powerline_segment_info) + (' ' * self.nrspaces)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PowerlinePromptOut(PowerlinePrompt):
|
||||||
|
powerline_prompt_type = 'out'
|
||||||
|
powerline_is_prompt = False
|
||||||
|
|
||||||
|
def set_p_str(self):
|
||||||
|
super(PowerlinePromptOut, self).set_p_str()
|
||||||
|
spaces = ' ' * self.powerline_last_in['nrspaces']
|
||||||
|
self.p_str += spaces
|
||||||
|
self.p_str_nocolor += spaces
|
||||||
|
|
||||||
|
|
||||||
|
class PowerlinePrompt2(PowerlinePromptOut):
|
||||||
|
powerline_prompt_type = 'in2'
|
||||||
|
powerline_is_prompt = True
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigurableIPythonPowerline(IPythonPowerline):
|
||||||
|
def init(self, config_overrides=None, theme_overrides={}, config_paths=None):
|
||||||
|
self.config_overrides = config_overrides
|
||||||
|
self.theme_overrides = theme_overrides
|
||||||
|
self.config_paths = config_paths
|
||||||
|
super(ConfigurableIPythonPowerline, self).init(renderer_module='.pre_5')
|
||||||
|
|
||||||
|
def ipython_magic(self, ip, parameter_s=''):
|
||||||
|
if parameter_s == 'reload':
|
||||||
|
self.reload()
|
||||||
|
else:
|
||||||
|
raise ValueError('Expected `reload`, but got {0}'.format(parameter_s))
|
||||||
|
|
||||||
|
def do_setup(self, ip, shutdown_hook):
|
||||||
|
last_in = {'nrspaces': 0}
|
||||||
|
for attr, prompt_class in (
|
||||||
|
('prompt1', PowerlinePrompt1),
|
||||||
|
('prompt2', PowerlinePrompt2),
|
||||||
|
('prompt_out', PowerlinePromptOut)
|
||||||
|
):
|
||||||
|
old_prompt = getattr(ip.IP.outputcache, attr)
|
||||||
|
prompt = prompt_class(self, last_in, old_prompt)
|
||||||
|
setattr(ip.IP.outputcache, attr, prompt)
|
||||||
|
ip.expose_magic('powerline', self.ipython_magic)
|
||||||
|
shutdown_hook.powerline = ref(self)
|
||||||
|
|
||||||
|
|
||||||
|
class ShutdownHook(object):
|
||||||
|
powerline = lambda: None
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
from IPython.ipapi import TryNext
|
||||||
|
powerline = self.powerline()
|
||||||
|
if powerline is not None:
|
||||||
|
powerline.shutdown()
|
||||||
|
raise TryNext()
|
||||||
|
|
||||||
|
|
||||||
|
def setup(**kwargs):
|
||||||
|
ip = get_ipython()
|
||||||
|
|
||||||
|
powerline = ConfigurableIPythonPowerline(**kwargs)
|
||||||
|
shutdown_hook = ShutdownHook()
|
||||||
|
|
||||||
|
def late_startup_hook():
|
||||||
|
powerline.setup(ip, shutdown_hook)
|
||||||
|
raise TryNext()
|
||||||
|
|
||||||
|
ip.IP.hooks.late_startup_hook.add(late_startup_hook)
|
||||||
|
ip.IP.hooks.shutdown_hook.add(shutdown_hook)
|
81
powerline-bin/powerline/bindings/ipython/since_5.py
Normal file
81
powerline-bin/powerline/bindings/ipython/since_5.py
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
from weakref import ref
|
||||||
|
|
||||||
|
from IPython.terminal.prompts import Prompts
|
||||||
|
from pygments.token import Token # NOQA
|
||||||
|
|
||||||
|
from powerline.ipython import IPythonPowerline
|
||||||
|
from powerline.renderers.ipython.since_5 import PowerlinePromptStyle
|
||||||
|
from powerline.bindings.ipython.post_0_11 import PowerlineMagics, ShutdownHook
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigurableIPythonPowerline(IPythonPowerline):
|
||||||
|
def init(self, ip):
|
||||||
|
config = ip.config.Powerline
|
||||||
|
self.config_overrides = config.get('config_overrides')
|
||||||
|
self.theme_overrides = config.get('theme_overrides', {})
|
||||||
|
self.config_paths = config.get('config_paths')
|
||||||
|
super(ConfigurableIPythonPowerline, self).init(
|
||||||
|
renderer_module='.since_5')
|
||||||
|
|
||||||
|
def do_setup(self, ip, prompts, shutdown_hook):
|
||||||
|
prompts.powerline = self
|
||||||
|
|
||||||
|
msfn_missing = ()
|
||||||
|
saved_msfn = getattr(ip, '_make_style_from_name', msfn_missing)
|
||||||
|
|
||||||
|
if hasattr(saved_msfn, 'powerline_original'):
|
||||||
|
saved_msfn = saved_msfn.powerline_original
|
||||||
|
|
||||||
|
def _make_style_from_name(ip, name):
|
||||||
|
prev_style = saved_msfn(name)
|
||||||
|
new_style = PowerlinePromptStyle(lambda: prev_style)
|
||||||
|
return new_style
|
||||||
|
|
||||||
|
_make_style_from_name.powerline_original = saved_msfn
|
||||||
|
|
||||||
|
if not isinstance(ip._style, PowerlinePromptStyle):
|
||||||
|
prev_style = ip._style
|
||||||
|
ip._style = PowerlinePromptStyle(lambda: prev_style)
|
||||||
|
|
||||||
|
if not isinstance(saved_msfn, type(self.init)):
|
||||||
|
_saved_msfn = saved_msfn
|
||||||
|
saved_msfn = lambda: _saved_msfn(ip)
|
||||||
|
|
||||||
|
if saved_msfn is not msfn_missing:
|
||||||
|
ip._make_style_from_name = _make_style_from_name
|
||||||
|
|
||||||
|
magics = PowerlineMagics(ip, self)
|
||||||
|
ip.register_magics(magics)
|
||||||
|
|
||||||
|
if shutdown_hook:
|
||||||
|
shutdown_hook.powerline = ref(self)
|
||||||
|
|
||||||
|
|
||||||
|
class PowerlinePrompts(Prompts):
|
||||||
|
'''Class that returns powerline prompts
|
||||||
|
'''
|
||||||
|
def __init__(self, shell):
|
||||||
|
shutdown_hook = ShutdownHook(shell)
|
||||||
|
powerline = ConfigurableIPythonPowerline(shell)
|
||||||
|
self.shell = shell
|
||||||
|
powerline.do_setup(shell, self, shutdown_hook)
|
||||||
|
self.last_output_count = None
|
||||||
|
self.last_output = {}
|
||||||
|
|
||||||
|
for prompt in ('in', 'continuation', 'rewrite', 'out'):
|
||||||
|
exec((
|
||||||
|
'def {0}_prompt_tokens(self, *args, **kwargs):\n'
|
||||||
|
' if self.last_output_count != self.shell.execution_count:\n'
|
||||||
|
' self.last_output.clear()\n'
|
||||||
|
' self.last_output_count = self.shell.execution_count\n'
|
||||||
|
' if "{0}" not in self.last_output:\n'
|
||||||
|
' self.last_output["{0}"] = self.powerline.render('
|
||||||
|
' side="left",'
|
||||||
|
' matcher_info="{1}",'
|
||||||
|
' segment_info=self.shell,'
|
||||||
|
' ) + [(Token.Generic.Prompt, " ")]\n'
|
||||||
|
' return self.last_output["{0}"]'
|
||||||
|
).format(prompt, 'in2' if prompt == 'continuation' else prompt))
|
BIN
powerline-bin/powerline/bindings/lemonbar/__pycache__/powerline-lemonbar.cpython-312.pyc
Normal file
BIN
powerline-bin/powerline/bindings/lemonbar/__pycache__/powerline-lemonbar.cpython-312.pyc
Normal file
Binary file not shown.
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import time
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from threading import Lock, Timer
|
||||||
|
|
||||||
|
from powerline.lemonbar import LemonbarPowerline
|
||||||
|
from powerline.commands.lemonbar import get_argparser
|
||||||
|
from powerline.bindings.wm import get_connected_xrandr_outputs
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = get_argparser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
powerline = LemonbarPowerline()
|
||||||
|
powerline.update_renderer()
|
||||||
|
bars = []
|
||||||
|
|
||||||
|
for screen in get_connected_xrandr_outputs(powerline.pl):
|
||||||
|
command = [args.bar_command, '-g', '{0}x{1}+{2}'.format(screen['width'], args.height, screen['x'])] + args.args[1:]
|
||||||
|
process = subprocess.Popen(command, stdin=subprocess.PIPE)
|
||||||
|
bars.append((screen['name'], process, int(screen['width']) / 5))
|
||||||
|
|
||||||
|
lock = Lock()
|
||||||
|
modes = ['default']
|
||||||
|
|
||||||
|
def render(reschedule=False):
|
||||||
|
if reschedule:
|
||||||
|
Timer(args.interval, render, kwargs={'reschedule': True}).start()
|
||||||
|
|
||||||
|
global lock
|
||||||
|
with lock:
|
||||||
|
for output, process, width in bars:
|
||||||
|
process.stdin.write(powerline.render(mode=modes[0], width=width, matcher_info=output).encode('utf-8') + b'\n')
|
||||||
|
process.stdin.flush()
|
||||||
|
|
||||||
|
def update(evt):
|
||||||
|
modes[0] = evt.change
|
||||||
|
render()
|
||||||
|
|
||||||
|
render(reschedule=True)
|
||||||
|
|
||||||
|
if args.i3:
|
||||||
|
try:
|
||||||
|
import i3ipc
|
||||||
|
except ImportError:
|
||||||
|
import i3
|
||||||
|
i3.Subscription(lambda evt, data, sub: render(), 'workspace')
|
||||||
|
else:
|
||||||
|
conn = i3ipc.Connection()
|
||||||
|
conn.on('workspace::focus', lambda conn, evt: render())
|
||||||
|
conn.on('mode', lambda conn, evt: update(evt))
|
||||||
|
conn.main()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(1e8)
|
183
powerline-bin/powerline/bindings/pdb/__init__.py
Normal file
183
powerline-bin/powerline/bindings/pdb/__init__.py
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import pdb
|
||||||
|
|
||||||
|
from powerline.pdb import PDBPowerline
|
||||||
|
from powerline.lib.encoding import get_preferred_output_encoding
|
||||||
|
from powerline.lib.unicode import unicode
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
# XXX The below classes make code compatible with PDBpp which uses pyrepl
|
||||||
|
# which does not expect unicode or something above ASCII. They are
|
||||||
|
# completely not needed if pdbpp is not used, but that’s not always the
|
||||||
|
# case.
|
||||||
|
class PowerlineRenderBytesResult(bytes):
|
||||||
|
def __new__(cls, s, encoding=None):
|
||||||
|
encoding = encoding or s.encoding
|
||||||
|
if isinstance(s, PowerlineRenderResult):
|
||||||
|
return s.encode(encoding)
|
||||||
|
self = bytes.__new__(cls, s.encode(encoding) if isinstance(s, unicode) else s)
|
||||||
|
self.encoding = encoding
|
||||||
|
return self
|
||||||
|
|
||||||
|
for meth in (
|
||||||
|
'__contains__',
|
||||||
|
'partition', 'rpartition',
|
||||||
|
'split', 'rsplit',
|
||||||
|
'count', 'join',
|
||||||
|
):
|
||||||
|
exec((
|
||||||
|
'def {0}(self, *args):\n'
|
||||||
|
' if any((isinstance(arg, unicode) for arg in args)):\n'
|
||||||
|
' return self.__unicode__().{0}(*args)\n'
|
||||||
|
' else:\n'
|
||||||
|
' return bytes.{0}(self, *args)'
|
||||||
|
).format(meth))
|
||||||
|
|
||||||
|
for meth in (
|
||||||
|
'find', 'rfind',
|
||||||
|
'index', 'rindex',
|
||||||
|
):
|
||||||
|
exec((
|
||||||
|
'def {0}(self, *args):\n'
|
||||||
|
' if any((isinstance(arg, unicode) for arg in args)):\n'
|
||||||
|
' args = [arg.encode(self.encoding) if isinstance(arg, unicode) else arg for arg in args]\n'
|
||||||
|
' return bytes.{0}(self, *args)'
|
||||||
|
).format(meth))
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.decode(self.encoding))
|
||||||
|
|
||||||
|
def __getitem__(self, *args):
|
||||||
|
return PowerlineRenderBytesResult(bytes.__getitem__(self, *args), encoding=self.encoding)
|
||||||
|
|
||||||
|
def __getslice__(self, *args):
|
||||||
|
return PowerlineRenderBytesResult(bytes.__getslice__(self, *args), encoding=self.encoding)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def add(encoding, *args):
|
||||||
|
if any((isinstance(arg, unicode) for arg in args)):
|
||||||
|
return PowerlineRenderResult(''.join((
|
||||||
|
arg
|
||||||
|
if isinstance(arg, unicode)
|
||||||
|
else arg.decode(encoding)
|
||||||
|
for arg in args
|
||||||
|
)), encoding)
|
||||||
|
else:
|
||||||
|
return PowerlineRenderBytesResult(b''.join(args), encoding=encoding)
|
||||||
|
|
||||||
|
def __add__(self, other):
|
||||||
|
return self.add(self.encoding, self, other)
|
||||||
|
|
||||||
|
def __radd__(self, other):
|
||||||
|
return self.add(self.encoding, other, self)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return PowerlineRenderResult(self)
|
||||||
|
|
||||||
|
class PowerlineRenderResult(unicode):
|
||||||
|
def __new__(cls, s, encoding=None):
|
||||||
|
encoding = (
|
||||||
|
encoding
|
||||||
|
or getattr(s, 'encoding', None)
|
||||||
|
or get_preferred_output_encoding()
|
||||||
|
)
|
||||||
|
if isinstance(s, unicode):
|
||||||
|
self = unicode.__new__(cls, s)
|
||||||
|
else:
|
||||||
|
self = unicode.__new__(cls, s, encoding, 'replace')
|
||||||
|
self.encoding = encoding
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return PowerlineRenderBytesResult(self)
|
||||||
|
|
||||||
|
def __getitem__(self, *args):
|
||||||
|
return PowerlineRenderResult(unicode.__getitem__(self, *args))
|
||||||
|
|
||||||
|
def __getslice__(self, *args):
|
||||||
|
return PowerlineRenderResult(unicode.__getslice__(self, *args))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def add(encoding, *args):
|
||||||
|
return PowerlineRenderResult(''.join((
|
||||||
|
arg
|
||||||
|
if isinstance(arg, unicode)
|
||||||
|
else arg.decode(encoding)
|
||||||
|
for arg in args
|
||||||
|
)), encoding)
|
||||||
|
|
||||||
|
def __add__(self, other):
|
||||||
|
return self.add(self.encoding, self, other)
|
||||||
|
|
||||||
|
def __radd__(self, other):
|
||||||
|
return self.add(self.encoding, other, self)
|
||||||
|
|
||||||
|
def encode(self, *args, **kwargs):
|
||||||
|
return PowerlineRenderBytesResult(unicode.encode(self, *args, **kwargs), args[0])
|
||||||
|
else:
|
||||||
|
PowerlineRenderResult = str
|
||||||
|
|
||||||
|
|
||||||
|
def use_powerline_prompt(cls):
|
||||||
|
'''Decorator that installs powerline prompt to the class
|
||||||
|
|
||||||
|
:param pdb.Pdb cls:
|
||||||
|
Class that should be decorated.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
``cls`` argument or a class derived from it. Latter is used to turn
|
||||||
|
old-style classes into new-style classes.
|
||||||
|
'''
|
||||||
|
@property
|
||||||
|
def prompt(self):
|
||||||
|
try:
|
||||||
|
powerline = self.powerline
|
||||||
|
except AttributeError:
|
||||||
|
powerline = PDBPowerline()
|
||||||
|
powerline.setup(self)
|
||||||
|
self.powerline = powerline
|
||||||
|
return PowerlineRenderResult(powerline.render(side='left'))
|
||||||
|
|
||||||
|
@prompt.setter
|
||||||
|
def prompt(self, _):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@prompt.deleter
|
||||||
|
def prompt(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not hasattr(cls, '__class__'):
|
||||||
|
# Old-style class: make it new-style or @property will not work.
|
||||||
|
old_cls = cls
|
||||||
|
|
||||||
|
class cls(cls, object):
|
||||||
|
__module__ = cls.__module__
|
||||||
|
__doc__ = cls.__doc__
|
||||||
|
|
||||||
|
cls.__name__ = old_cls.__name__
|
||||||
|
|
||||||
|
cls.prompt = prompt
|
||||||
|
|
||||||
|
return cls
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
'''Run module as a script
|
||||||
|
|
||||||
|
Uses :py:func:`pdb.main` function directly, but prior to that it mocks
|
||||||
|
:py:class:`pdb.Pdb` class with powerline-specific class instance.
|
||||||
|
'''
|
||||||
|
orig_pdb = pdb.Pdb
|
||||||
|
|
||||||
|
@use_powerline_prompt
|
||||||
|
class Pdb(pdb.Pdb, object):
|
||||||
|
def __init__(self):
|
||||||
|
orig_pdb.__init__(self)
|
||||||
|
|
||||||
|
pdb.Pdb = Pdb
|
||||||
|
|
||||||
|
return pdb.main()
|
9
powerline-bin/powerline/bindings/pdb/__main__.py
Normal file
9
powerline-bin/powerline/bindings/pdb/__main__.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
from powerline.bindings.pdb import main
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Binary file not shown.
Binary file not shown.
0
powerline-bin/powerline/bindings/qtile/__init__.py
Normal file
0
powerline-bin/powerline/bindings/qtile/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
61
powerline-bin/powerline/bindings/qtile/widget.py
Normal file
61
powerline-bin/powerline/bindings/qtile/widget.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
from libqtile.bar import CALCULATED
|
||||||
|
from libqtile.widget import TextBox
|
||||||
|
|
||||||
|
from powerline import Powerline
|
||||||
|
|
||||||
|
|
||||||
|
class QTilePowerline(Powerline):
|
||||||
|
def do_setup(self, obj):
|
||||||
|
obj.powerline = self
|
||||||
|
|
||||||
|
|
||||||
|
class PowerlineTextBox(TextBox):
|
||||||
|
# TODO Replace timeout argument with update_interval argument in next major
|
||||||
|
# release.
|
||||||
|
def __init__(self, timeout=2, text=b' ', width=CALCULATED, side='right', update_interval=None, **config):
|
||||||
|
super(PowerlineTextBox, self).__init__(text, width, **config)
|
||||||
|
self.side = side
|
||||||
|
self.update_interval = update_interval or timeout
|
||||||
|
self.did_run_timer_setup = False
|
||||||
|
powerline = QTilePowerline(ext='wm', renderer_module='pango_markup')
|
||||||
|
powerline.setup(self)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
if not self.configured:
|
||||||
|
return True
|
||||||
|
self.text = self.powerline.render(side=self.side).encode('utf-8')
|
||||||
|
self.bar.draw()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def cmd_update(self, text):
|
||||||
|
self.update(text)
|
||||||
|
|
||||||
|
def cmd_get(self):
|
||||||
|
return self.text
|
||||||
|
|
||||||
|
def timer_setup(self):
|
||||||
|
if not self.did_run_timer_setup:
|
||||||
|
self.did_run_timer_setup = True
|
||||||
|
self.timeout_add(self.update_interval, self.update)
|
||||||
|
|
||||||
|
def _configure(self, qtile, bar):
|
||||||
|
super(PowerlineTextBox, self)._configure(qtile, bar)
|
||||||
|
if self.layout.markup:
|
||||||
|
# QTile-0.9.1: no need to recreate layout or run timer_setup
|
||||||
|
return
|
||||||
|
self.layout = self.drawer.textlayout(
|
||||||
|
self.text,
|
||||||
|
self.foreground,
|
||||||
|
self.font,
|
||||||
|
self.fontsize,
|
||||||
|
self.fontshadow,
|
||||||
|
markup=True,
|
||||||
|
)
|
||||||
|
self.timer_setup()
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Remove this at next major release
|
||||||
|
Powerline = PowerlineTextBox
|
92
powerline-bin/powerline/bindings/rc/powerline.rc
Normal file
92
powerline-bin/powerline/bindings/rc/powerline.rc
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
fn _powerline_sigwinch {
|
||||||
|
_POWERLINE_COLUMNS = `{
|
||||||
|
stty size | cut -d' ' -f2
|
||||||
|
}
|
||||||
|
_powerline_tmux_setenv COLUMNS $_POWERLINE_COLUMNS
|
||||||
|
}
|
||||||
|
fn _powerline_update_pwd {
|
||||||
|
_POWERLINE_NEW_PWD = `{pwd}
|
||||||
|
if (test $^_POWERLINE_NEW_PWD '=' $^_POWERLINE_SAVED_PWD) {
|
||||||
|
_POWERLINE_SAVED_PWD = $_POWERLINE_NEW_PWD
|
||||||
|
_powerline_tmux_setenv PWD $_POWERLINE_SAVED_PWD
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn _powerline_continuation_prompt {
|
||||||
|
_powerline_prompt --renderer-arg 'local_theme=continuation' $*
|
||||||
|
}
|
||||||
|
fn _powerline_prompt {
|
||||||
|
$POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell aboveleft -r.readline --last-pipe-status $^_POWERLINE_STATUS --last-exit-code $_POWERLINE_STATUS($#_POWERLINE_STATUS) --jobnum $_POWERLINE_JOBNUM --renderer-arg 'client_id='$pid $*
|
||||||
|
}
|
||||||
|
fn _powerline_set_prompt {
|
||||||
|
_POWERLINE_STATUS = ( $status )
|
||||||
|
_POWERLINE_JOBNUM = $#apids
|
||||||
|
prompt = (``() {
|
||||||
|
_powerline_prompt
|
||||||
|
} ``() {
|
||||||
|
_powerline_continuation_prompt
|
||||||
|
})
|
||||||
|
_powerline_update_pwd
|
||||||
|
}
|
||||||
|
|
||||||
|
fn _powerline_common_setup {
|
||||||
|
fn sigwinch {
|
||||||
|
_powerline_sigwinch
|
||||||
|
}
|
||||||
|
_powerline_sigwinch
|
||||||
|
_POWERLINE_SAVED_PWD = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
fn _powerline_tmux_pane {
|
||||||
|
if (test -n $TMUX_PANE) {
|
||||||
|
echo $TMUX_PANE | tr -d ' %'
|
||||||
|
} else {
|
||||||
|
TMUX=$_POWERLINE_TMUX tmux display -p '#D' | tr -d ' %'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn _powerline_tmux_setenv {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test -z $POWERLINE_CONFIG_COMMAND) {
|
||||||
|
if (which powerline-config >/dev/null) {
|
||||||
|
POWERLINE_CONFIG_COMMAND = powerline-config
|
||||||
|
} else {
|
||||||
|
echo powerline-config executable not found, unable to proceed >[2=1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (test -n $POWERLINE_CONFIG_COMMAND) {
|
||||||
|
if ($POWERLINE_CONFIG_COMMAND shell --shell rcsh uses prompt) {
|
||||||
|
if (test -n $POWERLINE_COMMAND_ARGS) {
|
||||||
|
# Perform splitting
|
||||||
|
POWERLINE_COMMAND_ARGS=( `{echo $POWERLINE_COMMAND_ARGS} )
|
||||||
|
}
|
||||||
|
fn prompt {
|
||||||
|
_powerline_set_prompt
|
||||||
|
}
|
||||||
|
if (test -z $POWERLINE_SHELL_CONTINUATION$POWERLINE_RCSH_CONTINUATION) {
|
||||||
|
_POWERLINE_STATUS = 0
|
||||||
|
_POWERLINE_JOBNUM = 0
|
||||||
|
_POWERLINE_CONTINUATION = `{
|
||||||
|
_powerline_continuation_prompt
|
||||||
|
}
|
||||||
|
fn _powerline_continuation_prompt {
|
||||||
|
echo -n $_POWERLINE_CONTINUATION
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_powerline_common_setup
|
||||||
|
}
|
||||||
|
if (test -n $TMUX) {
|
||||||
|
if ($POWERLINE_CONFIG_COMMAND shell --shell rcsh uses tmux) {
|
||||||
|
_POWERLINE_TMUX=$TMUX
|
||||||
|
fn _powerline_tmux_setenv {
|
||||||
|
if (test -n $2) {
|
||||||
|
TMUX=$_POWERLINE_TMUX tmux setenv -g TMUX_$1^_`{
|
||||||
|
_powerline_tmux_pane
|
||||||
|
} $2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_powerline_common_setup
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# vim: ft=rcshell
|
239
powerline-bin/powerline/bindings/shell/powerline.sh
Normal file
239
powerline-bin/powerline/bindings/shell/powerline.sh
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
_POWERLINE_SOURCED="$_"
|
||||||
|
_powerline_columns_fallback() {
|
||||||
|
if which stty >/dev/null ; then
|
||||||
|
# Ksh does not have “local” built-in
|
||||||
|
_powerline_cols="$(stty size 2>/dev/null)"
|
||||||
|
if ! test -z "$_powerline_cols" ; then
|
||||||
|
echo "${_powerline_cols#* }"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo 0
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_has_jobs_in_subshell() {
|
||||||
|
if test -n "$_POWERLINE_HAS_JOBS_IN_SUBSHELL" ; then
|
||||||
|
return $_POWERLINE_HAS_JOBS_IN_SUBSHELL
|
||||||
|
elif test -z "$1" ; then
|
||||||
|
sleep 1 &
|
||||||
|
# Check whether shell outputs anything in a subshell when using jobs
|
||||||
|
# built-in. Shells like dash will not output anything meaning that
|
||||||
|
# I have to bother with temporary files.
|
||||||
|
test "$(jobs -p|wc -l)" -gt 0
|
||||||
|
else
|
||||||
|
case "$1" in
|
||||||
|
dash|bb|ash) return 1 ;;
|
||||||
|
mksh|ksh|bash) return 0 ;;
|
||||||
|
*) _powerline_has_jobs_in_subshell ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
_POWERLINE_HAS_JOBS_IN_SUBSHELL=$?
|
||||||
|
return $_POWERLINE_HAS_JOBS_IN_SUBSHELL
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_set_append_trap() {
|
||||||
|
if _powerline_has_jobs_in_subshell "$@" ; then
|
||||||
|
_powerline_append_trap() {
|
||||||
|
# Arguments: command, signal
|
||||||
|
# Ksh does not have “local” built-in
|
||||||
|
_powerline_traps="$(trap)"
|
||||||
|
if echo "$_powerline_traps" | grep -cm1 $2'$' >/dev/null ; then
|
||||||
|
_powerline_traps="$(echo "$_powerline_traps" | sed "s/ $2/'\\n$1' $2/")"
|
||||||
|
eval "$_powerline_traps"
|
||||||
|
else
|
||||||
|
trap "$1" $2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_powerline_append_trap() {
|
||||||
|
# Arguments: command, signal
|
||||||
|
_powerline_create_temp
|
||||||
|
trap > $_POWERLINE_TEMP
|
||||||
|
if grep -cm1 $2'$' $_POWERLINE_TEMP >/dev/null ; then
|
||||||
|
sed -i -e "s/ $2/'\\n$1' $2/"
|
||||||
|
. $_POWERLINE_TEMP
|
||||||
|
else
|
||||||
|
trap "$1" $2
|
||||||
|
fi
|
||||||
|
echo -n > $_POWERLINE_TEMP
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
_powerline_set_append_trap() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_create_temp() {
|
||||||
|
if test -z "$_POWERLINE_TEMP" || ! test -e "$_POWERLINE_TEMP" ; then
|
||||||
|
_POWERLINE_TEMP="$(mktemp "${TMPDIR:-/tmp}/powerline.XXXXXXXX")"
|
||||||
|
_powerline_append_trap 'rm $_POWERLINE_TEMP' EXIT
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_set_set_jobs() {
|
||||||
|
if _powerline_has_jobs_in_subshell "$@" ; then
|
||||||
|
_powerline_set_jobs() {
|
||||||
|
_POWERLINE_JOBS="$(jobs -p|wc -l|tr -d ' ')"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_powerline_set_append_trap "$@"
|
||||||
|
_POWERLINE_PID=$$
|
||||||
|
_powerline_append_trap '_powerline_do_set_jobs' USR1
|
||||||
|
_powerline_do_set_jobs() {
|
||||||
|
_powerline_create_temp
|
||||||
|
jobs -p > $_POWERLINE_TEMP
|
||||||
|
}
|
||||||
|
# This command will always be launched from a subshell, thus a hack is
|
||||||
|
# needed to run `jobs -p` outside of the subshell.
|
||||||
|
_powerline_set_jobs() {
|
||||||
|
kill -USR1 $_POWERLINE_PID
|
||||||
|
# Note: most likely this will read data from the previous run. Tests
|
||||||
|
# show that it is OK for some reasons.
|
||||||
|
_POWERLINE_JOBS="$(wc -l < $_POWERLINE_TEMP | tr -d ' ')"
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
_powerline_set_set_jobs() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_set_command() {
|
||||||
|
if test -z "${POWERLINE_COMMAND}" ; then
|
||||||
|
POWERLINE_COMMAND="$("$POWERLINE_CONFIG_COMMAND" shell command)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_pane() {
|
||||||
|
echo "${TMUX_PANE:-`TMUX="$_POWERLINE_TMUX" tmux display -p "#D"`}" | \
|
||||||
|
tr -d ' %'
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_setenv() {
|
||||||
|
TMUX="$_POWERLINE_TMUX" tmux setenv -g TMUX_"$1"_`_powerline_tmux_pane` "$2"
|
||||||
|
TMUX="$_POWERLINE_TMUX" tmux refresh -S
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_set_pwd() {
|
||||||
|
if test "$_POWERLINE_SAVED_PWD" != "$PWD" ; then
|
||||||
|
_POWERLINE_SAVED_PWD="$PWD"
|
||||||
|
_powerline_tmux_setenv PWD "$PWD"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_set_columns() {
|
||||||
|
_powerline_tmux_setenv COLUMNS "${COLUMNS:-$(_powerline_columns_fallback)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_set_renderer_arg() {
|
||||||
|
case "$1" in
|
||||||
|
bb|ash) _POWERLINE_RENDERER_ARG="-r .bash" ;;
|
||||||
|
mksh|ksh) _POWERLINE_RENDERER_ARG="-r .ksh" ;;
|
||||||
|
bash|dash) _POWERLINE_RENDERER_ARG= ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_set_jobs() {
|
||||||
|
_powerline_set_set_jobs
|
||||||
|
_powerline_set_jobs
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_local_prompt() {
|
||||||
|
# Arguments: side, exit_code, local theme
|
||||||
|
_powerline_set_jobs
|
||||||
|
"$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS shell $1 \
|
||||||
|
$_POWERLINE_RENDERER_ARG \
|
||||||
|
--renderer-arg="client_id=$$" \
|
||||||
|
--last-exit-code=$2 \
|
||||||
|
--jobnum=$_POWERLINE_JOBS \
|
||||||
|
--renderer-arg="local_theme=$3"
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_prompt() {
|
||||||
|
# Arguments: side, exit_code
|
||||||
|
_powerline_set_jobs
|
||||||
|
"$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS shell $1 \
|
||||||
|
--width="${COLUMNS:-$(_powerline_columns_fallback)}" \
|
||||||
|
$_POWERLINE_RENDERER_ARG \
|
||||||
|
--renderer-arg="client_id=$$" \
|
||||||
|
--last-exit-code=$2 \
|
||||||
|
--jobnum=$_POWERLINE_JOBS
|
||||||
|
_powerline_update_psN
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_setup_psN() {
|
||||||
|
case "$1" in
|
||||||
|
mksh|ksh|bash)
|
||||||
|
_POWERLINE_PID=$$
|
||||||
|
_powerline_update_psN() {
|
||||||
|
kill -USR1 $_POWERLINE_PID
|
||||||
|
}
|
||||||
|
# No command substitution in PS2 and PS3
|
||||||
|
_powerline_set_psN() {
|
||||||
|
if test -n "$POWERLINE_SHELL_CONTINUATION" ; then
|
||||||
|
PS2="$(_powerline_local_prompt left $? continuation)"
|
||||||
|
fi
|
||||||
|
if test -n "$POWERLINE_SHELL_SELECT" ; then
|
||||||
|
PS3="$(_powerline_local_prompt left $? select)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
_powerline_append_trap '_powerline_set_psN' USR1
|
||||||
|
_powerline_set_psN
|
||||||
|
;;
|
||||||
|
bb|ash|dash)
|
||||||
|
_powerline_update_psN() {
|
||||||
|
# Do nothing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PS2='$(_powerline_local_prompt left $? continuation)'
|
||||||
|
# No select support
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_setup_prompt() {
|
||||||
|
VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||||
|
_powerline_set_append_trap "$@"
|
||||||
|
_powerline_set_set_jobs "$@"
|
||||||
|
_powerline_set_command "$@"
|
||||||
|
_powerline_set_renderer_arg "$@"
|
||||||
|
PS1='$(_powerline_prompt aboveleft $?)'
|
||||||
|
PS2="$(_powerline_local_prompt left 0 continuation)"
|
||||||
|
PS3="$(_powerline_local_prompt left 0 select)"
|
||||||
|
_powerline_setup_psN "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_init_tmux_support() {
|
||||||
|
# Dash does not have &>/dev/null
|
||||||
|
if test -n "$TMUX" && tmux refresh -S >/dev/null 2>/dev/null ; then
|
||||||
|
# TMUX variable may be unset to create new tmux session inside this one
|
||||||
|
_POWERLINE_TMUX="$TMUX"
|
||||||
|
|
||||||
|
_powerline_set_append_trap "$@"
|
||||||
|
|
||||||
|
# If _powerline_tmux_set_pwd is used before _powerline_prompt it sets $?
|
||||||
|
# to zero in ksh.
|
||||||
|
PS1="$PS1"'$(_powerline_tmux_set_pwd)'
|
||||||
|
_powerline_append_trap '_powerline_tmux_set_columns' WINCH
|
||||||
|
_powerline_tmux_set_columns
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if test -z "${POWERLINE_CONFIG_COMMAND}" ; then
|
||||||
|
if which powerline-config >/dev/null ; then
|
||||||
|
POWERLINE_CONFIG_COMMAND=powerline-config
|
||||||
|
else
|
||||||
|
POWERLINE_CONFIG_COMMAND="$(dirname "$_POWERLINE_SOURCED")/../../../scripts/powerline-config"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Strips the leading `-`: it may be present when shell is a login shell
|
||||||
|
_POWERLINE_USED_SHELL=${0#-}
|
||||||
|
_POWERLINE_USED_SHELL=${_POWERLINE_USED_SHELL##*/}
|
||||||
|
|
||||||
|
if "${POWERLINE_CONFIG_COMMAND}" shell uses tmux ; then
|
||||||
|
_powerline_init_tmux_support $_POWERLINE_USED_SHELL
|
||||||
|
fi
|
||||||
|
if "${POWERLINE_CONFIG_COMMAND}" shell --shell=bash uses prompt ; then
|
||||||
|
_powerline_setup_prompt $_POWERLINE_USED_SHELL
|
||||||
|
fi
|
60
powerline-bin/powerline/bindings/tcsh/powerline.tcsh
Normal file
60
powerline-bin/powerline/bindings/tcsh/powerline.tcsh
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# http://unix.stackexchange.com/questions/4650/determining-path-to-sourced-shell-script:
|
||||||
|
# > In tcsh, $_ at the beginning of the script will contain the location if the
|
||||||
|
# > file was sourced and $0 contains it if it was run.
|
||||||
|
#
|
||||||
|
# Guess this relies on `$_` being set as to last argument to previous command
|
||||||
|
# which must be `.` or `source` in this case
|
||||||
|
set POWERLINE_SOURCED=($_)
|
||||||
|
if ! $?POWERLINE_CONFIG_COMMAND then
|
||||||
|
if ( { which powerline-config > /dev/null } ) then
|
||||||
|
set POWERLINE_CONFIG_COMMAND="powerline-config"
|
||||||
|
else
|
||||||
|
set POWERLINE_CONFIG_COMMAND="$POWERLINE_SOURCED[2]:h:h:h:h/scripts/powerline-config"
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
if "$POWERLINE_CONFIG_COMMAND" == "" then
|
||||||
|
if ( { which powerline-config > /dev/null } ) then
|
||||||
|
set POWERLINE_CONFIG_COMMAND="powerline-config"
|
||||||
|
else
|
||||||
|
set POWERLINE_CONFIG_COMMAND="$POWERLINE_SOURCED[2]:h:h:h:h/scripts/powerline-config"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
if ( { $POWERLINE_CONFIG_COMMAND shell --shell=tcsh uses tmux } ) then
|
||||||
|
if ( $?TMUX_PANE ) then
|
||||||
|
if ( "$TMUX_PANE" == "" ) then
|
||||||
|
set _POWERLINE_TMUX_PANE="`tmux display -p '#D'`"
|
||||||
|
else
|
||||||
|
set _POWERLINE_TMUX_PANE="$TMUX_PANE"
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
set _POWERLINE_TMUX_PANE="`tmux display -p '#D'`"
|
||||||
|
endif
|
||||||
|
set _POWERLINE_TMUX_PANE="`echo $_POWERLINE_TMUX_PANE:q | tr -d '% '`"
|
||||||
|
alias _powerline_tmux_set_pwd 'if ( $?TMUX && { tmux refresh -S >&/dev/null } ) tmux setenv -g TMUX_PWD_$_POWERLINE_TMUX_PANE $PWD:q ; if ( $?TMUX ) tmux refresh -S >&/dev/null'
|
||||||
|
alias cwdcmd "`alias cwdcmd` ; _powerline_tmux_set_pwd"
|
||||||
|
endif
|
||||||
|
if ( { $POWERLINE_CONFIG_COMMAND shell --shell=tcsh uses prompt } ) then
|
||||||
|
if ! $?POWERLINE_COMMAND then
|
||||||
|
set POWERLINE_COMMAND="`$POWERLINE_CONFIG_COMMAND:q shell command`"
|
||||||
|
else
|
||||||
|
if "$POWERLINE_COMMAND" == "" then
|
||||||
|
set POWERLINE_COMMAND="`$POWERLINE_CONFIG_COMMAND:q shell command`"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
if ! $?POWERLINE_COMMAND_ARGS then
|
||||||
|
set POWERLINE_COMMAND_ARGS=""
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ( $?POWERLINE_NO_TCSH_ABOVE || $?POWERLINE_NO_SHELL_ABOVE ) then
|
||||||
|
alias _powerline_above true
|
||||||
|
else
|
||||||
|
alias _powerline_above '$POWERLINE_COMMAND:q $POWERLINE_COMMAND_ARGS shell above --renderer-arg=client_id=$$ --last-exit-code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS'
|
||||||
|
endif
|
||||||
|
|
||||||
|
alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND:q $POWERLINE_COMMAND_ARGS shell left -r .tcsh --renderer-arg=client_id=$$ --last-exit-code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS`"'
|
||||||
|
alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND:q $POWERLINE_COMMAND_ARGS shell right -r .tcsh --renderer-arg=client_id=$$ --last-exit-code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS`"'
|
||||||
|
alias _powerline_set_columns 'set POWERLINE_COLUMNS=`stty size|cut -d" " -f2` ; set POWERLINE_COLUMNS=`expr $POWERLINE_COLUMNS - 2`'
|
||||||
|
|
||||||
|
alias precmd 'set POWERLINE_STATUS=$? ; '"`alias precmd`"' ; _powerline_set_columns ; _powerline_above ; _powerline_set_prompt ; _powerline_set_rprompt'
|
||||||
|
endif
|
84
powerline-bin/powerline/bindings/tmux/__init__.py
Normal file
84
powerline-bin/powerline/bindings/tmux/__init__.py
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import re
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from powerline.lib.shell import run_cmd
|
||||||
|
|
||||||
|
|
||||||
|
TmuxVersionInfo = namedtuple('TmuxVersionInfo', ('major', 'minor', 'suffix'))
|
||||||
|
|
||||||
|
|
||||||
|
def get_tmux_executable_name():
|
||||||
|
'''Returns tmux executable name
|
||||||
|
|
||||||
|
It should be defined in POWERLINE_TMUX_EXE environment variable, otherwise
|
||||||
|
it is simply “tmux”.
|
||||||
|
'''
|
||||||
|
|
||||||
|
return os.environ.get('POWERLINE_TMUX_EXE', 'tmux')
|
||||||
|
|
||||||
|
|
||||||
|
def _run_tmux(runner, args):
|
||||||
|
return runner([get_tmux_executable_name()] + list(args))
|
||||||
|
|
||||||
|
|
||||||
|
def run_tmux_command(*args):
|
||||||
|
'''Run tmux command, ignoring the output'''
|
||||||
|
_run_tmux(subprocess.check_call, args)
|
||||||
|
|
||||||
|
|
||||||
|
def get_tmux_output(pl, *args):
|
||||||
|
'''Run tmux command and return its output'''
|
||||||
|
return _run_tmux(lambda cmd: run_cmd(pl, cmd), args)
|
||||||
|
|
||||||
|
|
||||||
|
def set_tmux_environment(varname, value, remove=True):
|
||||||
|
'''Set tmux global environment variable
|
||||||
|
|
||||||
|
:param str varname:
|
||||||
|
Name of the variable to set.
|
||||||
|
:param str value:
|
||||||
|
Variable value.
|
||||||
|
:param bool remove:
|
||||||
|
True if variable should be removed from the environment prior to
|
||||||
|
attaching any client (runs ``tmux set-environment -r {varname}``).
|
||||||
|
'''
|
||||||
|
run_tmux_command('set-environment', '-g', varname, value)
|
||||||
|
if remove:
|
||||||
|
try:
|
||||||
|
run_tmux_command('set-environment', '-r', varname)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
# On tmux-2.0 this command may fail for whatever reason. Since it is
|
||||||
|
# critical just ignore the failure.
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def source_tmux_file(fname):
|
||||||
|
'''Source tmux configuration file
|
||||||
|
|
||||||
|
:param str fname:
|
||||||
|
Full path to the sourced file.
|
||||||
|
'''
|
||||||
|
run_tmux_command('source', fname)
|
||||||
|
|
||||||
|
|
||||||
|
NON_DIGITS = re.compile('[^0-9]+')
|
||||||
|
DIGITS = re.compile('[0-9]+')
|
||||||
|
NON_LETTERS = re.compile('[^a-z]+')
|
||||||
|
|
||||||
|
|
||||||
|
def get_tmux_version(pl):
|
||||||
|
version_string = get_tmux_output(pl, '-V')
|
||||||
|
_, version_string = version_string.split(' ')
|
||||||
|
version_string = version_string.strip()
|
||||||
|
if version_string == 'master':
|
||||||
|
return TmuxVersionInfo(float('inf'), 0, version_string)
|
||||||
|
major, minor = version_string.split('.')
|
||||||
|
suffix = DIGITS.subn('', minor)[0] or None
|
||||||
|
minor = NON_DIGITS.subn('', minor)[0]
|
||||||
|
return TmuxVersionInfo(int(major), int(minor), suffix)
|
Binary file not shown.
11
powerline-bin/powerline/bindings/tmux/powerline-base.conf
Normal file
11
powerline-bin/powerline/bindings/tmux/powerline-base.conf
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
set -g status on
|
||||||
|
set -g status-interval 2
|
||||||
|
set -g status-left-length 20
|
||||||
|
set -g status-right '#(env "$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS tmux right -R pane_id=\"`tmux display -p "#""D"`\")'
|
||||||
|
set -g status-right-length 150
|
||||||
|
set -g window-status-format "#[$_POWERLINE_WINDOW_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER_SPACES#I#F #[$_POWERLINE_WINDOW_DIVIDER_COLOR]$_POWERLINE_LEFT_SOFT_DIVIDER#[default]#W $_POWERLINE_LEFT_HARD_DIVIDER_SPACES"
|
||||||
|
set -g window-status-current-format "#[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#[$_POWERLINE_WINDOW_CURRENT_COLOR]#I#F $_POWERLINE_LEFT_SOFT_DIVIDER#[$_POWERLINE_WINDOW_NAME_COLOR]#W #[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER"
|
||||||
|
|
||||||
|
# Legacy status-left definition to be overwritten for tmux Versions 1.8+
|
||||||
|
set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left -R pane_id=\"`tmux display -p '#''D'`\")"
|
||||||
|
# vim: ft=tmux
|
2
powerline-bin/powerline/bindings/tmux/powerline.conf
Normal file
2
powerline-bin/powerline/bindings/tmux/powerline.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
if-shell 'env "$POWERLINE_CONFIG_COMMAND" tmux setup' '' 'run-shell "powerline-config tmux setup"'
|
||||||
|
# vim: ft=tmux
|
@ -0,0 +1,3 @@
|
|||||||
|
set -g status-right '#(env "$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS tmux right -R pane_id="`tmux display -p "#""D"`" --width=`tmux display -p "#""{client_width}"` -R width_adjust=`tmux show-options -g status-left-length | cut -d" " -f 2`)'
|
||||||
|
set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left --width=`tmux display -p '#''{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=\"`tmux display -p '#''D'`\")"
|
||||||
|
# vim: ft=tmux
|
@ -0,0 +1,5 @@
|
|||||||
|
# powerline_tmux_1.8.conf
|
||||||
|
# tmux Version 1.8 introduces window-status-last-{attr,bg,fg}, which is
|
||||||
|
# deprecated for versions 1.9+, thus only applicable to version 1.8.
|
||||||
|
set -qg window-status-last-fg "$_POWERLINE_ACTIVE_WINDOW_FG"
|
||||||
|
# vim: ft=tmux
|
@ -0,0 +1,11 @@
|
|||||||
|
# powerline_tmux_legacy_common.conf
|
||||||
|
# tmux Version 1.8 and earlier (legacy) common options. The foo-{attr,bg,fg}
|
||||||
|
# options are deprecated starting with tmux Version 1.9.
|
||||||
|
set -g status-fg "$_POWERLINE_BACKGROUND_FG"
|
||||||
|
set -g status-bg "$_POWERLINE_BACKGROUND_BG"
|
||||||
|
set-window-option -g window-status-fg "$_POWERLINE_WINDOW_STATUS_FG"
|
||||||
|
set-window-option -g window-status-activity-attr "$_POWERLINE_ACTIVITY_STATUS_ATTR_LEGACY"
|
||||||
|
set-window-option -g window-status-bell-attr "$_POWERLINE_BELL_STATUS_ATTR_LEGACY"
|
||||||
|
set-window-option -g window-status-activity-fg "$_POWERLINE_ACTIVITY_STATUS_FG"
|
||||||
|
set-window-option -g window-status-bell-fg "$_POWERLINE_BELL_STATUS_FG"
|
||||||
|
# vim: ft=tmux
|
@ -0,0 +1,5 @@
|
|||||||
|
# powerline_tmux_1.8_plus.conf
|
||||||
|
# tmux Version 1.8 introduces the 'client_prefix' format variable, applicable
|
||||||
|
# for versions 1.8+
|
||||||
|
set -qg status-left "#{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_FG]#[bg=$_POWERLINE_SESSION_PREFIX_BG]#[$_POWERLINE_SESSION_PREFIX_ATTR],#[fg=$_POWERLINE_SESSION_FG]#[bg=$_POWERLINE_SESSION_BG]#[$_POWERLINE_SESSION_ATTR]} #S #{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_BG],#[fg=$_POWERLINE_SESSION_BG]}#[bg=$_POWERLINE_BACKGROUND_BG]#[nobold]$_POWERLINE_LEFT_HARD_DIVIDER#(env \$POWERLINE_COMMAND \$POWERLINE_COMMAND_ARGS tmux left --width=`tmux display -p '#''{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=\"`tmux display -p '#''D'`\")"
|
||||||
|
# vim: ft=tmux
|
@ -0,0 +1,8 @@
|
|||||||
|
# powerline_tmux_1.9_plus.conf
|
||||||
|
# Version 1.9 introduces the foo-style options, applicable to version 1.9+
|
||||||
|
set-option -qg status-style "$_POWERLINE_BACKGROUND_COLOR"
|
||||||
|
set-option -qg window-status-last-style "$_POWERLINE_ACTIVE_WINDOW_STATUS_COLOR"
|
||||||
|
set-window-option -qg window-status-style "$_POWERLINE_WINDOW_STATUS_COLOR"
|
||||||
|
set-window-option -qg window-status-activity-style "$_POWERLINE_ACTIVITY_STATUS_COLOR"
|
||||||
|
set-window-option -qg window-status-bell-style "$_POWERLINE_BELL_STATUS_COLOR"
|
||||||
|
# vim: ft=tmux
|
@ -0,0 +1,3 @@
|
|||||||
|
# Starting from tmux-2.1 escaping of dollar signs inside #() is harmful
|
||||||
|
set -qg status-left "#{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_FG]#[bg=$_POWERLINE_SESSION_PREFIX_BG]#[$_POWERLINE_SESSION_PREFIX_ATTR],#[fg=$_POWERLINE_SESSION_FG]#[bg=$_POWERLINE_SESSION_BG]#[$_POWERLINE_SESSION_ATTR]} #S #{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_BG],#[fg=$_POWERLINE_SESSION_BG]}#[bg=$_POWERLINE_BACKGROUND_BG]#[nobold]$_POWERLINE_LEFT_HARD_DIVIDER#(env $POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS tmux left --width=`tmux display -p '#''{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=\"`tmux display -p '#''D'`\")"
|
||||||
|
set -g window-status-format "#[$_POWERLINE_WINDOW_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER_SPACES#I#{?window_flags,#F, } #[$_POWERLINE_WINDOW_DIVIDER_COLOR]$_POWERLINE_LEFT_SOFT_DIVIDER#[default]#W $_POWERLINE_LEFT_HARD_DIVIDER_SPACES"
|
482
powerline-bin/powerline/bindings/vim/__init__.py
Normal file
482
powerline-bin/powerline/bindings/vim/__init__.py
Normal file
@ -0,0 +1,482 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import codecs
|
||||||
|
|
||||||
|
try:
|
||||||
|
import vim
|
||||||
|
except ImportError:
|
||||||
|
vim = object()
|
||||||
|
|
||||||
|
from powerline.lib.unicode import unicode
|
||||||
|
|
||||||
|
|
||||||
|
if (
|
||||||
|
hasattr(vim, 'options')
|
||||||
|
and hasattr(vim, 'vvars')
|
||||||
|
and vim.vvars['version'] > 703
|
||||||
|
):
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
def get_vim_encoding():
|
||||||
|
return vim.options['encoding'] or 'ascii'
|
||||||
|
else:
|
||||||
|
def get_vim_encoding():
|
||||||
|
return vim.options['encoding'].decode('ascii') or 'ascii'
|
||||||
|
elif hasattr(vim, 'eval'):
|
||||||
|
def get_vim_encoding():
|
||||||
|
return vim.eval('&encoding') or 'ascii'
|
||||||
|
else:
|
||||||
|
def get_vim_encoding():
|
||||||
|
return 'utf-8'
|
||||||
|
|
||||||
|
get_vim_encoding.__doc__ = (
|
||||||
|
'''Get encoding used for Vim strings
|
||||||
|
|
||||||
|
:return:
|
||||||
|
Value of ``&encoding``. If it is empty (i.e. Vim is compiled
|
||||||
|
without +multibyte) returns ``'ascii'``. When building documentation
|
||||||
|
outputs ``'utf-8'`` unconditionally.
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
vim_encoding = get_vim_encoding()
|
||||||
|
|
||||||
|
|
||||||
|
python_to_vim_types = {
|
||||||
|
unicode: (
|
||||||
|
lambda o: b'\'' + (o.translate({
|
||||||
|
ord('\''): '\'\'',
|
||||||
|
}).encode(vim_encoding)) + b'\''
|
||||||
|
),
|
||||||
|
list: (
|
||||||
|
lambda o: b'[' + (
|
||||||
|
b','.join((python_to_vim(i) for i in o))
|
||||||
|
) + b']'
|
||||||
|
),
|
||||||
|
bytes: (lambda o: b'\'' + o.replace(b'\'', b'\'\'') + b'\''),
|
||||||
|
int: (str if str is bytes else (lambda o: unicode(o).encode('ascii'))),
|
||||||
|
}
|
||||||
|
python_to_vim_types[float] = python_to_vim_types[int]
|
||||||
|
|
||||||
|
|
||||||
|
def python_to_vim(o):
|
||||||
|
return python_to_vim_types[type(o)](o)
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
def str_to_bytes(s):
|
||||||
|
return s
|
||||||
|
|
||||||
|
def unicode_eval(expr):
|
||||||
|
ret = vim.eval(expr)
|
||||||
|
return ret.decode(vim_encoding, 'powerline_vim_strtrans_error')
|
||||||
|
else:
|
||||||
|
def str_to_bytes(s):
|
||||||
|
return s.encode(vim_encoding)
|
||||||
|
|
||||||
|
def unicode_eval(expr):
|
||||||
|
return vim.eval(expr)
|
||||||
|
|
||||||
|
|
||||||
|
def safe_bytes_eval(expr):
|
||||||
|
return bytes(bytearray((
|
||||||
|
int(chunk) for chunk in (
|
||||||
|
vim.eval(
|
||||||
|
b'substitute(' + expr + b', ' +
|
||||||
|
b'\'^.*$\', \'\\=join(map(range(len(submatch(0))), ' +
|
||||||
|
b'"char2nr(submatch(0)[v:val])"))\', "")'
|
||||||
|
).split()
|
||||||
|
)
|
||||||
|
)))
|
||||||
|
|
||||||
|
|
||||||
|
def eval_bytes(expr):
|
||||||
|
try:
|
||||||
|
return str_to_bytes(vim.eval(expr))
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
return safe_bytes_eval(expr)
|
||||||
|
|
||||||
|
|
||||||
|
def eval_unicode(expr):
|
||||||
|
try:
|
||||||
|
return unicode_eval(expr)
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
return safe_bytes_eval(expr).decode(vim_encoding, 'powerline_vim_strtrans_error')
|
||||||
|
|
||||||
|
|
||||||
|
if hasattr(vim, 'bindeval'):
|
||||||
|
rettype_func = {
|
||||||
|
None: lambda f: f,
|
||||||
|
'unicode': (
|
||||||
|
lambda f: (
|
||||||
|
lambda *args, **kwargs: (
|
||||||
|
f(*args, **kwargs).decode(
|
||||||
|
vim_encoding, 'powerline_vim_strtrans_error'
|
||||||
|
))))
|
||||||
|
}
|
||||||
|
rettype_func['int'] = rettype_func['bytes'] = rettype_func[None]
|
||||||
|
rettype_func['str'] = rettype_func['bytes'] if str is bytes else rettype_func['unicode']
|
||||||
|
|
||||||
|
def vim_get_func(f, rettype=None):
|
||||||
|
'''Return a vim function binding.'''
|
||||||
|
try:
|
||||||
|
func = vim.bindeval('function("' + f + '")')
|
||||||
|
except vim.error:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return rettype_func[rettype](func)
|
||||||
|
else:
|
||||||
|
rettype_eval = {
|
||||||
|
None: getattr(vim, 'eval', None),
|
||||||
|
'int': lambda expr: int(vim.eval(expr)),
|
||||||
|
'bytes': eval_bytes,
|
||||||
|
'unicode': eval_unicode,
|
||||||
|
}
|
||||||
|
rettype_eval['str'] = rettype_eval[None]
|
||||||
|
|
||||||
|
class VimFunc(object):
|
||||||
|
'''Evaluate a vim function using vim.eval().
|
||||||
|
|
||||||
|
This is a fallback class for older vim versions.
|
||||||
|
'''
|
||||||
|
__slots__ = ('f', 'eval')
|
||||||
|
|
||||||
|
def __init__(self, f, rettype=None):
|
||||||
|
self.f = f.encode('utf-8')
|
||||||
|
self.eval = rettype_eval[rettype]
|
||||||
|
|
||||||
|
def __call__(self, *args):
|
||||||
|
return self.eval(self.f + b'(' + (b','.join((
|
||||||
|
python_to_vim(o) for o in args
|
||||||
|
))) + b')')
|
||||||
|
|
||||||
|
vim_get_func = VimFunc
|
||||||
|
|
||||||
|
|
||||||
|
def vim_get_autoload_func(f, rettype=None):
|
||||||
|
func = vim_get_func(f)
|
||||||
|
if not func:
|
||||||
|
vim.command('runtime! ' + f.replace('#', '/')[:f.rindex('#')] + '.vim')
|
||||||
|
func = vim_get_func(f)
|
||||||
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
if hasattr(vim, 'Function'):
|
||||||
|
def vim_func_exists(f):
|
||||||
|
try:
|
||||||
|
vim.Function(f)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
def vim_func_exists(f):
|
||||||
|
try:
|
||||||
|
return bool(int(vim.eval('exists("*{0}")'.format(f))))
|
||||||
|
except vim.error:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
if type(vim) is object:
|
||||||
|
vim_get_func = lambda *args, **kwargs: None
|
||||||
|
|
||||||
|
|
||||||
|
_getbufvar = vim_get_func('getbufvar')
|
||||||
|
_vim_exists = vim_get_func('exists', rettype='int')
|
||||||
|
|
||||||
|
|
||||||
|
# It may crash on some old vim versions and I do not remember in which patch
|
||||||
|
# I fixed this crash.
|
||||||
|
if hasattr(vim, 'vvars') and vim.vvars[str('version')] > 703:
|
||||||
|
_vim_to_python_types = {
|
||||||
|
getattr(vim, 'Dictionary', None) or type(vim.bindeval('{}')):
|
||||||
|
lambda value: dict((
|
||||||
|
(_vim_to_python(k), _vim_to_python(v))
|
||||||
|
for k, v in value.items()
|
||||||
|
)),
|
||||||
|
getattr(vim, 'List', None) or type(vim.bindeval('[]')):
|
||||||
|
lambda value: [_vim_to_python(item) for item in value],
|
||||||
|
getattr(vim, 'Function', None) or type(vim.bindeval('function("mode")')):
|
||||||
|
lambda _: None,
|
||||||
|
}
|
||||||
|
|
||||||
|
def vim_getvar(varname):
|
||||||
|
return _vim_to_python(vim.vars[str(varname)])
|
||||||
|
|
||||||
|
def bufvar_exists(buffer, varname):
|
||||||
|
buffer = buffer or vim.current.buffer
|
||||||
|
return varname in buffer.vars
|
||||||
|
|
||||||
|
def vim_getwinvar(segment_info, varname):
|
||||||
|
return _vim_to_python(segment_info['window'].vars[str(varname)])
|
||||||
|
|
||||||
|
def vim_global_exists(name):
|
||||||
|
try:
|
||||||
|
vim.vars[name]
|
||||||
|
except KeyError:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
_vim_to_python_types = {
|
||||||
|
dict: (lambda value: dict(((k, _vim_to_python(v)) for k, v in value.items()))),
|
||||||
|
list: (lambda value: [_vim_to_python(i) for i in value]),
|
||||||
|
}
|
||||||
|
|
||||||
|
def vim_getvar(varname):
|
||||||
|
varname = 'g:' + varname
|
||||||
|
if _vim_exists(varname):
|
||||||
|
return vim.eval(varname)
|
||||||
|
else:
|
||||||
|
raise KeyError(varname)
|
||||||
|
|
||||||
|
def bufvar_exists(buffer, varname):
|
||||||
|
if not buffer or buffer.number == vim.current.buffer.number:
|
||||||
|
return int(vim.eval('exists("b:{0}")'.format(varname)))
|
||||||
|
else:
|
||||||
|
return int(vim.eval(
|
||||||
|
'has_key(getbufvar({0}, ""), {1})'.format(buffer.number, varname)
|
||||||
|
))
|
||||||
|
|
||||||
|
def vim_getwinvar(segment_info, varname):
|
||||||
|
result = vim.eval('getwinvar({0}, "{1}")'.format(segment_info['winnr'], varname))
|
||||||
|
if result == '':
|
||||||
|
if not int(vim.eval('has_key(getwinvar({0}, ""), "{1}")'.format(segment_info['winnr'], varname))):
|
||||||
|
raise KeyError(varname)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def vim_global_exists(name):
|
||||||
|
return int(vim.eval('exists("g:' + name + '")'))
|
||||||
|
|
||||||
|
|
||||||
|
def vim_command_exists(name):
|
||||||
|
return _vim_exists(':' + name)
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
getbufvar = _getbufvar
|
||||||
|
else:
|
||||||
|
_vim_to_python_types[bytes] = lambda value: value.decode(vim_encoding)
|
||||||
|
|
||||||
|
def getbufvar(*args):
|
||||||
|
return _vim_to_python(_getbufvar(*args))
|
||||||
|
|
||||||
|
|
||||||
|
_id = lambda value: value
|
||||||
|
|
||||||
|
|
||||||
|
def _vim_to_python(value):
|
||||||
|
return _vim_to_python_types.get(type(value), _id)(value)
|
||||||
|
|
||||||
|
|
||||||
|
if hasattr(vim, 'options'):
|
||||||
|
def vim_getbufoption(info, option):
|
||||||
|
return _vim_to_python(info['buffer'].options[str(option)])
|
||||||
|
|
||||||
|
def vim_getoption(option):
|
||||||
|
return vim.options[str(option)]
|
||||||
|
|
||||||
|
def vim_setoption(option, value):
|
||||||
|
vim.options[str(option)] = value
|
||||||
|
else:
|
||||||
|
def vim_getbufoption(info, option):
|
||||||
|
return getbufvar(info['bufnr'], '&' + option)
|
||||||
|
|
||||||
|
def vim_getoption(option):
|
||||||
|
return vim.eval('&g:' + option)
|
||||||
|
|
||||||
|
def vim_setoption(option, value):
|
||||||
|
vim.command('let &g:{option} = {value}'.format(
|
||||||
|
option=option, value=python_to_vim(value)))
|
||||||
|
|
||||||
|
|
||||||
|
if hasattr(vim, 'tabpages'):
|
||||||
|
current_tabpage = lambda: vim.current.tabpage
|
||||||
|
list_tabpages = lambda: vim.tabpages
|
||||||
|
|
||||||
|
def list_tabpage_buffers_segment_info(segment_info):
|
||||||
|
return (
|
||||||
|
{'buffer': window.buffer, 'bufnr': window.buffer.number}
|
||||||
|
for window in segment_info['tabpage'].windows
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
class FalseObject(object):
|
||||||
|
@staticmethod
|
||||||
|
def __nonzero__():
|
||||||
|
return False
|
||||||
|
|
||||||
|
__bool__ = __nonzero__
|
||||||
|
|
||||||
|
def get_buffer(number):
|
||||||
|
for buffer in vim.buffers:
|
||||||
|
if buffer.number == number:
|
||||||
|
return buffer
|
||||||
|
raise KeyError(number)
|
||||||
|
|
||||||
|
class WindowVars(object):
|
||||||
|
__slots__ = ('tabnr', 'winnr')
|
||||||
|
|
||||||
|
def __init__(self, window):
|
||||||
|
self.tabnr = window.tabnr
|
||||||
|
self.winnr = window.number
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
has_key = vim.eval('has_key(gettabwinvar({0}, {1}, ""), "{2}")'.format(self.tabnr, self.winnr, key))
|
||||||
|
if has_key == '0':
|
||||||
|
raise KeyError
|
||||||
|
return vim.eval('gettabwinvar({0}, {1}, "{2}")'.format(self.tabnr, self.winnr, key))
|
||||||
|
|
||||||
|
def get(self, key, default=None):
|
||||||
|
try:
|
||||||
|
return self[key]
|
||||||
|
except KeyError:
|
||||||
|
return default
|
||||||
|
|
||||||
|
class Window(FalseObject):
|
||||||
|
__slots__ = ('tabnr', 'number', '_vars')
|
||||||
|
|
||||||
|
def __init__(self, tabnr, number):
|
||||||
|
self.tabnr = tabnr
|
||||||
|
self.number = number
|
||||||
|
self.vars = WindowVars(self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def buffer(self):
|
||||||
|
return get_buffer(int(vim.eval('tabpagebuflist({0})[{1}]'.format(self.tabnr, self.number - 1))))
|
||||||
|
|
||||||
|
class Tabpage(FalseObject):
|
||||||
|
__slots__ = ('number',)
|
||||||
|
|
||||||
|
def __init__(self, number):
|
||||||
|
self.number = number
|
||||||
|
|
||||||
|
def __eq__(self, tabpage):
|
||||||
|
if not isinstance(tabpage, Tabpage):
|
||||||
|
raise NotImplementedError
|
||||||
|
return self.number == tabpage.number
|
||||||
|
|
||||||
|
@property
|
||||||
|
def window(self):
|
||||||
|
return Window(self.number, int(vim.eval('tabpagewinnr({0})'.format(self.number))))
|
||||||
|
|
||||||
|
def _last_tab_nr():
|
||||||
|
return int(vim.eval('tabpagenr("$")'))
|
||||||
|
|
||||||
|
def current_tabpage():
|
||||||
|
return Tabpage(int(vim.eval('tabpagenr()')))
|
||||||
|
|
||||||
|
def list_tabpages():
|
||||||
|
return [Tabpage(nr) for nr in range(1, _last_tab_nr() + 1)]
|
||||||
|
|
||||||
|
class TabBufSegmentInfo(dict):
|
||||||
|
def __getitem__(self, key):
|
||||||
|
try:
|
||||||
|
return super(TabBufSegmentInfo, self).__getitem__(key)
|
||||||
|
except KeyError:
|
||||||
|
if key != 'buffer':
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
buffer = get_buffer(super(TabBufSegmentInfo, self).__getitem__('bufnr'))
|
||||||
|
self['buffer'] = buffer
|
||||||
|
return buffer
|
||||||
|
|
||||||
|
def list_tabpage_buffers_segment_info(segment_info):
|
||||||
|
return (
|
||||||
|
TabBufSegmentInfo(bufnr=int(bufnrstr))
|
||||||
|
for bufnrstr in vim.eval('tabpagebuflist({0})'.format(segment_info['tabnr']))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class VimEnviron(object):
|
||||||
|
@staticmethod
|
||||||
|
def __getitem__(key):
|
||||||
|
return vim.eval('$' + key)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get(key, default=None):
|
||||||
|
return vim.eval('$' + key) or default
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __setitem__(key, value):
|
||||||
|
return vim.command(
|
||||||
|
'let ${0}="{1}"'.format(
|
||||||
|
key,
|
||||||
|
value.replace('"', '\\"')
|
||||||
|
.replace('\\', '\\\\')
|
||||||
|
.replace('\n', '\\n')
|
||||||
|
.replace('\0', '')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
def buffer_name(segment_info):
|
||||||
|
return segment_info['buffer'].name
|
||||||
|
else:
|
||||||
|
vim_bufname = vim_get_func('bufname', rettype='bytes')
|
||||||
|
|
||||||
|
def buffer_name(segment_info):
|
||||||
|
try:
|
||||||
|
name = segment_info['buffer'].name
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
return vim_bufname(segment_info['bufnr'])
|
||||||
|
else:
|
||||||
|
return name.encode(segment_info['encoding']) if name else None
|
||||||
|
|
||||||
|
|
||||||
|
vim_strtrans = vim_get_func('strtrans', rettype='unicode')
|
||||||
|
|
||||||
|
|
||||||
|
def powerline_vim_strtrans_error(e):
|
||||||
|
if not isinstance(e, UnicodeDecodeError):
|
||||||
|
raise NotImplementedError
|
||||||
|
text = vim_strtrans(e.object[e.start:e.end])
|
||||||
|
return (text, e.end)
|
||||||
|
|
||||||
|
|
||||||
|
codecs.register_error('powerline_vim_strtrans_error', powerline_vim_strtrans_error)
|
||||||
|
|
||||||
|
|
||||||
|
did_autocmd = False
|
||||||
|
buffer_caches = []
|
||||||
|
|
||||||
|
|
||||||
|
def register_buffer_cache(cachedict):
|
||||||
|
global did_autocmd
|
||||||
|
global buffer_caches
|
||||||
|
from powerline.vim import get_default_pycmd, pycmd
|
||||||
|
if not did_autocmd:
|
||||||
|
import __main__
|
||||||
|
__main__.powerline_on_bwipe = on_bwipe
|
||||||
|
vim.command('augroup Powerline')
|
||||||
|
vim.command(' autocmd! BufWipeout * :{pycmd} powerline_on_bwipe()'.format(
|
||||||
|
pycmd=(pycmd or get_default_pycmd())))
|
||||||
|
vim.command('augroup END')
|
||||||
|
did_autocmd = True
|
||||||
|
buffer_caches.append(cachedict)
|
||||||
|
return cachedict
|
||||||
|
|
||||||
|
|
||||||
|
def on_bwipe():
|
||||||
|
global buffer_caches
|
||||||
|
bufnr = int(vim.eval('expand("<abuf>")'))
|
||||||
|
for cachedict in buffer_caches:
|
||||||
|
cachedict.pop(bufnr, None)
|
||||||
|
|
||||||
|
|
||||||
|
environ = VimEnviron()
|
||||||
|
|
||||||
|
|
||||||
|
def create_ruby_dpowerline():
|
||||||
|
vim.command((
|
||||||
|
'''
|
||||||
|
ruby
|
||||||
|
if $powerline == nil
|
||||||
|
class Powerline
|
||||||
|
end
|
||||||
|
$powerline = Powerline.new
|
||||||
|
end
|
||||||
|
'''
|
||||||
|
))
|
Binary file not shown.
@ -0,0 +1,20 @@
|
|||||||
|
python import cProfile
|
||||||
|
python powerline_pr = cProfile.Profile()
|
||||||
|
|
||||||
|
function powerline#debug#profile_pyeval(s)
|
||||||
|
python powerline_pr.enable()
|
||||||
|
try
|
||||||
|
let ret = pyeval(a:s)
|
||||||
|
finally
|
||||||
|
python powerline_pr.disable()
|
||||||
|
endtry
|
||||||
|
return ret
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function powerline#debug#write_profile(fname)
|
||||||
|
python import vim
|
||||||
|
python powerline_pr.dump_stats(vim.eval('a:fname'))
|
||||||
|
python powerline_pr = cProfile.Profile()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
command -nargs=1 -complete=file WriteProfiling :call powerline#debug#write_profile(<q-args>)
|
169
powerline-bin/powerline/bindings/vim/plugin/powerline.vim
Normal file
169
powerline-bin/powerline/bindings/vim/plugin/powerline.vim
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
if exists('g:powerline_loaded')
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let g:powerline_loaded = 1
|
||||||
|
|
||||||
|
if exists('g:powerline_pycmd')
|
||||||
|
let s:pycmd = substitute(g:powerline_pycmd, '\v\C^(py)%[thon](3?)$', '\1\2', '')
|
||||||
|
if s:pycmd is# 'py'
|
||||||
|
let s:has_python = has('python')
|
||||||
|
let s:pyeval = get(g:, 'powerline_pyeval', 'pyeval')
|
||||||
|
elseif s:pycmd is# 'py3'
|
||||||
|
let s:has_python = has('python3')
|
||||||
|
let s:pyeval = 'py3eval'
|
||||||
|
let s:pyeval = get(g:, 'powerline_pyeval', 'py3eval')
|
||||||
|
else
|
||||||
|
if !exists('g:powerline_pyeval')
|
||||||
|
echohl ErrorMsg
|
||||||
|
echomsg 'g:powerline_pycmd was set to an unknown values, but g:powerline_pyeval'
|
||||||
|
echomsg 'was not set. You should either set g:powerline_pycmd to "py3" or "py",'
|
||||||
|
echomsg 'specify g:powerline_pyeval explicitly or unset both and let powerline'
|
||||||
|
echomsg 'figure them out.'
|
||||||
|
echohl None
|
||||||
|
unlet s:pycmd
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let s:pyeval = g:powerline_pyeval
|
||||||
|
let s:has_python = 1
|
||||||
|
endif
|
||||||
|
elseif has('python')
|
||||||
|
let s:has_python = 1
|
||||||
|
let s:pycmd = 'py'
|
||||||
|
let s:pyeval = get(g:, 'powerline_pyeval', 'pyeval')
|
||||||
|
elseif has('python3')
|
||||||
|
let s:has_python = 1
|
||||||
|
let s:pycmd = 'py3'
|
||||||
|
let s:pyeval = get(g:, 'powerline_pyeval', 'py3eval')
|
||||||
|
else
|
||||||
|
let s:has_python = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !s:has_python
|
||||||
|
if !exists('g:powerline_no_python_error')
|
||||||
|
echohl ErrorMsg
|
||||||
|
echomsg 'You need vim compiled with Python 2.6, 2.7 or 3.2 and later support'
|
||||||
|
echomsg 'for Powerline to work. Please consult the documentation for more'
|
||||||
|
echomsg 'details.'
|
||||||
|
echohl None
|
||||||
|
endif
|
||||||
|
unlet s:has_python
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
unlet s:has_python
|
||||||
|
|
||||||
|
let s:import_cmd = 'from powerline.vim import VimPowerline'
|
||||||
|
function s:rcmd(s)
|
||||||
|
if !exists('s:pystr')
|
||||||
|
let s:pystr = a:s . "\n"
|
||||||
|
else
|
||||||
|
let s:pystr = s:pystr . a:s . "\n"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
try
|
||||||
|
let s:can_replace_pyeval = !exists('g:powerline_pyeval')
|
||||||
|
call s:rcmd('try:')
|
||||||
|
call s:rcmd(' powerline_appended_path = None')
|
||||||
|
call s:rcmd(' try:')
|
||||||
|
call s:rcmd(' '.s:import_cmd.'')
|
||||||
|
call s:rcmd(' except ImportError:')
|
||||||
|
call s:rcmd(' import sys, vim')
|
||||||
|
call s:rcmd(' powerline_appended_path = vim.eval("expand(\"<sfile>:h:h:h:h:h\")")')
|
||||||
|
call s:rcmd(' sys.path.append(powerline_appended_path)')
|
||||||
|
call s:rcmd(' '.s:import_cmd.'')
|
||||||
|
call s:rcmd(' import vim')
|
||||||
|
call s:rcmd(' powerline_instance = VimPowerline()')
|
||||||
|
call s:rcmd(' powerline_instance.setup(pyeval=vim.eval("s:pyeval"), pycmd=vim.eval("s:pycmd"), can_replace_pyeval=int(vim.eval("s:can_replace_pyeval")))')
|
||||||
|
call s:rcmd(' del VimPowerline')
|
||||||
|
call s:rcmd(' del powerline_instance')
|
||||||
|
call s:rcmd('except Exception:')
|
||||||
|
call s:rcmd(' import traceback, sys')
|
||||||
|
call s:rcmd(' traceback.print_exc(file=sys.stdout)')
|
||||||
|
call s:rcmd(' raise')
|
||||||
|
execute s:pycmd s:pystr
|
||||||
|
unlet s:pystr
|
||||||
|
let s:launched = 1
|
||||||
|
finally
|
||||||
|
unlet s:can_replace_pyeval
|
||||||
|
unlet s:import_cmd
|
||||||
|
if !exists('s:launched')
|
||||||
|
unlet s:pystr
|
||||||
|
echohl ErrorMsg
|
||||||
|
echomsg 'An error occurred while importing powerline module.'
|
||||||
|
echomsg 'This could be caused by invalid sys.path setting,'
|
||||||
|
echomsg 'or by an incompatible Python version (powerline requires'
|
||||||
|
echomsg 'Python 2.6, 2.7 or 3.2 and later to work). Please consult'
|
||||||
|
echomsg 'the troubleshooting section in the documentation for'
|
||||||
|
echomsg 'possible solutions.'
|
||||||
|
if s:pycmd is# 'py' && has('python3')
|
||||||
|
echomsg 'If powerline on your system is installed for python 3 only you'
|
||||||
|
echomsg 'should set g:powerline_pycmd to "py3" to make it load correctly.'
|
||||||
|
endif
|
||||||
|
echohl None
|
||||||
|
call s:rcmd('def powerline_troubleshoot():')
|
||||||
|
call s:rcmd(' import sys')
|
||||||
|
call s:rcmd(' import vim')
|
||||||
|
call s:rcmd(' if sys.version_info < (2, 6):')
|
||||||
|
call s:rcmd(' print("Too old python version: " + sys.version + " (first supported is 2.6)")')
|
||||||
|
call s:rcmd(' elif sys.version_info[0] == 3 and sys.version_info[1] < 2:')
|
||||||
|
call s:rcmd(' print("Too old python 3 version: " + sys.version + " (first supported is 3.2)")')
|
||||||
|
call s:rcmd(' try:')
|
||||||
|
call s:rcmd(' import powerline')
|
||||||
|
call s:rcmd(' except ImportError:')
|
||||||
|
call s:rcmd(' print("Unable to import powerline, is it installed?")')
|
||||||
|
call s:rcmd(' else:')
|
||||||
|
call s:rcmd(' if not vim.eval(''expand("<sfile>")'').startswith("/usr/"):')
|
||||||
|
call s:rcmd(' import os')
|
||||||
|
call s:rcmd(' powerline_dir = os.path.realpath(os.path.normpath(powerline.__file__))')
|
||||||
|
call s:rcmd(' powerline_dir = os.path.dirname(powerline.__file__)')
|
||||||
|
call s:rcmd(' this_dir = os.path.realpath(os.path.normpath(vim.eval(''expand("<sfile>:p")'')))')
|
||||||
|
call s:rcmd(' this_dir = os.path.dirname(this_dir)') " powerline/bindings/vim/plugin
|
||||||
|
call s:rcmd(' this_dir = os.path.dirname(this_dir)') " powerline/bindings/vim
|
||||||
|
call s:rcmd(' this_dir = os.path.dirname(this_dir)') " powerline/bindings
|
||||||
|
call s:rcmd(' this_dir = os.path.dirname(this_dir)') " powerline
|
||||||
|
call s:rcmd(' if os.path.basename(this_dir) != "powerline":')
|
||||||
|
call s:rcmd(' print("Check your installation:")')
|
||||||
|
call s:rcmd(' print("this script is not in powerline[/bindings/vim/plugin] directory,")')
|
||||||
|
call s:rcmd(' print("neither it is installed system-wide")')
|
||||||
|
call s:rcmd(' real_powerline_dir = os.path.realpath(powerline_dir)')
|
||||||
|
call s:rcmd(' real_this_dir = os.path.realpath(this_dir)')
|
||||||
|
call s:rcmd(' this_dir_par = os.path.dirname(real_this_dir)')
|
||||||
|
call s:rcmd(' powerline_appended_path = globals().get("powerline_appended_path")')
|
||||||
|
call s:rcmd(' if powerline_appended_path is not None and this_dir_par != powerline_appended_path:')
|
||||||
|
call s:rcmd(' print("Check your installation: this script is symlinked somewhere")')
|
||||||
|
call s:rcmd(' print("where powerline is not present: {0!r} != {1!r}.".format(')
|
||||||
|
call s:rcmd(' real_this_dir, powerline_appended_path))')
|
||||||
|
call s:rcmd(' elif real_powerline_dir != real_this_dir:')
|
||||||
|
call s:rcmd(' print("It appears that you have two powerline versions installed:")')
|
||||||
|
call s:rcmd(' print("one in " + real_powerline_dir + ", other in " + real_this_dir + ".")')
|
||||||
|
call s:rcmd(' print("You should remove one of this. Check out troubleshooting section,")')
|
||||||
|
call s:rcmd(' print("it contains some information about the alternatives.")')
|
||||||
|
call s:rcmd(' try:')
|
||||||
|
call s:rcmd(' from powerline.lint import check')
|
||||||
|
call s:rcmd(' except ImportError:')
|
||||||
|
call s:rcmd(' print("Failed to import powerline.lint.check, cannot run powerline-lint")')
|
||||||
|
call s:rcmd(' else:')
|
||||||
|
call s:rcmd(' try:')
|
||||||
|
call s:rcmd(' paths = powerline_instance.get_config_paths()')
|
||||||
|
call s:rcmd(' except NameError:')
|
||||||
|
call s:rcmd(' pass')
|
||||||
|
call s:rcmd(' else:')
|
||||||
|
call s:rcmd(' from powerline.lint.markedjson.error import echoerr')
|
||||||
|
call s:rcmd(' ee = lambda *args, **kwargs: echoerr(*args, stream=sys.stdout, **kwargs)')
|
||||||
|
call s:rcmd(' check(paths=paths, echoerr=ee, require_ext="vim")')
|
||||||
|
call s:rcmd('try:')
|
||||||
|
call s:rcmd(' powerline_troubleshoot()')
|
||||||
|
call s:rcmd('finally:')
|
||||||
|
call s:rcmd(' del powerline_troubleshoot')
|
||||||
|
execute s:pycmd s:pystr
|
||||||
|
unlet s:pystr
|
||||||
|
unlet s:pycmd
|
||||||
|
unlet s:pyeval
|
||||||
|
delfunction s:rcmd
|
||||||
|
finish
|
||||||
|
else
|
||||||
|
unlet s:launched
|
||||||
|
endif
|
||||||
|
unlet s:pycmd
|
||||||
|
unlet s:pyeval
|
||||||
|
delfunction s:rcmd
|
||||||
|
endtry
|
85
powerline-bin/powerline/bindings/wm/__init__.py
Normal file
85
powerline-bin/powerline/bindings/wm/__init__.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
from powerline.theme import requires_segment_info
|
||||||
|
from powerline.lib.shell import run_cmd
|
||||||
|
from powerline.bindings.wm.awesome import AwesomeThread
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_UPDATE_INTERVAL = 0.5
|
||||||
|
|
||||||
|
|
||||||
|
conn = None
|
||||||
|
|
||||||
|
|
||||||
|
def i3_subscribe(conn, event, callback):
|
||||||
|
'''Subscribe to i3 workspace event
|
||||||
|
|
||||||
|
:param conn:
|
||||||
|
Connection returned by :py:func:`get_i3_connection`.
|
||||||
|
:param str event:
|
||||||
|
Event to subscribe to, e.g. ``'workspace'``.
|
||||||
|
:param func callback:
|
||||||
|
Function to run on event.
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
import i3ipc
|
||||||
|
except ImportError:
|
||||||
|
import i3
|
||||||
|
conn.Subscription(callback, event)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
conn.on(event, callback)
|
||||||
|
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
class I3Thread(Thread):
|
||||||
|
daemon = True
|
||||||
|
|
||||||
|
def __init__(self, conn):
|
||||||
|
super(I3Thread, self).__init__()
|
||||||
|
self.__conn = conn
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.__conn.main()
|
||||||
|
|
||||||
|
thread = I3Thread(conn=conn)
|
||||||
|
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
|
def get_i3_connection():
|
||||||
|
'''Return a valid, cached i3 Connection instance
|
||||||
|
'''
|
||||||
|
global conn
|
||||||
|
if not conn:
|
||||||
|
try:
|
||||||
|
import i3ipc
|
||||||
|
except ImportError:
|
||||||
|
import i3 as conn
|
||||||
|
else:
|
||||||
|
conn = i3ipc.Connection()
|
||||||
|
return conn
|
||||||
|
|
||||||
|
|
||||||
|
XRANDR_OUTPUT_RE = re.compile(r'^(?P<name>[0-9A-Za-z-]+) connected(?P<primary> primary)? (?P<width>\d+)x(?P<height>\d+)\+(?P<x>\d+)\+(?P<y>\d+)', re.MULTILINE)
|
||||||
|
|
||||||
|
|
||||||
|
def get_connected_xrandr_outputs(pl):
|
||||||
|
'''Iterate over xrandr outputs
|
||||||
|
|
||||||
|
Outputs are represented by a dictionary with ``name``, ``width``,
|
||||||
|
``height``, ``primary``, ``x`` and ``y`` keys.
|
||||||
|
'''
|
||||||
|
return (match.groupdict() for match in XRANDR_OUTPUT_RE.finditer(
|
||||||
|
run_cmd(pl, ['xrandr', '-q'])
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
wm_threads = {
|
||||||
|
'awesome': AwesomeThread,
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
59
powerline-bin/powerline/bindings/wm/awesome.py
Normal file
59
powerline-bin/powerline/bindings/wm/awesome.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from threading import Thread, Event
|
||||||
|
from time import sleep
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
|
from powerline import Powerline
|
||||||
|
from powerline.lib.monotonic import monotonic
|
||||||
|
|
||||||
|
|
||||||
|
def read_to_log(pl, client):
|
||||||
|
for line in client.stdout:
|
||||||
|
if line:
|
||||||
|
pl.info(line, prefix='awesome-client')
|
||||||
|
for line in client.stderr:
|
||||||
|
if line:
|
||||||
|
pl.error(line, prefix='awesome-client')
|
||||||
|
if client.wait():
|
||||||
|
pl.error('Client exited with {0}', client.returncode, prefix='awesome')
|
||||||
|
|
||||||
|
|
||||||
|
def run(thread_shutdown_event=None, pl_shutdown_event=None, pl_config_loader=None,
|
||||||
|
interval=None):
|
||||||
|
powerline = Powerline(
|
||||||
|
'wm',
|
||||||
|
renderer_module='pango_markup',
|
||||||
|
shutdown_event=pl_shutdown_event,
|
||||||
|
config_loader=pl_config_loader,
|
||||||
|
)
|
||||||
|
powerline.update_renderer()
|
||||||
|
|
||||||
|
if not thread_shutdown_event:
|
||||||
|
thread_shutdown_event = powerline.shutdown_event
|
||||||
|
|
||||||
|
while not thread_shutdown_event.is_set():
|
||||||
|
# powerline.update_interval may change over time
|
||||||
|
used_interval = interval or powerline.update_interval
|
||||||
|
start_time = monotonic()
|
||||||
|
s = powerline.render(side='right')
|
||||||
|
request = 'powerline_widget:set_markup(\'' + s.translate({'\'': '\\\'', '\\': '\\\\'}) + '\')\n'
|
||||||
|
client = Popen(['awesome-client'], shell=False, stdout=PIPE, stderr=PIPE, stdin=PIPE)
|
||||||
|
client.stdin.write(request.encode('utf-8'))
|
||||||
|
client.stdin.close()
|
||||||
|
read_to_log(powerline.pl, client)
|
||||||
|
thread_shutdown_event.wait(max(used_interval - (monotonic() - start_time), 0.1))
|
||||||
|
|
||||||
|
|
||||||
|
class AwesomeThread(Thread):
|
||||||
|
__slots__ = ('powerline_shutdown_event',)
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(AwesomeThread, self).__init__()
|
||||||
|
self.powerline_run_kwargs = kwargs
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
run(**self.powerline_run_kwargs)
|
228
powerline-bin/powerline/bindings/zsh/__init__.py
Normal file
228
powerline-bin/powerline/bindings/zsh/__init__.py
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import atexit
|
||||||
|
|
||||||
|
from weakref import WeakValueDictionary, ref
|
||||||
|
|
||||||
|
import zsh
|
||||||
|
|
||||||
|
from powerline.shell import ShellPowerline
|
||||||
|
from powerline.lib.overrides import parsedotval, parse_override_var
|
||||||
|
from powerline.lib.unicode import unicode, u
|
||||||
|
from powerline.lib.encoding import (get_preferred_output_encoding,
|
||||||
|
get_preferred_environment_encoding)
|
||||||
|
from powerline.lib.dict import mergeargs
|
||||||
|
|
||||||
|
|
||||||
|
used_powerlines = WeakValueDictionary()
|
||||||
|
|
||||||
|
|
||||||
|
def shutdown():
|
||||||
|
for powerline in tuple(used_powerlines.values()):
|
||||||
|
powerline.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
def get_var_config(var):
|
||||||
|
try:
|
||||||
|
val = zsh.getvalue(var)
|
||||||
|
if isinstance(val, dict):
|
||||||
|
return mergeargs([parsedotval((u(k), u(v))) for k, v in val.items()])
|
||||||
|
elif isinstance(val, (unicode, str, bytes)):
|
||||||
|
return mergeargs(parse_override_var(u(val)))
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class Args(object):
|
||||||
|
__slots__ = ('last_pipe_status', 'last_exit_code')
|
||||||
|
ext = ['shell']
|
||||||
|
renderer_module = '.zsh'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def config_override(self):
|
||||||
|
return get_var_config('POWERLINE_CONFIG_OVERRIDES')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def theme_override(self):
|
||||||
|
return get_var_config('POWERLINE_THEME_OVERRIDES')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def config_path(self):
|
||||||
|
try:
|
||||||
|
ret = zsh.getvalue('POWERLINE_CONFIG_PATHS')
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
if isinstance(ret, (unicode, str, bytes)):
|
||||||
|
return [
|
||||||
|
path
|
||||||
|
for path in ret.split((b':' if isinstance(ret, bytes) else ':'))
|
||||||
|
if path
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@property
|
||||||
|
def jobnum(self):
|
||||||
|
return zsh.getvalue('_POWERLINE_JOBNUM')
|
||||||
|
|
||||||
|
|
||||||
|
def string(s):
|
||||||
|
if type(s) is bytes:
|
||||||
|
return s.decode(get_preferred_environment_encoding(), 'replace')
|
||||||
|
else:
|
||||||
|
return str(s)
|
||||||
|
|
||||||
|
|
||||||
|
class Environment(object):
|
||||||
|
@staticmethod
|
||||||
|
def __getitem__(key):
|
||||||
|
try:
|
||||||
|
return string(zsh.getvalue(key))
|
||||||
|
except IndexError as e:
|
||||||
|
raise KeyError(*e.args)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get(key, default=None):
|
||||||
|
try:
|
||||||
|
return string(zsh.getvalue(key))
|
||||||
|
except IndexError:
|
||||||
|
return default
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __contains__(key):
|
||||||
|
try:
|
||||||
|
zsh.getvalue(key)
|
||||||
|
return True
|
||||||
|
except IndexError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
if hasattr(getattr(zsh, 'environ', None), '__contains__'):
|
||||||
|
environ = zsh.environ
|
||||||
|
else:
|
||||||
|
environ = Environment()
|
||||||
|
|
||||||
|
|
||||||
|
if hasattr(zsh, 'expand') and zsh.expand('${:-}') == '':
|
||||||
|
zsh_expand = zsh.expand
|
||||||
|
else:
|
||||||
|
def zsh_expand(s):
|
||||||
|
zsh.eval('local _POWERLINE_REPLY="' + s + '"')
|
||||||
|
ret = zsh.getvalue('_POWERLINE_REPLY')
|
||||||
|
zsh.setvalue('_POWERLINE_REPLY', None)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
class ZshPowerline(ShellPowerline):
|
||||||
|
def init(self, **kwargs):
|
||||||
|
super(ZshPowerline, self).init(Args(), **kwargs)
|
||||||
|
|
||||||
|
def precmd(self):
|
||||||
|
self.args.last_pipe_status = zsh.pipestatus()
|
||||||
|
self.args.last_exit_code = zsh.last_exit_code()
|
||||||
|
|
||||||
|
def do_setup(self, zsh_globals):
|
||||||
|
set_prompt(self, 'PS1', 'left', None, above=True)
|
||||||
|
set_prompt(self, 'RPS1', 'right', None)
|
||||||
|
set_prompt(self, 'PS2', 'left', 'continuation')
|
||||||
|
set_prompt(self, 'RPS2', 'right', 'continuation')
|
||||||
|
set_prompt(self, 'PS3', 'left', 'select')
|
||||||
|
used_powerlines[id(self)] = self
|
||||||
|
zsh_globals['_powerline'] = self
|
||||||
|
|
||||||
|
|
||||||
|
class Prompt(object):
|
||||||
|
__slots__ = ('powerline', 'side', 'savedpsvar', 'savedps', 'args', 'theme', 'above', '__weakref__')
|
||||||
|
|
||||||
|
def __init__(self, powerline, side, theme, savedpsvar=None, savedps=None, above=False):
|
||||||
|
self.powerline = powerline
|
||||||
|
self.side = side
|
||||||
|
self.above = above
|
||||||
|
self.savedpsvar = savedpsvar
|
||||||
|
self.savedps = savedps
|
||||||
|
self.args = powerline.args
|
||||||
|
self.theme = theme
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
parser_state = u(zsh_expand('${(%):-%_}'))
|
||||||
|
shortened_path = u(zsh_expand('${(%):-%~}'))
|
||||||
|
try:
|
||||||
|
mode = u(zsh.getvalue('_POWERLINE_MODE'))
|
||||||
|
except IndexError:
|
||||||
|
mode = None
|
||||||
|
try:
|
||||||
|
default_mode = u(zsh.getvalue('_POWERLINE_DEFAULT_MODE'))
|
||||||
|
except IndexError:
|
||||||
|
default_mode = None
|
||||||
|
segment_info = {
|
||||||
|
'args': self.args,
|
||||||
|
'environ': environ,
|
||||||
|
'client_id': 1,
|
||||||
|
'local_theme': self.theme,
|
||||||
|
'parser_state': parser_state,
|
||||||
|
'shortened_path': shortened_path,
|
||||||
|
'mode': mode,
|
||||||
|
'default_mode': default_mode,
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
zle_rprompt_indent = zsh.getvalue('ZLE_RPROMPT_INDENT')
|
||||||
|
except IndexError:
|
||||||
|
zle_rprompt_indent = 1
|
||||||
|
r = ''
|
||||||
|
if self.above:
|
||||||
|
for line in self.powerline.render_above_lines(
|
||||||
|
width=zsh.columns() - zle_rprompt_indent,
|
||||||
|
segment_info=segment_info,
|
||||||
|
):
|
||||||
|
if line:
|
||||||
|
r += line + '\n'
|
||||||
|
r += self.powerline.render(
|
||||||
|
width=zsh.columns(),
|
||||||
|
side=self.side,
|
||||||
|
segment_info=segment_info,
|
||||||
|
mode=mode,
|
||||||
|
)
|
||||||
|
if type(r) is not str:
|
||||||
|
if type(r) is bytes:
|
||||||
|
return r.decode(get_preferred_output_encoding(), 'replace')
|
||||||
|
else:
|
||||||
|
return r.encode(get_preferred_output_encoding(), 'replace')
|
||||||
|
return r
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
if self.savedps:
|
||||||
|
zsh.setvalue(self.savedpsvar, self.savedps)
|
||||||
|
self.powerline.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
def set_prompt(powerline, psvar, side, theme, above=False):
|
||||||
|
try:
|
||||||
|
savedps = zsh.getvalue(psvar)
|
||||||
|
except IndexError:
|
||||||
|
savedps = None
|
||||||
|
zpyvar = 'ZPYTHON_POWERLINE_' + psvar
|
||||||
|
prompt = Prompt(powerline, side, theme, psvar, savedps, above)
|
||||||
|
zsh.setvalue(zpyvar, None)
|
||||||
|
zsh.set_special_string(zpyvar, prompt)
|
||||||
|
zsh.setvalue(psvar, '${' + zpyvar + '}')
|
||||||
|
return ref(prompt)
|
||||||
|
|
||||||
|
|
||||||
|
def reload():
|
||||||
|
for powerline in tuple(used_powerlines.values()):
|
||||||
|
powerline.reload()
|
||||||
|
|
||||||
|
|
||||||
|
def reload_config():
|
||||||
|
for powerline in used_powerlines.values():
|
||||||
|
powerline.create_renderer(load_main=True, load_colors=True, load_colorscheme=True, load_theme=True)
|
||||||
|
|
||||||
|
|
||||||
|
def setup(zsh_globals):
|
||||||
|
powerline = ZshPowerline()
|
||||||
|
powerline.setup(zsh_globals)
|
||||||
|
atexit.register(shutdown)
|
Binary file not shown.
216
powerline-bin/powerline/bindings/zsh/powerline.zsh
Normal file
216
powerline-bin/powerline/bindings/zsh/powerline.zsh
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
local _POWERLINE_SOURCED="$0:A"
|
||||||
|
|
||||||
|
_powerline_columns_fallback() {
|
||||||
|
if which stty &>/dev/null ; then
|
||||||
|
local cols="$(stty size 2>/dev/null)"
|
||||||
|
if ! test -z "$cols" ; then
|
||||||
|
echo "${cols#* }"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo 0
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_append_precmd_function() {
|
||||||
|
if test -z "${precmd_functions[(re)$1]}" ; then
|
||||||
|
precmd_functions+=( $1 )
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
integer -g _POWERLINE_JOBNUM=0
|
||||||
|
|
||||||
|
_powerline_tmux_pane() {
|
||||||
|
local -x TMUX="$_POWERLINE_TMUX"
|
||||||
|
echo "${TMUX_PANE:-`tmux display -p "#D"`}" | tr -d ' %'
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_tmux_pane() {
|
||||||
|
local -x TMUX="$_POWERLINE_TMUX"
|
||||||
|
echo "${TMUX_PANE:-`tmux display -p "#D"`}" | tr -d ' %'
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_init_tmux_support() {
|
||||||
|
emulate -L zsh
|
||||||
|
if test -n "$TMUX" && tmux refresh -S &>/dev/null ; then
|
||||||
|
# TMUX variable may be unset to create new tmux session inside this one
|
||||||
|
typeset -g _POWERLINE_TMUX="$TMUX"
|
||||||
|
|
||||||
|
function -g _powerline_tmux_setenv() {
|
||||||
|
emulate -L zsh
|
||||||
|
local -x TMUX="$_POWERLINE_TMUX"
|
||||||
|
tmux setenv -g TMUX_"$1"_$(_powerline_tmux_pane) "$2"
|
||||||
|
tmux refresh -S
|
||||||
|
}
|
||||||
|
|
||||||
|
function -g _powerline_tmux_set_pwd() {
|
||||||
|
_powerline_tmux_setenv PWD "$PWD"
|
||||||
|
}
|
||||||
|
|
||||||
|
function -g _powerline_tmux_set_columns() {
|
||||||
|
_powerline_tmux_setenv COLUMNS "${COLUMNS:-$(_powerline_columns_fallback)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
chpwd_functions+=( _powerline_tmux_set_pwd )
|
||||||
|
trap '_powerline_tmux_set_columns' SIGWINCH
|
||||||
|
_powerline_tmux_set_columns
|
||||||
|
_powerline_tmux_set_pwd
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_init_modes_support() {
|
||||||
|
emulate -L zsh
|
||||||
|
|
||||||
|
test -z "$ZSH_VERSION" && return 0
|
||||||
|
|
||||||
|
local -a vs
|
||||||
|
vs=( ${(s:.:)ZSH_VERSION} )
|
||||||
|
|
||||||
|
# Mode support requires >=zsh-4.3.11
|
||||||
|
if (( vs[1] < 4 || (vs[1] == 4 && (vs[2] < 3 || (vs[2] == 3 && vs[3] < 11))) )) ; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
function -g _powerline_get_main_keymap_name() {
|
||||||
|
REPLY="${${(Q)${${(z)${"$(bindkey -lL main)"}}[3]}}:-.safe}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function -g _powerline_set_true_keymap_name() {
|
||||||
|
typeset -g _POWERLINE_MODE="${1}"
|
||||||
|
local plm_bk="$(bindkey -lL ${_POWERLINE_MODE})"
|
||||||
|
if [[ $plm_bk = 'bindkey -A'* ]] ; then
|
||||||
|
_powerline_set_true_keymap_name ${(Q)${${(z)plm_bk}[3]}}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function -g _powerline_zle_keymap_select() {
|
||||||
|
_powerline_set_true_keymap_name $KEYMAP
|
||||||
|
zle reset-prompt
|
||||||
|
test -z "$_POWERLINE_SAVE_WIDGET" || zle $_POWERLINE_SAVE_WIDGET
|
||||||
|
}
|
||||||
|
|
||||||
|
function -g _powerline_set_main_keymap_name() {
|
||||||
|
local REPLY
|
||||||
|
_powerline_get_main_keymap_name
|
||||||
|
_powerline_set_true_keymap_name "$REPLY"
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_add_widget zle-keymap-select _powerline_zle_keymap_select
|
||||||
|
_powerline_set_main_keymap_name
|
||||||
|
|
||||||
|
if [[ "$_POWERLINE_MODE" != vi* ]] ; then
|
||||||
|
typeset -g _POWERLINE_DEFAULT_MODE="$_POWERLINE_MODE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
_powerline_append_precmd_function _powerline_set_main_keymap_name
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_set_jobnum() {
|
||||||
|
# If you are wondering why I am not using the same code as I use for bash
|
||||||
|
# ($(jobs|wc -l)): consider the following test:
|
||||||
|
# echo abc | less
|
||||||
|
# <C-z>
|
||||||
|
# . This way jobs will print
|
||||||
|
# [1] + done echo abc |
|
||||||
|
# suspended less -M
|
||||||
|
# ([ is in first column). You see: any line counting thingie will return
|
||||||
|
# wrong number of jobs. You need to filter the lines first. Or not use
|
||||||
|
# jobs built-in at all.
|
||||||
|
integer -g _POWERLINE_JOBNUM=${(%):-%j}
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_update_counter() {
|
||||||
|
zpython '_powerline.precmd()'
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_setup_prompt() {
|
||||||
|
emulate -L zsh
|
||||||
|
|
||||||
|
_powerline_append_precmd_function _powerline_set_jobnum
|
||||||
|
|
||||||
|
typeset -g VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||||
|
|
||||||
|
if test -z "${POWERLINE_NO_ZSH_ZPYTHON}" && { zmodload libzpython || zmodload zsh/zpython } &>/dev/null ; then
|
||||||
|
_powerline_append_precmd_function _powerline_update_counter
|
||||||
|
zpython 'from powerline.bindings.zsh import setup as _powerline_setup'
|
||||||
|
zpython '_powerline_setup(globals())'
|
||||||
|
zpython 'del _powerline_setup'
|
||||||
|
powerline-reload() {
|
||||||
|
zpython 'from powerline.bindings.zsh import reload as _powerline_reload'
|
||||||
|
zpython '_powerline_reload()'
|
||||||
|
zpython 'del _powerline_reload'
|
||||||
|
}
|
||||||
|
powerline-reload-config() {
|
||||||
|
zpython 'from powerline.bindings.zsh import reload_config as _powerline_reload_config'
|
||||||
|
zpython '_powerline_reload_config()'
|
||||||
|
zpython 'del _powerline_reload_config'
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if test -z "${POWERLINE_COMMAND}" ; then
|
||||||
|
typeset -g POWERLINE_COMMAND="$($POWERLINE_CONFIG_COMMAND shell command)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local add_args='-r .zsh'
|
||||||
|
add_args+=' --last-exit-code=$?'
|
||||||
|
add_args+=' --last-pipe-status="$pipestatus"'
|
||||||
|
add_args+=' --renderer-arg="client_id=$$"'
|
||||||
|
add_args+=' --renderer-arg="shortened_path=${(%):-%~}"'
|
||||||
|
add_args+=' --jobnum=$_POWERLINE_JOBNUM'
|
||||||
|
add_args+=' --renderer-arg="mode=$_POWERLINE_MODE"'
|
||||||
|
add_args+=' --renderer-arg="default_mode=$_POWERLINE_DEFAULT_MODE"'
|
||||||
|
local new_args_2=' --renderer-arg="parser_state=${(%%):-%_}"'
|
||||||
|
new_args_2+=' --renderer-arg="local_theme=continuation"'
|
||||||
|
local add_args_3=$add_args' --renderer-arg="local_theme=select"'
|
||||||
|
local add_args_2=$add_args$new_args_2
|
||||||
|
add_args+=' --width=$(( ${COLUMNS:-$(_powerline_columns_fallback)} - ${ZLE_RPROMPT_INDENT:-1} ))'
|
||||||
|
local add_args_r2=$add_args$new_args_2
|
||||||
|
typeset -g PS1='$("$POWERLINE_COMMAND" $=POWERLINE_COMMAND_ARGS shell aboveleft '$add_args')'
|
||||||
|
typeset -g RPS1='$("$POWERLINE_COMMAND" $=POWERLINE_COMMAND_ARGS shell right '$add_args')'
|
||||||
|
typeset -g PS2='$("$POWERLINE_COMMAND" $=POWERLINE_COMMAND_ARGS shell left '$add_args_2')'
|
||||||
|
typeset -g RPS2='$("$POWERLINE_COMMAND" $=POWERLINE_COMMAND_ARGS shell right '$add_args_r2')'
|
||||||
|
typeset -g PS3='$("$POWERLINE_COMMAND" $=POWERLINE_COMMAND_ARGS shell left '$add_args_3')'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerline_add_widget() {
|
||||||
|
local widget="$1"
|
||||||
|
local function="$2"
|
||||||
|
local old_widget_command="$(zle -l -L $widget)"
|
||||||
|
if [[ "$old_widget_command" = "zle -N $widget $function" ]] ; then
|
||||||
|
return 0
|
||||||
|
elif [[ -z "$old_widget_command" ]] ; then
|
||||||
|
zle -N $widget $function
|
||||||
|
else
|
||||||
|
local save_widget="_powerline_save_$widget"
|
||||||
|
local -i i=0
|
||||||
|
while ! test -z "$(zle -l -L $save_widget)" ; do
|
||||||
|
save_widget="${save_widget}_$i"
|
||||||
|
(( i++ ))
|
||||||
|
done
|
||||||
|
# If widget was defined with `zle -N widget` (without `function`
|
||||||
|
# argument) then this function will be handy.
|
||||||
|
eval "function $save_widget() { emulate -L zsh; $widget \$@ }"
|
||||||
|
eval "${old_widget_command/$widget/$save_widget}"
|
||||||
|
zle -N $widget $function
|
||||||
|
typeset -g _POWERLINE_SAVE_WIDGET="$save_widget"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if test -z "${POWERLINE_CONFIG_COMMAND}" ; then
|
||||||
|
if which powerline-config >/dev/null ; then
|
||||||
|
typeset -g POWERLINE_CONFIG_COMMAND=powerline-config
|
||||||
|
else
|
||||||
|
typeset -g POWERLINE_CONFIG_COMMAND="${_POWERLINE_SOURCED:h:h:h:h}/scripts/powerline-config"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
setopt promptpercent
|
||||||
|
setopt promptsubst
|
||||||
|
|
||||||
|
if "${POWERLINE_CONFIG_COMMAND}" shell --shell=zsh uses prompt ; then
|
||||||
|
_powerline_setup_prompt
|
||||||
|
_powerline_init_modes_support
|
||||||
|
fi
|
||||||
|
if "${POWERLINE_CONFIG_COMMAND}" shell --shell=zsh uses tmux ; then
|
||||||
|
_powerline_init_tmux_support
|
||||||
|
fi
|
147
powerline-bin/powerline/colorscheme.py
Normal file
147
powerline-bin/powerline/colorscheme.py
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
from copy import copy
|
||||||
|
|
||||||
|
from powerline.lib.unicode import unicode
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_MODE_KEY = None
|
||||||
|
ATTR_BOLD = 1
|
||||||
|
ATTR_ITALIC = 2
|
||||||
|
ATTR_UNDERLINE = 4
|
||||||
|
|
||||||
|
|
||||||
|
def get_attrs_flag(attrs):
|
||||||
|
'''Convert an attribute array to a renderer flag.'''
|
||||||
|
attrs_flag = 0
|
||||||
|
if 'bold' in attrs:
|
||||||
|
attrs_flag |= ATTR_BOLD
|
||||||
|
if 'italic' in attrs:
|
||||||
|
attrs_flag |= ATTR_ITALIC
|
||||||
|
if 'underline' in attrs:
|
||||||
|
attrs_flag |= ATTR_UNDERLINE
|
||||||
|
return attrs_flag
|
||||||
|
|
||||||
|
|
||||||
|
def pick_gradient_value(grad_list, gradient_level):
|
||||||
|
'''Given a list of colors and gradient percent, return a color that should be used.
|
||||||
|
|
||||||
|
Note: gradient level is not checked for being inside [0, 100] interval.
|
||||||
|
'''
|
||||||
|
return grad_list[int(round(gradient_level * (len(grad_list) - 1) / 100))]
|
||||||
|
|
||||||
|
|
||||||
|
class Colorscheme(object):
|
||||||
|
def __init__(self, colorscheme_config, colors_config):
|
||||||
|
'''Initialize a colorscheme.'''
|
||||||
|
self.colors = {}
|
||||||
|
self.gradients = {}
|
||||||
|
|
||||||
|
self.groups = colorscheme_config['groups']
|
||||||
|
self.translations = colorscheme_config.get('mode_translations', {})
|
||||||
|
|
||||||
|
# Create a dict of color tuples with both a cterm and hex value
|
||||||
|
for color_name, color in colors_config['colors'].items():
|
||||||
|
try:
|
||||||
|
self.colors[color_name] = (color[0], int(color[1], 16))
|
||||||
|
except TypeError:
|
||||||
|
self.colors[color_name] = (color, cterm_to_hex[color])
|
||||||
|
|
||||||
|
# Create a dict of gradient names with two lists: for cterm and hex
|
||||||
|
# values. Two lists in place of one list of pairs were chosen because
|
||||||
|
# true colors allow more precise gradients.
|
||||||
|
for gradient_name, gradient in colors_config['gradients'].items():
|
||||||
|
if len(gradient) == 2:
|
||||||
|
self.gradients[gradient_name] = (
|
||||||
|
(gradient[0], [int(color, 16) for color in gradient[1]]))
|
||||||
|
else:
|
||||||
|
self.gradients[gradient_name] = (
|
||||||
|
(gradient[0], [cterm_to_hex[color] for color in gradient[0]]))
|
||||||
|
|
||||||
|
def get_gradient(self, gradient, gradient_level):
|
||||||
|
if gradient in self.gradients:
|
||||||
|
return tuple((pick_gradient_value(grad_list, gradient_level) for grad_list in self.gradients[gradient]))
|
||||||
|
else:
|
||||||
|
return self.colors[gradient]
|
||||||
|
|
||||||
|
def get_group_props(self, mode, trans, group, translate_colors=True):
|
||||||
|
if isinstance(group, (str, unicode)):
|
||||||
|
try:
|
||||||
|
group_props = trans['groups'][group]
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
group_props = self.groups[group]
|
||||||
|
except KeyError:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return self.get_group_props(mode, trans, group_props, True)
|
||||||
|
else:
|
||||||
|
return self.get_group_props(mode, trans, group_props, False)
|
||||||
|
else:
|
||||||
|
if translate_colors:
|
||||||
|
group_props = copy(group)
|
||||||
|
try:
|
||||||
|
ctrans = trans['colors']
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for key in ('fg', 'bg'):
|
||||||
|
try:
|
||||||
|
group_props[key] = ctrans[group_props[key]]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
return group_props
|
||||||
|
else:
|
||||||
|
return group
|
||||||
|
|
||||||
|
def get_highlighting(self, groups, mode, gradient_level=None):
|
||||||
|
trans = self.translations.get(mode, {})
|
||||||
|
for group in groups:
|
||||||
|
group_props = self.get_group_props(mode, trans, group)
|
||||||
|
if group_props:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise KeyError('Highlighting groups not found in colorscheme: ' + ', '.join(groups))
|
||||||
|
|
||||||
|
if gradient_level is None:
|
||||||
|
pick_color = self.colors.__getitem__
|
||||||
|
else:
|
||||||
|
pick_color = lambda gradient: self.get_gradient(gradient, gradient_level)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'fg': pick_color(group_props['fg']),
|
||||||
|
'bg': pick_color(group_props['bg']),
|
||||||
|
'attrs': get_attrs_flag(group_props.get('attrs', [])),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 0 1 2 3 4 5 6 7 8 9
|
||||||
|
cterm_to_hex = (
|
||||||
|
0x000000, 0xc00000, 0x008000, 0x804000, 0x0000c0, 0xc000c0, 0x008080, 0xc0c0c0, 0x808080, 0xff6060, # 0
|
||||||
|
0x00ff00, 0xffff00, 0x8080ff, 0xff40ff, 0x00ffff, 0xffffff, 0x000000, 0x00005f, 0x000087, 0x0000af, # 1
|
||||||
|
0x0000d7, 0x0000ff, 0x005f00, 0x005f5f, 0x005f87, 0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f, # 2
|
||||||
|
0x008787, 0x0087af, 0x0087d7, 0x0087ff, 0x00af00, 0x00af5f, 0x00af87, 0x00afaf, 0x00afd7, 0x00afff, # 3
|
||||||
|
0x00d700, 0x00d75f, 0x00d787, 0x00d7af, 0x00d7d7, 0x00d7ff, 0x00ff00, 0x00ff5f, 0x00ff87, 0x00ffaf, # 4
|
||||||
|
0x00ffd7, 0x00ffff, 0x5f0000, 0x5f005f, 0x5f0087, 0x5f00af, 0x5f00d7, 0x5f00ff, 0x5f5f00, 0x5f5f5f, # 5
|
||||||
|
0x5f5f87, 0x5f5faf, 0x5f5fd7, 0x5f5fff, 0x5f8700, 0x5f875f, 0x5f8787, 0x5f87af, 0x5f87d7, 0x5f87ff, # 6
|
||||||
|
0x5faf00, 0x5faf5f, 0x5faf87, 0x5fafaf, 0x5fafd7, 0x5fafff, 0x5fd700, 0x5fd75f, 0x5fd787, 0x5fd7af, # 7
|
||||||
|
0x5fd7d7, 0x5fd7ff, 0x5fff00, 0x5fff5f, 0x5fff87, 0x5fffaf, 0x5fffd7, 0x5fffff, 0x870000, 0x87005f, # 8
|
||||||
|
0x870087, 0x8700af, 0x8700d7, 0x8700ff, 0x875f00, 0x875f5f, 0x875f87, 0x875faf, 0x875fd7, 0x875fff, # 9
|
||||||
|
0x878700, 0x87875f, 0x878787, 0x8787af, 0x8787d7, 0x8787ff, 0x87af00, 0x87af5f, 0x87af87, 0x87afaf, # 10
|
||||||
|
0x87afd7, 0x87afff, 0x87d700, 0x87d75f, 0x87d787, 0x87d7af, 0x87d7d7, 0x87d7ff, 0x87ff00, 0x87ff5f, # 11
|
||||||
|
0x87ff87, 0x87ffaf, 0x87ffd7, 0x87ffff, 0xaf0000, 0xaf005f, 0xaf0087, 0xaf00af, 0xaf00d7, 0xaf00ff, # 12
|
||||||
|
0xaf5f00, 0xaf5f5f, 0xaf5f87, 0xaf5faf, 0xaf5fd7, 0xaf5fff, 0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af, # 13
|
||||||
|
0xaf87d7, 0xaf87ff, 0xafaf00, 0xafaf5f, 0xafaf87, 0xafafaf, 0xafafd7, 0xafafff, 0xafd700, 0xafd75f, # 14
|
||||||
|
0xafd787, 0xafd7af, 0xafd7d7, 0xafd7ff, 0xafff00, 0xafff5f, 0xafff87, 0xafffaf, 0xafffd7, 0xafffff, # 15
|
||||||
|
0xd70000, 0xd7005f, 0xd70087, 0xd700af, 0xd700d7, 0xd700ff, 0xd75f00, 0xd75f5f, 0xd75f87, 0xd75faf, # 16
|
||||||
|
0xd75fd7, 0xd75fff, 0xd78700, 0xd7875f, 0xd78787, 0xd787af, 0xd787d7, 0xd787ff, 0xd7af00, 0xd7af5f, # 17
|
||||||
|
0xd7af87, 0xd7afaf, 0xd7afd7, 0xd7afff, 0xd7d700, 0xd7d75f, 0xd7d787, 0xd7d7af, 0xd7d7d7, 0xd7d7ff, # 18
|
||||||
|
0xd7ff00, 0xd7ff5f, 0xd7ff87, 0xd7ffaf, 0xd7ffd7, 0xd7ffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af, # 19
|
||||||
|
0xff00d7, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87, 0xff5faf, 0xff5fd7, 0xff5fff, 0xff8700, 0xff875f, # 20
|
||||||
|
0xff8787, 0xff87af, 0xff87d7, 0xff87ff, 0xffaf00, 0xffaf5f, 0xffaf87, 0xffafaf, 0xffafd7, 0xffafff, # 21
|
||||||
|
0xffd700, 0xffd75f, 0xffd787, 0xffd7af, 0xffd7d7, 0xffd7ff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf, # 22
|
||||||
|
0xffffd7, 0xffffff, 0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e, # 23
|
||||||
|
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e, 0xa8a8a8, 0xb2b2b2, # 24
|
||||||
|
0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee # 25
|
||||||
|
)
|
0
powerline-bin/powerline/commands/__init__.py
Normal file
0
powerline-bin/powerline/commands/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
109
powerline-bin/powerline/commands/config.py
Normal file
109
powerline-bin/powerline/commands/config.py
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import powerline.bindings.config as config
|
||||||
|
|
||||||
|
|
||||||
|
class StrFunction(object):
|
||||||
|
def __init__(self, function, name=None):
|
||||||
|
self.name = name or function.__name__
|
||||||
|
self.function = function
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
self.function(*args, **kwargs)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
TMUX_ACTIONS = {
|
||||||
|
'source': StrFunction(config.source_tmux_files, 'source'),
|
||||||
|
'setenv': StrFunction(config.init_tmux_environment, 'setenv'),
|
||||||
|
'setup': StrFunction(config.tmux_setup, 'setup'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SHELL_ACTIONS = {
|
||||||
|
'command': StrFunction(config.shell_command, 'command'),
|
||||||
|
'uses': StrFunction(config.uses),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigArgParser(argparse.ArgumentParser):
|
||||||
|
def parse_args(self, *args, **kwargs):
|
||||||
|
ret = super(ConfigArgParser, self).parse_args(*args, **kwargs)
|
||||||
|
if not hasattr(ret, 'function'):
|
||||||
|
# In Python-3* `powerline-config` (without arguments) raises
|
||||||
|
# AttributeError. I have not found any standard way to display same
|
||||||
|
# error message as in Python-2*.
|
||||||
|
self.error('too few arguments')
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def get_argparser(ArgumentParser=ConfigArgParser):
|
||||||
|
parser = ArgumentParser(description='Script used to obtain powerline configuration.')
|
||||||
|
parser.add_argument(
|
||||||
|
'-p', '--config-path', action='append', metavar='PATH',
|
||||||
|
help='Path to configuration directory. If it is present '
|
||||||
|
'then configuration files will only be seeked in the provided path. '
|
||||||
|
'May be provided multiple times to search in a list of directories.'
|
||||||
|
)
|
||||||
|
subparsers = parser.add_subparsers()
|
||||||
|
tmux_parser = subparsers.add_parser('tmux', help='Tmux-specific commands')
|
||||||
|
tmux_parser.add_argument(
|
||||||
|
'function',
|
||||||
|
choices=tuple(TMUX_ACTIONS.values()),
|
||||||
|
metavar='ACTION',
|
||||||
|
type=(lambda v: TMUX_ACTIONS.get(v)),
|
||||||
|
help='If action is `source\' then version-specific tmux configuration '
|
||||||
|
'files are sourced, if it is `setenv\' then special '
|
||||||
|
'(prefixed with `_POWERLINE\') tmux global environment variables '
|
||||||
|
'are filled with data from powerline configuration. '
|
||||||
|
'Action `setup\' is just doing `setenv\' then `source\'.'
|
||||||
|
)
|
||||||
|
tpg = tmux_parser.add_mutually_exclusive_group()
|
||||||
|
tpg.add_argument(
|
||||||
|
'-s', '--source', action='store_true', default=None,
|
||||||
|
help='When using `setup\': always use configuration file sourcing. '
|
||||||
|
'By default this is determined automatically based on tmux '
|
||||||
|
'version: this is the default for tmux 1.8 and below.',
|
||||||
|
)
|
||||||
|
tpg.add_argument(
|
||||||
|
'-n', '--no-source', action='store_false', dest='source', default=None,
|
||||||
|
help='When using `setup\': in place of sourcing directly execute '
|
||||||
|
'configuration files. That is, read each needed '
|
||||||
|
'powerline-specific configuration file, substitute '
|
||||||
|
'`$_POWERLINE_…\' variables with appropriate values and run '
|
||||||
|
'`tmux config line\'. This is the default behaviour for '
|
||||||
|
'tmux 1.9 and above.'
|
||||||
|
)
|
||||||
|
|
||||||
|
shell_parser = subparsers.add_parser('shell', help='Shell-specific commands')
|
||||||
|
shell_parser.add_argument(
|
||||||
|
'function',
|
||||||
|
choices=tuple(SHELL_ACTIONS.values()),
|
||||||
|
type=(lambda v: SHELL_ACTIONS.get(v)),
|
||||||
|
metavar='ACTION',
|
||||||
|
help='If action is `command\' then preferred powerline command is '
|
||||||
|
'output, if it is `uses\' then powerline-config script will exit '
|
||||||
|
'with 1 if specified component is disabled and 0 otherwise.',
|
||||||
|
)
|
||||||
|
shell_parser.add_argument(
|
||||||
|
'component',
|
||||||
|
nargs='?',
|
||||||
|
choices=('tmux', 'prompt'),
|
||||||
|
metavar='COMPONENT',
|
||||||
|
help='Only applicable for `uses\' subcommand: makes `powerline-config\' '
|
||||||
|
'exit with 0 if specific component is enabled and with 1 otherwise. '
|
||||||
|
'`tmux\' component stands for tmux bindings '
|
||||||
|
'(e.g. those that notify tmux about current directory changes), '
|
||||||
|
'`prompt\' component stands for shell prompt.'
|
||||||
|
)
|
||||||
|
shell_parser.add_argument(
|
||||||
|
'-s', '--shell',
|
||||||
|
metavar='SHELL',
|
||||||
|
help='Shell for which query is run',
|
||||||
|
)
|
||||||
|
return parser
|
24
powerline-bin/powerline/commands/daemon.py
Normal file
24
powerline-bin/powerline/commands/daemon.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
def get_argparser(ArgumentParser=argparse.ArgumentParser):
|
||||||
|
parser = ArgumentParser(description='Daemon that improves powerline performance.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--quiet', '-q', action='store_true',
|
||||||
|
help='Without other options: do not complain about already running '
|
||||||
|
'powerline-daemon instance. '
|
||||||
|
'Will still exit with 1. '
|
||||||
|
'With `--kill\' and `--replace\': do not show any messages. '
|
||||||
|
'With `--foreground\': ignored. '
|
||||||
|
'Does not silence exceptions in any case.'
|
||||||
|
)
|
||||||
|
parser.add_argument('--socket', '-s', help='Specify socket which will be used for connecting to daemon.')
|
||||||
|
exclusive_group = parser.add_mutually_exclusive_group()
|
||||||
|
exclusive_group.add_argument('--kill', '-k', action='store_true', help='Kill an already running instance.')
|
||||||
|
replace_group = exclusive_group.add_argument_group()
|
||||||
|
replace_group.add_argument('--foreground', '-f', action='store_true', help='Run in the foreground (don’t daemonize).')
|
||||||
|
replace_group.add_argument('--replace', '-r', action='store_true', help='Replace an already running instance.')
|
||||||
|
return parser
|
35
powerline-bin/powerline/commands/lemonbar.py
Normal file
35
powerline-bin/powerline/commands/lemonbar.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
# WARNING: using unicode_literals causes errors in argparse
|
||||||
|
from __future__ import (division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
def get_argparser(ArgumentParser=argparse.ArgumentParser):
|
||||||
|
parser = ArgumentParser(
|
||||||
|
description='Powerline BAR bindings.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--i3', action='store_true',
|
||||||
|
help='Subscribe for i3 events.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--height', default='',
|
||||||
|
metavar='PIXELS', help='Bar height.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--interval', '-i',
|
||||||
|
type=float, default=0.5,
|
||||||
|
metavar='SECONDS', help='Refresh interval.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--bar-command', '-C',
|
||||||
|
default='lemonbar',
|
||||||
|
metavar='CMD', help='Name of the lemonbar executable to use.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'args', nargs=argparse.REMAINDER,
|
||||||
|
help='Extra arguments for lemonbar. Should be preceded with ``--`` '
|
||||||
|
'argument in order not to be confused with script own arguments.'
|
||||||
|
)
|
||||||
|
return parser
|
21
powerline-bin/powerline/commands/lint.py
Normal file
21
powerline-bin/powerline/commands/lint.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
def get_argparser(ArgumentParser=argparse.ArgumentParser):
|
||||||
|
parser = ArgumentParser(description='Powerline configuration checker.')
|
||||||
|
parser.add_argument(
|
||||||
|
'-p', '--config-path', action='append', metavar='PATH',
|
||||||
|
help='Paths where configuration should be checked, in order. You must '
|
||||||
|
'supply all paths necessary for powerline to work, '
|
||||||
|
'checking partial (e.g. only user overrides) configuration '
|
||||||
|
'is not supported.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-d', '--debug', action='store_const', const=True,
|
||||||
|
help='Display additional information. Used for debugging '
|
||||||
|
'`powerline-lint\' itself, not for debugging configuration.'
|
||||||
|
)
|
||||||
|
return parser
|
190
powerline-bin/powerline/commands/main.py
Normal file
190
powerline-bin/powerline/commands/main.py
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
# WARNING: using unicode_literals causes errors in argparse
|
||||||
|
from __future__ import (division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
|
from powerline.lib.overrides import parsedotval, parse_override_var
|
||||||
|
from powerline.lib.dict import mergeargs
|
||||||
|
from powerline.lib.encoding import get_preferred_arguments_encoding
|
||||||
|
from powerline.lib.unicode import u, unicode
|
||||||
|
from powerline.bindings.wm import wm_threads
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
encoding = get_preferred_arguments_encoding()
|
||||||
|
|
||||||
|
def arg_to_unicode(s):
|
||||||
|
return unicode(s, encoding, 'replace') if not isinstance(s, unicode) else s # NOQA
|
||||||
|
else:
|
||||||
|
def arg_to_unicode(s):
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
def finish_args(parser, environ, args, is_daemon=False):
|
||||||
|
'''Do some final transformations
|
||||||
|
|
||||||
|
Transforms ``*_override`` arguments into dictionaries, adding overrides from
|
||||||
|
environment variables. Transforms ``renderer_arg`` argument into dictionary
|
||||||
|
as well, but only if it is true.
|
||||||
|
|
||||||
|
:param dict environ:
|
||||||
|
Environment from which additional overrides should be taken from.
|
||||||
|
:param args:
|
||||||
|
Arguments object returned by
|
||||||
|
:py:meth:`argparse.ArgumentParser.parse_args`. Will be modified
|
||||||
|
in-place.
|
||||||
|
|
||||||
|
:return: Object received as second (``args``) argument.
|
||||||
|
'''
|
||||||
|
args.config_override = mergeargs(chain(
|
||||||
|
parse_override_var(environ.get('POWERLINE_CONFIG_OVERRIDES', '')),
|
||||||
|
(parsedotval(v) for v in args.config_override or ()),
|
||||||
|
))
|
||||||
|
args.theme_override = mergeargs(chain(
|
||||||
|
parse_override_var(environ.get('POWERLINE_THEME_OVERRIDES', '')),
|
||||||
|
(parsedotval(v) for v in args.theme_override or ()),
|
||||||
|
))
|
||||||
|
if args.renderer_arg:
|
||||||
|
args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg), remove=True)
|
||||||
|
if 'pane_id' in args.renderer_arg:
|
||||||
|
if isinstance(args.renderer_arg['pane_id'], (bytes, unicode)):
|
||||||
|
try:
|
||||||
|
args.renderer_arg['pane_id'] = int(args.renderer_arg['pane_id'].lstrip(' %'))
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
if 'client_id' not in args.renderer_arg:
|
||||||
|
args.renderer_arg['client_id'] = args.renderer_arg['pane_id']
|
||||||
|
args.config_path = (
|
||||||
|
[path for path in environ.get('POWERLINE_CONFIG_PATHS', '').split(':') if path]
|
||||||
|
+ (args.config_path or [])
|
||||||
|
)
|
||||||
|
if args.ext[0].startswith('wm.'):
|
||||||
|
if not is_daemon:
|
||||||
|
parser.error('WM bindings must be used with daemon only')
|
||||||
|
elif args.ext[0][3:] not in wm_threads:
|
||||||
|
parser.error('WM binding not found')
|
||||||
|
elif not args.side:
|
||||||
|
parser.error('expected one argument')
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
def int_or_sig(s):
|
||||||
|
if s.startswith('sig'):
|
||||||
|
return u(s)
|
||||||
|
else:
|
||||||
|
return int(s)
|
||||||
|
|
||||||
|
|
||||||
|
def get_argparser(ArgumentParser=argparse.ArgumentParser):
|
||||||
|
parser = ArgumentParser(description='Powerline prompt and statusline script.')
|
||||||
|
parser.add_argument(
|
||||||
|
'ext', nargs=1,
|
||||||
|
help='Extension: application for which powerline command is launched '
|
||||||
|
'(usually `shell\' or `tmux\'). Also supports `wm.\' extensions: '
|
||||||
|
+ ', '.join(('`wm.' + key + '\'' for key in wm_threads.keys())) + '.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'side', nargs='?', choices=('left', 'right', 'above', 'aboveleft'),
|
||||||
|
help='Side: `left\' and `right\' represent left and right side '
|
||||||
|
'respectively, `above\' emits lines that are supposed to be printed '
|
||||||
|
'just above the prompt and `aboveleft\' is like concatenating '
|
||||||
|
'`above\' with `left\' with the exception that only one Python '
|
||||||
|
'instance is used in this case. May be omitted for `wm.*\' extensions.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-r', '--renderer-module', metavar='MODULE', type=str,
|
||||||
|
help='Renderer module. Usually something like `.bash\' or `.zsh\' '
|
||||||
|
'(with leading dot) which is `powerline.renderers.{ext}{MODULE}\', '
|
||||||
|
'may also be full module name (must contain at least one dot or '
|
||||||
|
'end with a dot in case it is top-level module) or '
|
||||||
|
'`powerline.renderers\' submodule (in case there are no dots).'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-w', '--width', type=int,
|
||||||
|
help='Maximum prompt with. Triggers truncation of some segments.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--last-exit-code', metavar='INT', type=int_or_sig,
|
||||||
|
help='Last exit code.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--last-pipe-status', metavar='LIST', default='',
|
||||||
|
type=lambda s: [int_or_sig(status) for status in s.split()],
|
||||||
|
help='Like above, but is supposed to contain space-separated array '
|
||||||
|
'of statuses, representing exit statuses of commands in one pipe.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--jobnum', metavar='INT', type=int,
|
||||||
|
help='Number of jobs.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-c', '--config-override', metavar='KEY.KEY=VALUE', type=arg_to_unicode,
|
||||||
|
action='append',
|
||||||
|
help='Configuration overrides for `config.json\'. Is translated to a '
|
||||||
|
'dictionary and merged with the dictionary obtained from actual '
|
||||||
|
'JSON configuration: KEY.KEY=VALUE is translated to '
|
||||||
|
'`{"KEY": {"KEY": VALUE}}\' and then merged recursively. '
|
||||||
|
'VALUE may be any JSON value, values that are not '
|
||||||
|
'`null\', `true\', `false\', start with digit, `{\', `[\' '
|
||||||
|
'are treated like strings. If VALUE is omitted '
|
||||||
|
'then corresponding key is removed.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-t', '--theme-override', metavar='THEME.KEY.KEY=VALUE', type=arg_to_unicode,
|
||||||
|
action='append',
|
||||||
|
help='Like above, but theme-specific. THEME should point to '
|
||||||
|
'an existing and used theme to have any effect, but it is fine '
|
||||||
|
'to use any theme here.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-R', '--renderer-arg',
|
||||||
|
metavar='KEY=VAL', type=arg_to_unicode, action='append',
|
||||||
|
help='Like above, but provides argument for renderer. Is supposed '
|
||||||
|
'to be used only by shell bindings to provide various data like '
|
||||||
|
'last-exit-code or last-pipe-status (they are not using '
|
||||||
|
'`--renderer-arg\' for historical resons: `--renderer-arg\' '
|
||||||
|
'was added later).'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-p', '--config-path', action='append', metavar='PATH',
|
||||||
|
help='Path to configuration directory. If it is present then '
|
||||||
|
'configuration files will only be seeked in the provided path. '
|
||||||
|
'May be provided multiple times to search in a list of directories.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--socket', metavar='ADDRESS', type=str,
|
||||||
|
help='Socket address to use in daemon clients. Is always UNIX domain '
|
||||||
|
'socket on linux and file socket on Mac OS X. Not used here, '
|
||||||
|
'present only for compatibility with other powerline clients. '
|
||||||
|
'This argument must always be the first one and be in a form '
|
||||||
|
'`--socket ADDRESS\': no `=\' or short form allowed '
|
||||||
|
'(in other powerline clients, not here).'
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def write_output(args, powerline, segment_info, write):
|
||||||
|
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=segment_info.get('mode', None),
|
||||||
|
):
|
||||||
|
if line:
|
||||||
|
write(line + '\n')
|
||||||
|
args.side = args.side[len('above'):]
|
||||||
|
|
||||||
|
if args.side:
|
||||||
|
rendered = powerline.render(
|
||||||
|
width=args.width,
|
||||||
|
side=args.side,
|
||||||
|
segment_info=segment_info,
|
||||||
|
mode=segment_info.get('mode', None),
|
||||||
|
)
|
||||||
|
write(rendered)
|
10
powerline-bin/powerline/config.py
Normal file
10
powerline-bin/powerline/config.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
POWERLINE_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
BINDINGS_DIRECTORY = os.path.join(POWERLINE_ROOT, 'powerline', 'bindings')
|
||||||
|
TMUX_CONFIG_DIRECTORY = os.path.join(BINDINGS_DIRECTORY, 'tmux')
|
||||||
|
DEFAULT_SYSTEM_CONFIG_DIR = None
|
124
powerline-bin/powerline/config_files/colors.json
Normal file
124
powerline-bin/powerline/config_files/colors.json
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
{
|
||||||
|
"colors": {
|
||||||
|
"black": 16,
|
||||||
|
"white": 231,
|
||||||
|
|
||||||
|
"green": 2,
|
||||||
|
"darkestgreen": 22,
|
||||||
|
"darkgreen": 28,
|
||||||
|
"mediumgreen": 70,
|
||||||
|
"brightgreen": 148,
|
||||||
|
|
||||||
|
"darkestcyan": 23,
|
||||||
|
"darkcyan": 74,
|
||||||
|
"mediumcyan": 117,
|
||||||
|
"brightcyan": 159,
|
||||||
|
|
||||||
|
"darkestblue": 24,
|
||||||
|
"darkblue": 31,
|
||||||
|
|
||||||
|
"red": 1,
|
||||||
|
"darkestred": 52,
|
||||||
|
"darkred": 88,
|
||||||
|
"mediumred": 124,
|
||||||
|
"brightred": 160,
|
||||||
|
"brightestred": 196,
|
||||||
|
|
||||||
|
"darkestpurple": 55,
|
||||||
|
"mediumpurple": 98,
|
||||||
|
"brightpurple": 189,
|
||||||
|
|
||||||
|
"darkorange": 94,
|
||||||
|
"mediumorange": 166,
|
||||||
|
"brightorange": 208,
|
||||||
|
"brightestorange": 214,
|
||||||
|
|
||||||
|
"yellow": 11,
|
||||||
|
"brightyellow": 220,
|
||||||
|
|
||||||
|
"gray0": 233,
|
||||||
|
"gray1": 235,
|
||||||
|
"gray2": 236,
|
||||||
|
"gray3": 239,
|
||||||
|
"gray4": 240,
|
||||||
|
"gray5": 241,
|
||||||
|
"gray6": 244,
|
||||||
|
"gray7": 245,
|
||||||
|
"gray8": 247,
|
||||||
|
"gray9": 250,
|
||||||
|
"gray10": 252,
|
||||||
|
|
||||||
|
"gray11": 234,
|
||||||
|
"gray90": 254,
|
||||||
|
|
||||||
|
"gray70": [249, "b3b3b3"],
|
||||||
|
|
||||||
|
"lightyellowgreen": 106,
|
||||||
|
"gold3": 178,
|
||||||
|
"orangered": 202,
|
||||||
|
|
||||||
|
"steelblue": 67,
|
||||||
|
"darkorange3": 166,
|
||||||
|
"skyblue1": 117,
|
||||||
|
"khaki1": 228,
|
||||||
|
|
||||||
|
"solarized:base03": [8, "002b36"],
|
||||||
|
"solarized:base02": [0, "073642"],
|
||||||
|
"solarized:base01": [10, "586e75"],
|
||||||
|
"solarized:base00": [11, "657b83"],
|
||||||
|
"solarized:base0": [12, "839496"],
|
||||||
|
"solarized:base1": [14, "93a1a1"],
|
||||||
|
"solarized:base2": [7, "eee8d5"],
|
||||||
|
"solarized:base3": [15, "fdf6e3"],
|
||||||
|
"solarized:yellow": [3, "b58900"],
|
||||||
|
"solarized:orange": [9, "cb4b16"],
|
||||||
|
"solarized:red": [1, "dc322f"],
|
||||||
|
"solarized:magenta": [5, "d33682"],
|
||||||
|
"solarized:violet": [13, "6c71c4"],
|
||||||
|
"solarized:blue": [4, "268bd2"],
|
||||||
|
"solarized:cyan": [6, "2aa198"],
|
||||||
|
"solarized:green": [2, "859900"]
|
||||||
|
},
|
||||||
|
"gradients": {
|
||||||
|
"dark_GREEN_Orange_red": [
|
||||||
|
[22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 94, 94, 94, 94, 94, 94, 94, 88, 52],
|
||||||
|
["006000", "006000", "006000", "006000", "006000", "006000", "006000", "006000", "006000", "036000", "076000", "0a6000", "0d6000", "106000", "126000", "146000", "166000", "186000", "1a6000", "1b6000", "1d6000", "1e6000", "206000", "216000", "236000", "246000", "256000", "266000", "286000", "296000", "2a6000", "2b6000", "2c6100", "2d6100", "2f6100", "306100", "316100", "326100", "336100", "346100", "356100", "366100", "376100", "386100", "386100", "396100", "3a6100", "3b6100", "3c6100", "3d6100", "3e6100", "3f6100", "406100", "406100", "416100", "426000", "436000", "446000", "456000", "456000", "466000", "476000", "486000", "496000", "496000", "4a6000", "4b6000", "4c6000", "4d6000", "4d6000", "4e6000", "4f6000", "506000", "506000", "516000", "526000", "536000", "536000", "546000", "556000", "566000", "566000", "576000", "586000", "596000", "596000", "5a6000", "5d6000", "616000", "646000", "686000", "6b6000", "6f6000", "726000", "766000", "796000", "7d6000", "806000", "7e5500", "6f3105", "5d0001"]
|
||||||
|
],
|
||||||
|
"GREEN_Orange_red": [
|
||||||
|
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1],
|
||||||
|
["005f00", "015f00", "025f00", "035f00", "045f00", "055f00", "065f00", "075f00", "085f00", "095f00", "0b5f00", "0c5f00", "0d5f00", "0e5f00", "0f5f00", "105f00", "115f00", "125f00", "135f00", "145f00", "165f00", "175f00", "185f00", "195f00", "1a5f00", "1b5f00", "1c5f00", "1d5f00", "1e5f00", "1f5f00", "215f00", "225f00", "235f00", "245f00", "255f00", "265f00", "275f00", "285f00", "295f00", "2a5f00", "2c5f00", "2d5f00", "2e5f00", "2f5f00", "305f00", "315f00", "325f00", "335f00", "345f00", "355f00", "375f00", "385f00", "395f00", "3a5f00", "3b5f00", "3c5f00", "3d5f00", "3e5f00", "3f5f00", "415f00", "425f00", "435f00", "445f00", "455f00", "465f00", "475f00", "485f00", "495f00", "4a5f00", "4c5f00", "4d5f00", "4e5f00", "4f5f00", "505f00", "515f00", "525f00", "535f00", "545f00", "555f00", "575f00", "585f00", "595f00", "5a5f00", "5b5f00", "5c5f00", "5d5f00", "5e5f00", "615f00", "655f00", "685f00", "6c5f00", "6f5f00", "735f00", "765f00", "7a5f00", "7d5f00", "815f00", "845f00", "815200", "702900"]
|
||||||
|
],
|
||||||
|
"green_yellow_red": [
|
||||||
|
[190, 184, 178, 172, 166, 160],
|
||||||
|
["8ae71c", "8ce71c", "8fe71c", "92e71c", "95e71d", "98e71d", "9ae71d", "9de71d", "a0e71e", "a3e71e", "a6e71e", "a8e71e", "abe71f", "aee71f", "b1e71f", "b4e71f", "b6e720", "b9e720", "bce720", "bfe720", "c2e821", "c3e721", "c5e621", "c7e521", "c9e522", "cbe422", "cde322", "cfe222", "d1e223", "d3e123", "d5e023", "d7df23", "d9df24", "dbde24", "dddd24", "dfdc24", "e1dc25", "e3db25", "e5da25", "e7d925", "e9d926", "e9d626", "e9d426", "e9d126", "e9cf27", "e9cc27", "e9ca27", "e9c727", "e9c528", "e9c228", "e9c028", "e9bd28", "e9bb29", "e9b829", "e9b629", "e9b329", "e9b12a", "e9ae2a", "e9ac2a", "e9a92a", "eaa72b", "eaa42b", "eaa22b", "ea9f2b", "ea9d2c", "ea9b2c", "ea982c", "ea962c", "ea942d", "ea912d", "ea8f2d", "ea8d2d", "ea8a2e", "ea882e", "ea862e", "ea832e", "ea812f", "ea7f2f", "ea7c2f", "ea7a2f", "eb7830", "eb7530", "eb7330", "eb7130", "eb6f31", "eb6c31", "eb6a31", "eb6831", "eb6632", "eb6332", "eb6132", "eb5f32", "eb5d33", "eb5a33", "eb5833", "eb5633", "eb5434", "eb5134", "eb4f34", "eb4d34", "ec4b35"]
|
||||||
|
],
|
||||||
|
"green_yellow_orange_red": [
|
||||||
|
[2, 3, 9, 1],
|
||||||
|
["719e07", "739d06", "759c06", "779c06", "799b06", "7b9a05", "7d9a05", "7f9905", "819805", "839805", "859704", "879704", "899604", "8b9504", "8d9504", "8f9403", "919303", "949303", "969203", "989102", "9a9102", "9c9002", "9e9002", "a08f02", "a28e01", "a48e01", "a68d01", "a88c01", "aa8c01", "ac8b00", "ae8a00", "b08a00", "b28900", "b58900", "b58700", "b68501", "b78302", "b78102", "b87f03", "b97d04", "b97b04", "ba7905", "bb7806", "bb7606", "bc7407", "bd7208", "bd7008", "be6e09", "bf6c0a", "bf6a0a", "c0690b", "c1670c", "c1650c", "c2630d", "c3610e", "c35f0e", "c45d0f", "c55b10", "c55a10", "c65811", "c75612", "c75412", "c85213", "c95014", "c94e14", "ca4c15", "cb4b16", "cb4a16", "cc4917", "cc4818", "cd4719", "cd4719", "ce461a", "ce451b", "cf441c", "cf441c", "d0431d", "d0421e", "d1411f", "d1411f", "d24020", "d23f21", "d33e22", "d33e22", "d43d23", "d43c24", "d53b25", "d53b25", "d63a26", "d63927", "d73828", "d73828", "d83729", "d8362a", "d9352b", "d9352b", "da342c", "da332d", "db322e", "dc322f"]
|
||||||
|
],
|
||||||
|
"yellow_red": [
|
||||||
|
[220, 178, 172, 166, 160],
|
||||||
|
["ffd700", "fdd500", "fbd300", "fad200", "f8d000", "f7cf00", "f5cd00", "f3cb00", "f2ca00", "f0c800", "efc700", "edc500", "ebc300", "eac200", "e8c000", "e7bf00", "e5bd00", "e3bb00", "e2ba00", "e0b800", "dfb700", "ddb500", "dbb300", "dab200", "d8b000", "d7af00", "d7ad00", "d7ab00", "d7aa00", "d7a800", "d7a700", "d7a500", "d7a300", "d7a200", "d7a000", "d79f00", "d79d00", "d79b00", "d79a00", "d79800", "d79700", "d79500", "d79300", "d79200", "d79000", "d78f00", "d78d00", "d78b00", "d78a00", "d78800", "d78700", "d78500", "d78300", "d78200", "d78000", "d77f00", "d77d00", "d77b00", "d77a00", "d77800", "d77700", "d77500", "d77300", "d77200", "d77000", "d76f00", "d76d00", "d76b00", "d76a00", "d76800", "d76700", "d76500", "d76300", "d76200", "d76000", "d75f00", "d75b00", "d75700", "d75300", "d74f00", "d74c00", "d74800", "d74400", "d74000", "d73c00", "d73900", "d73500", "d73100", "d72d00", "d72900", "d72600", "d72200", "d71e00", "d71a00", "d71600", "d71300", "d70f00", "d70b00", "d70700"]
|
||||||
|
],
|
||||||
|
"yellow_orange_red": [
|
||||||
|
[3, 9, 1],
|
||||||
|
["b58900", "b58700", "b58600", "b68501", "b68401", "b78202", "b78102", "b88003", "b87f03", "b87d03", "b97c04", "b97b04", "ba7a05", "ba7805", "bb7706", "bb7606", "bc7507", "bc7307", "bc7207", "bd7108", "bd7008", "be6e09", "be6d09", "bf6c0a", "bf6b0a", "c06a0b", "c0680b", "c0670b", "c1660c", "c1650c", "c2630d", "c2620d", "c3610e", "c3600e", "c35e0e", "c45d0f", "c45c0f", "c55b10", "c55910", "c65811", "c65711", "c75612", "c75412", "c75312", "c85213", "c85113", "c94f14", "c94e14", "ca4d15", "ca4c15", "cb4b16", "cb4a16", "cb4a17", "cc4917", "cc4918", "cc4818", "cd4819", "cd4719", "cd471a", "ce461a", "ce461b", "ce451b", "cf451c", "cf441c", "cf441d", "d0431d", "d0431e", "d0421e", "d1421f", "d1411f", "d14120", "d24020", "d24021", "d23f21", "d33f22", "d33e22", "d33e23", "d43d23", "d43d24", "d43c24", "d53c25", "d53b25", "d53b26", "d63a26", "d63a27", "d63927", "d73928", "d73828", "d73829", "d83729", "d8372a", "d8362a", "d9362b", "d9352b", "d9352c", "da342c", "da342d", "da332d", "db332e"]
|
||||||
|
],
|
||||||
|
"blue_red": [
|
||||||
|
[39, 74, 68, 67, 103, 97, 96, 132, 131, 167, 203, 197],
|
||||||
|
["19b4fe", "1bb2fc", "1db1fa", "1faff8", "22aef6", "24adf4", "26abf2", "29aaf0", "2ba9ee", "2da7ec", "30a6ea", "32a5e8", "34a3e6", "36a2e4", "39a0e2", "3b9fe1", "3d9edf", "409cdd", "429bdb", "449ad9", "4798d7", "4997d5", "4b96d3", "4d94d1", "5093cf", "5292cd", "5490cb", "578fc9", "598dc7", "5b8cc6", "5e8bc4", "6089c2", "6288c0", "6487be", "6785bc", "6984ba", "6b83b8", "6e81b6", "7080b4", "727eb2", "757db0", "777cae", "797aac", "7b79ab", "7e78a9", "8076a7", "8275a5", "8574a3", "8772a1", "89719f", "8c709d", "8e6e9b", "906d99", "926b97", "956a95", "976993", "996791", "9c668f", "9e658e", "a0638c", "a3628a", "a56188", "a75f86", "a95e84", "ac5c82", "ae5b80", "b05a7e", "b3587c", "b5577a", "b75678", "ba5476", "bc5374", "be5273", "c05071", "c34f6f", "c54e6d", "c74c6b", "ca4b69", "cc4967", "ce4865", "d14763", "d34561", "d5445f", "d7435d", "da415b", "dc4059", "de3f58", "e13d56", "e33c54", "e53a52", "e83950", "ea384e", "ec364c", "ee354a", "f13448", "f33246", "f53144", "f83042", "fa2e40"]
|
||||||
|
],
|
||||||
|
"white_red": [
|
||||||
|
[231, 255, 223, 216, 209, 202, 196],
|
||||||
|
["ffffff", "fefefe", "fdfdfd", "fdfdfd", "fcfcfc", "fbfbfb", "fafafa", "fafafa", "f9f9f9", "f8f8f8", "f7f7f7", "f7f7f7", "f6f6f6", "f5f5f5", "f4f4f4", "f4f3f4", "f3f3f3", "f2f2f2", "f1f1f1", "f0f0f0", "f0f0f0", "efefef", "eeeeee", "efecea", "f1eae4", "f2e8de", "f3e6d8", "f5e4d3", "f6e2cd", "f7e0c7", "f8dec2", "f9dcbc", "fadab6", "fad8b1", "fbd5ac", "fbd2a9", "fbcea5", "fbcaa1", "fbc79e", "fbc39a", "fbc097", "fbbc93", "fbb88f", "fbb58c", "fab188", "faad85", "faaa81", "fba67e", "fba37a", "fb9f76", "fb9c73", "fb986f", "fb946c", "fb9168", "fa8d65", "fa8961", "fa865c", "fa8256", "fb7f4f", "fb7b48", "fb7841", "fb743a", "fb7133", "fb6d2c", "fa6a23", "fa661a", "fa620e", "fa5f03", "fa5d03", "fa5b03", "fa5a03", "fa5803", "fa5703", "fa5503", "fa5303", "fa5103", "fa4f03", "fa4e03", "fa4c03", "fa4a04", "fa4804", "fa4604", "fa4404", "fa4204", "fa3f04", "fa3d04", "fa3b04", "fa3805", "fa3605", "fa3305", "fb3105", "fb2e05", "fb2a05", "fb2705", "fb2306", "fb1f06", "fb1b06", "fb1506", "fb0e06", "fa0506", "fa0007"]
|
||||||
|
],
|
||||||
|
"dark_green_gray": [
|
||||||
|
[70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247],
|
||||||
|
["51b000", "52b000", "54b000", "55b002", "56b007", "57b00d", "58b011", "59af15", "5aaf18", "5caf1b", "5daf1e", "5eaf21", "5faf23", "60ae25", "61ae27", "62ae2a", "63ae2c", "64ae2e", "65ae30", "66ae31", "67ad33", "68ad35", "69ad37", "69ad38", "6aad3a", "6bad3c", "6cac3d", "6dac3f", "6eac40", "6fac42", "70ac44", "70ac45", "71ab47", "72ab48", "73ab49", "74ab4b", "75ab4c", "75ab4e", "76aa4f", "77aa51", "78aa52", "79aa53", "79aa55", "7aaa56", "7ba957", "7ca959", "7ca95a", "7da95b", "7ea95d", "7fa95e", "7fa85f", "80a861", "81a862", "81a863", "82a865", "83a766", "83a767", "84a768", "85a76a", "85a76b", "86a66c", "87a66d", "87a66f", "88a670", "89a671", "89a672", "8aa574", "8ba575", "8ba576", "8ca577", "8da579", "8da47a", "8ea47b", "8ea47c", "8fa47d", "90a47f", "90a380", "91a381", "91a382", "92a384", "93a385", "93a286", "94a287", "94a288", "95a28a", "95a18b", "96a18c", "97a18d", "97a18e", "98a190", "98a091", "99a092", "99a093", "9aa094", "9aa096", "9b9f97", "9b9f98", "9c9f99", "9c9f9a", "9d9e9c", "9d9e9d"]
|
||||||
|
],
|
||||||
|
"light_green_gray": [
|
||||||
|
[148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 187, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250],
|
||||||
|
["a3d900", "a4d800", "a4d800", "a5d805", "a5d80d", "a6d714", "a6d719", "a6d71d", "a7d621", "a7d625", "a8d628", "a8d62b", "a8d52e", "a9d531", "a9d533", "aad536", "aad438", "aad43a", "abd43d", "abd33f", "abd341", "acd343", "acd345", "acd247", "add249", "add24b", "add14d", "aed14f", "aed151", "aed152", "afd054", "afd056", "afd058", "b0d059", "b0cf5b", "b0cf5d", "b1cf5e", "b1ce60", "b1ce62", "b1ce63", "b2ce65", "b2cd67", "b2cd68", "b3cd6a", "b3cc6b", "b3cc6d", "b3cc6e", "b4cc70", "b4cb71", "b4cb73", "b4cb75", "b5ca76", "b5ca78", "b5ca79", "b5ca7a", "b6c97c", "b6c97d", "b6c97f", "b6c880", "b6c882", "b7c883", "b7c885", "b7c786", "b7c788", "b7c789", "b8c68a", "b8c68c", "b8c68d", "b8c68f", "b8c590", "b9c591", "b9c593", "b9c494", "b9c496", "b9c497", "b9c498", "bac39a", "bac39b", "bac39d", "bac29e", "bac29f", "bac2a1", "bac2a2", "bac1a4", "bbc1a5", "bbc1a6", "bbc0a8", "bbc0a9", "bbc0aa", "bbc0ac", "bbbfad", "bbbfae", "bbbfb0", "bbbeb1", "bcbeb3", "bcbeb4", "bcbdb5", "bcbdb7", "bcbdb8", "bcbdb9", "bcbcbb"]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"name": "Default",
|
||||||
|
"groups": {
|
||||||
|
"information:additional": { "fg": "gray9", "bg": "gray4", "attrs": [] },
|
||||||
|
"information:regular": { "fg": "gray10", "bg": "gray4", "attrs": ["bold"] },
|
||||||
|
"information:highlighted": { "fg": "white", "bg": "gray4", "attrs": [] },
|
||||||
|
"information:priority": { "fg": "brightyellow", "bg": "mediumorange", "attrs": [] },
|
||||||
|
"warning:regular": { "fg": "white", "bg": "brightred", "attrs": ["bold"] },
|
||||||
|
"critical:failure": { "fg": "white", "bg": "darkestred", "attrs": [] },
|
||||||
|
"critical:success": { "fg": "white", "bg": "darkestgreen", "attrs": [] },
|
||||||
|
"background": { "fg": "white", "bg": "gray0", "attrs": [] },
|
||||||
|
"background:divider": { "fg": "gray5", "bg": "gray0", "attrs": [] },
|
||||||
|
"session": { "fg": "black", "bg": "gray10", "attrs": ["bold"] },
|
||||||
|
"date": { "fg": "gray8", "bg": "gray2", "attrs": [] },
|
||||||
|
"time": { "fg": "gray10", "bg": "gray2", "attrs": ["bold"] },
|
||||||
|
"time:divider": { "fg": "gray5", "bg": "gray2", "attrs": [] },
|
||||||
|
"email_alert": "warning:regular",
|
||||||
|
"email_alert_gradient": { "fg": "white", "bg": "yellow_orange_red", "attrs": ["bold"] },
|
||||||
|
"hostname": { "fg": "black", "bg": "gray10", "attrs": ["bold"] },
|
||||||
|
"weather": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"weather_temp_gradient": { "fg": "blue_red", "bg": "gray0", "attrs": [] },
|
||||||
|
"weather_condition_hot": { "fg": "khaki1", "bg": "gray0", "attrs": [] },
|
||||||
|
"weather_condition_snowy": { "fg": "skyblue1", "bg": "gray0", "attrs": [] },
|
||||||
|
"weather_condition_rainy": { "fg": "skyblue1", "bg": "gray0", "attrs": [] },
|
||||||
|
"uptime": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"external_ip": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"internal_ip": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"network_load": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"network_load_gradient": { "fg": "green_yellow_orange_red", "bg": "gray0", "attrs": [] },
|
||||||
|
"network_load_sent_gradient": "network_load_gradient",
|
||||||
|
"network_load_recv_gradient": "network_load_gradient",
|
||||||
|
"network_load:divider": "background:divider",
|
||||||
|
"system_load": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"system_load_gradient": { "fg": "green_yellow_orange_red", "bg": "gray0", "attrs": [] },
|
||||||
|
"environment": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"cpu_load_percent": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"cpu_load_percent_gradient": { "fg": "green_yellow_orange_red", "bg": "gray0", "attrs": [] },
|
||||||
|
"battery": { "fg": "gray8", "bg": "gray0", "attrs": [] },
|
||||||
|
"battery_gradient": { "fg": "white_red", "bg": "gray0", "attrs": [] },
|
||||||
|
"battery_full": { "fg": "red", "bg": "gray0", "attrs": [] },
|
||||||
|
"battery_empty": { "fg": "white", "bg": "gray0", "attrs": [] },
|
||||||
|
"player": { "fg": "gray10", "bg": "black", "attrs": [] },
|
||||||
|
"user": { "fg": "white", "bg": "darkblue", "attrs": ["bold"] },
|
||||||
|
"branch": { "fg": "gray9", "bg": "gray2", "attrs": [] },
|
||||||
|
"branch_dirty": { "fg": "brightyellow", "bg": "gray2", "attrs": [] },
|
||||||
|
"branch_clean": { "fg": "gray9", "bg": "gray2", "attrs": [] },
|
||||||
|
"branch:divider": { "fg": "gray7", "bg": "gray2", "attrs": [] },
|
||||||
|
"stash": "branch_dirty",
|
||||||
|
"stash:divider": "branch:divider",
|
||||||
|
"cwd": "information:additional",
|
||||||
|
"cwd:current_folder": "information:regular",
|
||||||
|
"cwd:divider": { "fg": "gray7", "bg": "gray4", "attrs": [] },
|
||||||
|
"virtualenv": { "fg": "white", "bg": "darkcyan", "attrs": [] },
|
||||||
|
"attached_clients": { "fg": "gray8", "bg": "gray0", "attrs": [] }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"groups": {
|
||||||
|
"prompt": "information:additional",
|
||||||
|
"prompt_count": "information:highlighted"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"groups": {
|
||||||
|
"current_code_name": "information:additional",
|
||||||
|
"current_context": "current_code_name",
|
||||||
|
"current_line": "information:regular",
|
||||||
|
"current_file": "information:regular"
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user