Skip to content

Instantly share code, notes, and snippets.

@zfogg
Forked from memeplex/base16.py
Created December 30, 2016 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zfogg/0c4a16679643395b299525b2ae1df0a2 to your computer and use it in GitHub Desktop.
Save zfogg/0c4a16679643395b299525b2ae1df0a2 to your computer and use it in GitHub Desktop.
Base16 default theme for ipython + pygments + prompt toolkit closely matching vim base16 theme.
# -*- coding: utf-8 -*-
"""
Base16 Default Dark by Chris Kempson (http://chriskempson.com).
IPython Template by Carlos Pita (carlosjosepita@gmail.com).
Created with Base16 Builder by Chris Kempson.
"""
from prompt_toolkit.terminal.vt100_output import _256_colors
from pygments.style import Style
from pygments.token import (Keyword, Name, Comment, String, Error, Text,
Number, Operator, Literal, Token)
# See http://chriskempson.com/projects/base16/ for a description of the role
# of the different colors in the base16 palette.
base00 = '#181818'
base01 = '#282828'
base02 = '#383838'
base03 = '#585858'
base04 = '#b8b8b8'
base05 = '#d8d8d8'
base06 = '#e8e8e8'
base07 = '#f8f8f8'
base08 = '#ab4642'
base09 = '#dc9656'
base0A = '#f7ca88'
base0B = '#a1b56c'
base0C = '#86c1b9'
base0D = '#7cafc2'
base0E = '#ba8baf'
base0F = '#a16946'
# See https://github.com/jonathanslenders/python-prompt-toolkit/issues/355
colors = (globals()['base0' + d] for d in '08BADEC5379F1246')
for i, color in enumerate(colors):
r, g, b = int(color[1:3], 16), int(color[3:5], 16), int(color[5:], 16)
_256_colors[r, g, b] = i + 6 if i > 8 else i
# See http://pygments.org/docs/tokens/ for a description of the different
# pygments tokens.
class Base16Style(Style):
background_color = base00
highlight_color = base02
default_style = base05
styles = {
Text: base05,
Error: '%s bold' % base08,
Comment: base03,
Keyword: base0E,
Keyword.Constant: base0D,
Keyword.Namespace: base0D,
Name.Builtin: base0D,
Name.Function: base0D,
Name.Class: base0D,
Name.Decorator: base0E,
Name.Exception: base08,
Number: base09,
Operator.Word: base0D,
Literal: base0B,
String: base0B
}
# See https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py
# for a description of prompt_toolkit related pseudo-tokens.
overrides = {
Token.Prompt: base0B,
Token.PromptNum: '%s bold' % base0B,
Token.OutPrompt: base08,
Token.OutPromptNum: '%s bold' % base08,
Token.Menu.Completions.Completion: 'bg:%s %s' % (base01, base04),
Token.Menu.Completions.Completion.Current: 'bg:%s %s' % (base04, base01),
Token.MatchingBracket.Other: 'bg:%s %s' % (base03, base00)
}
from base16 import Base16Style, overrides
from IPython.terminal import interactiveshell
def get_style_by_name(name, original=interactiveshell.get_style_by_name):
return Base16Style if name == 'base16' else original(name)
interactiveshell.get_style_by_name = get_style_by_name
c.TerminalInteractiveShell.highlighting_style = 'base16'
c.TerminalInteractiveShell.highlighting_style_overrides = overrides
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment