mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-03 16:04:41 +01:00
fix: xonfig web is not upto-date (#4606)
* fix: xonfig web is not upto-date it should load data from backend * refactor: update elm-compile module * feat: update `xonfig web` * todo: * style: * tmp * feat: implements colors page * feat: implement prompts page * feat: implement xontribs page * refactor: remove elm from project * fix: qa errors * docs: * test: add test for xonfig.web * fix: lru-cache call * feat: add env variable for sys level config dir * refactor: add method to handle post * feat: implement updating prompts * feat: implement xontribs update page * style: * fix: tests failure * feat: add variables page * feat: add abbrevs,aliases pages * feat: run xonfig web in main process this way we can update the current session * style: optimize imports * docs: * refactor: write .xonshrc as the old code * refactor: split file write functions
This commit is contained in:
parent
a00b6014fe
commit
0ea9dd8811
19 changed files with 4951 additions and 834 deletions
36
.github/workflows/elm.yml
vendored
36
.github/workflows/elm.yml
vendored
|
@ -1,36 +0,0 @@
|
|||
name: Check Elm
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
name: Python 3.7 Elm Check Ubuntu
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/conda_pkgs_dir
|
||||
key: elm-env-${{ hashFiles('ci/environment-elm.yml') }}
|
||||
restore-keys: |
|
||||
elm-env-
|
||||
- name: Setup conda
|
||||
uses: conda-incubator/setup-miniconda@v2
|
||||
with:
|
||||
activate-environment: elm-xonsh-test
|
||||
environment-file: ci/environment-elm.yml
|
||||
auto-update-conda: true
|
||||
python-version: 3.7
|
||||
condarc-file: ci/condarc.yml
|
||||
- shell: bash -l {0}
|
||||
run: |
|
||||
python -m pip install . --no-deps
|
||||
pushd xonsh/webconfig
|
||||
python -m xonsh elm-compile.xsh
|
||||
popd
|
|
@ -1,10 +0,0 @@
|
|||
name: elm-xonsh-test
|
||||
channels:
|
||||
- conda-forge
|
||||
- defaults
|
||||
dependencies:
|
||||
- python=3.7
|
||||
- pygments
|
||||
- elm
|
||||
- uglify-js
|
||||
- docutils
|
23
news/webconfig.rst
Normal file
23
news/webconfig.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* ``xonfig web`` can now update ``abbrevs/aliases/env-variables``.
|
||||
|
||||
**Changed:**
|
||||
|
||||
* ``xonfig web`` now shows latest xontribs available from ``xonsh.xontribs_meta``
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -10,9 +10,10 @@ import re
|
|||
import sys
|
||||
import json
|
||||
import pytest # noqa F401
|
||||
|
||||
import io
|
||||
from xonsh.tools import ON_WINDOWS
|
||||
from xonsh.xonfig import xonfig_main
|
||||
from xonsh.webconfig import main as web_main
|
||||
|
||||
|
||||
def test_xonfg_help(capsys, xession):
|
||||
|
@ -132,3 +133,62 @@ def test_xonfig_kernel_with_jupyter(monkeypatch, capsys, fake_lib, xession):
|
|||
def test_xonfig_kernel_no_jupyter(capsys, xession):
|
||||
with pytest.raises(ImportError):
|
||||
rc = xonfig_main(["jupyter-kernel"]) # noqa F841
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def request_factory():
|
||||
class MockSocket:
|
||||
def getsockname(self):
|
||||
return ("sockname",)
|
||||
|
||||
def sendall(self, data):
|
||||
self.data = data
|
||||
|
||||
class MockRequest:
|
||||
_sock = MockSocket()
|
||||
|
||||
def __init__(self, path: str, method: str):
|
||||
self._path = path
|
||||
self.data = b""
|
||||
self.method = method.upper()
|
||||
|
||||
def makefile(self, *args, **kwargs):
|
||||
if args[0] == "rb":
|
||||
return io.BytesIO(f"{self.method} {self._path} HTTP/1.0".encode())
|
||||
elif args[0] == "wb":
|
||||
return io.BytesIO(b"")
|
||||
else:
|
||||
raise ValueError("Unknown file type to make", args, kwargs)
|
||||
|
||||
def sendall(self, data):
|
||||
self.data = data
|
||||
|
||||
return MockRequest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def get_req(request_factory):
|
||||
from urllib import parse
|
||||
|
||||
def factory(path, data: "dict[str, str]|None" = None):
|
||||
if data:
|
||||
path = path + "?" + parse.urlencode(data)
|
||||
request = request_factory(path, "get")
|
||||
handle = web_main.XonshConfigHTTPRequestHandler(request, (0, 0), None)
|
||||
return request, handle, request.data.decode()
|
||||
|
||||
return factory
|
||||
|
||||
|
||||
class TestXonfigWeb:
|
||||
def test_colors_get(self, get_req):
|
||||
_, _, resp = get_req("/")
|
||||
assert "Colors" in resp
|
||||
|
||||
def test_xontribs_get(self, get_req):
|
||||
_, _, resp = get_req("/xontribs")
|
||||
assert "Xontribs" in resp
|
||||
|
||||
def test_prompts_get(self, get_req):
|
||||
_, _, resp = get_req("/prompts")
|
||||
assert "Prompts" in resp
|
||||
|
|
|
@ -667,12 +667,6 @@ def default_completer_dirs(env):
|
|||
]
|
||||
|
||||
|
||||
@default_value
|
||||
def xonfig_data_files(env):
|
||||
"""``['$XONSH_SYS_CONFIG_DIR/xonfig-data.json', '$XONSH_CONFIG_DIR/xonfig-data.json']``\n"""
|
||||
return get_config_paths(env, "xonfig-data.json")
|
||||
|
||||
|
||||
@default_value
|
||||
def xonsh_append_newline(env):
|
||||
"""Appends a newline if we are in interactive mode"""
|
||||
|
@ -2156,6 +2150,11 @@ class Env(cabc.MutableMapping):
|
|||
else:
|
||||
return default
|
||||
|
||||
def get_stringified(self, key, default=None):
|
||||
value = self.get(key, default)
|
||||
detyper = self.get_detyper(key)
|
||||
return detyper(value)
|
||||
|
||||
def rawkeys(self):
|
||||
"""An iterator that returns all environment keys in their original form.
|
||||
This include string & compiled regular expression keys.
|
||||
|
@ -2281,6 +2280,11 @@ class Env(cabc.MutableMapping):
|
|||
"""
|
||||
self._vars.pop(name)
|
||||
|
||||
def is_configurable(self, name):
|
||||
if name not in self._vars:
|
||||
return False
|
||||
return self._vars[name].is_configurable
|
||||
|
||||
|
||||
class InternalEnvironDict(ChainMap):
|
||||
"""A dictionary which supports thread-local overrides.
|
||||
|
|
|
@ -1,281 +0,0 @@
|
|||
#!/usr/bin/env xonsh
|
||||
"""script for compiling elm source and dumping it to the js folder."""
|
||||
import os
|
||||
import io
|
||||
import tempfile
|
||||
from pprint import pprint
|
||||
|
||||
import pygments
|
||||
from pygments.lexers import Python3Lexer
|
||||
from pygments.formatters.html import HtmlFormatter
|
||||
|
||||
from xonsh.tools import print_color, format_color
|
||||
from xonsh.style_tools import partial_color_tokenize
|
||||
from xonsh.color_tools import rgb_to_ints
|
||||
from xonsh.pygments_cache import get_all_styles
|
||||
from xonsh.pyghooks import XonshStyle, xonsh_style_proxy, XonshHtmlFormatter, Token, XonshLexer
|
||||
from xonsh.prompt.base import PromptFormatter
|
||||
from xonsh.xontribs_meta import get_xontribs, Xontrib
|
||||
|
||||
|
||||
$RAISE_SUBPROC_ERROR = True
|
||||
$XONSH_SHOW_TRACEBACK = False
|
||||
|
||||
#
|
||||
# helper funcs
|
||||
#
|
||||
|
||||
def escape(s):
|
||||
return s.replace("\n", "").replace('"', '\\"')
|
||||
|
||||
|
||||
def invert_color(orig):
|
||||
r, g, b = rgb_to_ints(orig)
|
||||
inverted = [255 - r, 255 - g, 255 - b]
|
||||
new = [hex(n)[2:] for n in inverted]
|
||||
new = [n if len(n) == 2 else '0' + n for n in new]
|
||||
return ''.join(new)
|
||||
|
||||
|
||||
def html_format(s, style="default"):
|
||||
buf = io.StringIO()
|
||||
proxy_style = xonsh_style_proxy(XonshStyle(style))
|
||||
# make sure we have a foreground color
|
||||
fgcolor = proxy_style._styles[Token.Text][0]
|
||||
if not fgcolor:
|
||||
fgcolor = invert_color(proxy_style.background_color[1:].strip('#'))
|
||||
# need to generate stream before creating formatter so that all tokens actually exist
|
||||
if isinstance(s, str):
|
||||
token_stream = partial_color_tokenize(s)
|
||||
else:
|
||||
token_stream = s
|
||||
formatter = XonshHtmlFormatter(
|
||||
wrapcode=True,
|
||||
noclasses=True,
|
||||
style=proxy_style,
|
||||
prestyles="margin: 0em; padding: 0.5em 0.1em; color: #" + fgcolor,
|
||||
cssstyles="border-style: solid; border-radius: 5px",
|
||||
)
|
||||
formatter.format(token_stream, buf)
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
def rst_to_html(s):
|
||||
template = "%(body)s"
|
||||
with tempfile.NamedTemporaryFile('w+') as t, tempfile.NamedTemporaryFile('w+') as f:
|
||||
t.write(template)
|
||||
t.flush()
|
||||
f.write(s)
|
||||
f.flush()
|
||||
html = $(rst2html5.py --template @(t.name) @(f.name))
|
||||
return html
|
||||
|
||||
|
||||
#
|
||||
# first, write out elm-src/XonshData.elm
|
||||
#
|
||||
XONSH_DATA_HEADER = """-- A collection of xonsh values for the web-ui
|
||||
-- This file has been auto-generated by elm-compile.xsh
|
||||
module XonshData exposing (..)
|
||||
|
||||
import List
|
||||
import String
|
||||
|
||||
"""
|
||||
|
||||
# render prompts
|
||||
PROMPTS = [
|
||||
("default", '{env_name}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}'
|
||||
'{branch_color}{curr_branch: {}}{RESET} {BOLD_BLUE}'
|
||||
'{prompt_end}{RESET} '),
|
||||
("debian chroot", '{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{RESET}> '),
|
||||
("minimalist", '{BOLD_GREEN}{cwd_base}{RESET} ) '),
|
||||
("terlar", '{env_name}{BOLD_GREEN}{user}{RESET}@{hostname}:'
|
||||
'{BOLD_GREEN}{cwd}{RESET}|{gitstatus}\\n{BOLD_INTENSE_RED}➤{RESET} '),
|
||||
("default with git status", '{env_name}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}'
|
||||
'{branch_color}{gitstatus: {}}{RESET} {BOLD_BLUE}'
|
||||
'{prompt_end}{RESET} '),
|
||||
("robbyrussell", '{BOLD_INTENSE_RED}➜ {CYAN}{cwd_base} {gitstatus}{RESET} '),
|
||||
("just a dollar", "$ "),
|
||||
("simple pythonista", "{INTENSE_RED}{user}{RESET} at {INTENSE_PURPLE}{hostname}{RESET} "
|
||||
"in {BOLD_GREEN}{cwd}{RESET}\\n↪ "),
|
||||
("informative", "[{localtime}] {YELLOW}{env_name} {BOLD_BLUE}{user}@{hostname} "
|
||||
"{BOLD_GREEN}{cwd} {gitstatus}{RESET}\\n> "),
|
||||
("informative Version Control", "{YELLOW}{env_name} "
|
||||
"{BOLD_GREEN}{cwd} {gitstatus}{RESET} {prompt_end} "),
|
||||
("classic", "{user}@{hostname} {BOLD_GREEN}{cwd}{RESET}> "),
|
||||
("classic with git status", "{gitstatus} {RESET}{user}@{hostname} {BOLD_GREEN}{cwd}{RESET}> "),
|
||||
("screen savvy", "{YELLOW}{user}@{PURPLE}{hostname}{BOLD_GREEN}{cwd}{RESET}> "),
|
||||
("sorin", "{CYAN}{cwd} {INTENSE_RED}❯{INTENSE_YELLOW}❯{INTENSE_GREEN}❯{RESET} "),
|
||||
("acidhub", "❰{INTENSE_GREEN}{user}{RESET}❙{YELLOW}{cwd}{RESET}{env_name}❱{gitstatus}≻ "),
|
||||
("nim", "{INTENSE_GREEN}┬─[{YELLOW}{user}{RESET}@{BLUE}{hostname}{RESET}:{cwd}"
|
||||
"{INTENSE_GREEN}]─[{localtime}]─[{RESET}G:{INTENSE_GREEN}{curr_branch}=]"
|
||||
"\\n{INTENSE_GREEN}╰─>{INTENSE_RED}{prompt_end}{RESET} "),
|
||||
]
|
||||
|
||||
prompt_header = """type alias PromptData =
|
||||
{ name : String
|
||||
, value : String
|
||||
, display : String
|
||||
}
|
||||
|
||||
prompts : List PromptData
|
||||
prompts ="""
|
||||
|
||||
def render_prompts(lines):
|
||||
print_color("Rendering {GREEN}prompts{RESET}")
|
||||
prompt_format = PromptFormatter()
|
||||
fields = dict($PROMPT_FIELDS)
|
||||
fields.update(
|
||||
cwd="~/snail/stuff",
|
||||
cwd_base="stuff",
|
||||
user="lou",
|
||||
hostname="carcolh",
|
||||
env_name=fields['env_prefix'] + "env" + fields["env_postfix"],
|
||||
curr_branch="branch",
|
||||
gitstatus="{CYAN}branch|{BOLD_BLUE}+2{RESET}⚑7",
|
||||
branch_color="{BOLD_INTENSE_RED}",
|
||||
localtime="15:56:07",
|
||||
)
|
||||
lines.append(prompt_header)
|
||||
for i, (name, template) in enumerate(PROMPTS):
|
||||
display = html_format(prompt_format(template, fields=fields))
|
||||
item = 'name = "' + name + '", '
|
||||
item += 'value = "' + escape(template) + '", '
|
||||
item += 'display = "' + escape(display) + '"'
|
||||
pre = " [ " if i == 0 else " , "
|
||||
lines.append(pre + "{ " + item + " }")
|
||||
lines.append(" ]")
|
||||
|
||||
|
||||
# render color data
|
||||
|
||||
color_header = """
|
||||
type alias ColorData =
|
||||
{ name : String
|
||||
, display : String
|
||||
}
|
||||
|
||||
colors : List ColorData
|
||||
colors ="""
|
||||
|
||||
def render_colors(lines):
|
||||
print_color("Rendering {GREEN}color styles{RESET}")
|
||||
source = (
|
||||
'import sys\n'
|
||||
'echo "Welcome $USER on" @(sys.platform)\n\n'
|
||||
'def func(x=42):\n'
|
||||
' d = {"xonsh": True}\n'
|
||||
' return d.get("xonsh") and you\n\n'
|
||||
'# This is a comment\n'
|
||||
'![env | uniq | sort | grep PATH]\n'
|
||||
)
|
||||
lexer = XonshLexer()
|
||||
lexer.add_filter('tokenmerge')
|
||||
token_stream = list(pygments.lex(source, lexer=lexer))
|
||||
token_stream = [(t, s.replace("\n", "\\n")) for t, s in token_stream]
|
||||
lines.append(color_header)
|
||||
styles = sorted(get_all_styles())
|
||||
styles.insert(0, styles.pop(styles.index("default")))
|
||||
for i, style in enumerate(styles):
|
||||
display = html_format(token_stream, style=style)
|
||||
item = 'name = "' + style + '", '
|
||||
item += 'display = "' + escape(display) + '"'
|
||||
pre = " [ " if i == 0 else " , "
|
||||
lines.append(pre + "{ " + item + " }")
|
||||
lines.append(" ]")
|
||||
|
||||
|
||||
# render xontrib data
|
||||
|
||||
xontrib_header = """
|
||||
type alias XontribData =
|
||||
{ name : String
|
||||
, url : String
|
||||
, license : String
|
||||
, description : String
|
||||
}
|
||||
|
||||
xontribs : List XontribData
|
||||
xontribs ="""
|
||||
|
||||
|
||||
def get_xontrib_item(xontrib_name: str, xontrib: Xontrib):
|
||||
item = 'name = "' + xontrib_name + '", '
|
||||
item += 'url = "' + xontrib.url + '", '
|
||||
item += 'license = "' + (xontrib.package.license if xontrib.package else "") + '", '
|
||||
d = rst_to_html("".join(xontrib.description)).replace("\n", "\\n")
|
||||
item += 'description = "' + escape(d) + '"'
|
||||
return item
|
||||
|
||||
|
||||
def render_xontribs(lines):
|
||||
print_color("Rendering {GREEN}xontribs{RESET}")
|
||||
lines.append(xontrib_header)
|
||||
md = get_xontribs()
|
||||
for i, xontrib_name in enumerate(md):
|
||||
xontrib = md[xontrib_name]
|
||||
item = get_xontrib_item(xontrib_name, xontrib)
|
||||
pre = " [ " if i == 0 else " , "
|
||||
lines.append(pre + "{ " + item + " }")
|
||||
lines.append(" ]")
|
||||
|
||||
|
||||
def write_xonsh_data():
|
||||
# write XonshData.elm
|
||||
lines = [XONSH_DATA_HEADER]
|
||||
render_prompts(lines)
|
||||
render_colors(lines)
|
||||
render_xontribs(lines)
|
||||
src = "\n".join(lines) + "\n"
|
||||
xdelm = os.path.join('elm-src', 'XonshData.elm')
|
||||
with open(xdelm, 'w') as f:
|
||||
f.write(src)
|
||||
|
||||
|
||||
#
|
||||
# now compile the sources
|
||||
#
|
||||
SOURCES = [
|
||||
'App.elm',
|
||||
]
|
||||
with ${...}.swap(RAISE_SUBPROC_ERROR=False):
|
||||
HAVE_UGLIFY = bool(!(which uglifyjs e>o))
|
||||
|
||||
UGLIFY_FLAGS = ('pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",'
|
||||
'pure_getters,keep_fargs=false,unsafe_comps,unsafe')
|
||||
|
||||
|
||||
def compile():
|
||||
for source in SOURCES:
|
||||
base = os.path.splitext(source.lower())[0]
|
||||
src = os.path.join('elm-src', source)
|
||||
js_target = os.path.join('js', base + '.js')
|
||||
print_color('Compiling {YELLOW}' + src + '{RESET} -> {GREEN}' +
|
||||
js_target + '{RESET}')
|
||||
$XONSH_SHOW_TRACEBACK = False
|
||||
try:
|
||||
![elm make --optimize --output @(js_target) @(src)]
|
||||
except Exception:
|
||||
import sys
|
||||
sys.exit(1)
|
||||
new_files = [js_target]
|
||||
min_target = os.path.join('js', base + '.min.js')
|
||||
if os.path.exists(min_target):
|
||||
![rm -v @(min_target)]
|
||||
if HAVE_UGLIFY:
|
||||
print_color('Minifying {YELLOW}' + js_target + '{RESET} -> {GREEN}' +
|
||||
min_target + '{RESET}')
|
||||
![uglifyjs @(js_target) --compress @(UGLIFY_FLAGS) |
|
||||
uglifyjs --mangle --output @(min_target)]
|
||||
new_files.append(min_target)
|
||||
![ls -l @(new_files)]
|
||||
|
||||
|
||||
def main():
|
||||
write_xonsh_data()
|
||||
compile()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,228 +0,0 @@
|
|||
import Browser
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Html.Attributes exposing (class, style, href)
|
||||
import Html.Parser
|
||||
import Html.Parser.Util
|
||||
import Http
|
||||
import Maybe exposing (withDefault)
|
||||
import Set
|
||||
import Set exposing (Set)
|
||||
import List
|
||||
import String
|
||||
import Json.Decode
|
||||
import Json.Decode as Decode
|
||||
import Json.Encode as Encode
|
||||
import Bootstrap.Tab as Tab
|
||||
import Bootstrap.CDN as CDN
|
||||
import Bootstrap.Card as Card
|
||||
import Bootstrap.Text as Text
|
||||
import Bootstrap.Grid as Grid
|
||||
import Bootstrap.Grid.Row as Row
|
||||
import Bootstrap.Card.Block as Block
|
||||
import Bootstrap.Button as Button
|
||||
import Bootstrap.ListGroup as ListGroup
|
||||
import XonshData
|
||||
import XonshData exposing (PromptData, ColorData, XontribData)
|
||||
|
||||
|
||||
-- example with animation, you can drop the subscription part when not using animations
|
||||
type alias Model =
|
||||
{ tabState : Tab.State
|
||||
, promptValue : PromptData
|
||||
, colorValue : ColorData
|
||||
, xontribs : (Set String)
|
||||
--, response : Maybe PostResponse
|
||||
, error : Maybe Http.Error
|
||||
}
|
||||
|
||||
init : ( Model, Cmd Msg )
|
||||
init =
|
||||
( { tabState = Tab.initialState
|
||||
, promptValue = withDefault {name = "unknown", value = "$ ", display = ""}
|
||||
(List.head XonshData.prompts)
|
||||
, colorValue = withDefault {name = "unknown", display = ""}
|
||||
(List.head XonshData.colors)
|
||||
, xontribs = Set.empty
|
||||
--, response = Nothing
|
||||
, error = Nothing
|
||||
}
|
||||
, Cmd.none )
|
||||
|
||||
type Msg
|
||||
= TabMsg Tab.State
|
||||
| PromptSelect PromptData
|
||||
| ColorSelect ColorData
|
||||
| XontribAdded XontribData
|
||||
| XontribRemoved XontribData
|
||||
| SaveClicked
|
||||
| Response (Result Http.Error ())
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
TabMsg state ->
|
||||
( { model | tabState = state }
|
||||
, Cmd.none
|
||||
)
|
||||
PromptSelect value ->
|
||||
( { model | promptValue = value }
|
||||
, Cmd.none
|
||||
)
|
||||
ColorSelect value ->
|
||||
( { model | colorValue = value }
|
||||
, Cmd.none
|
||||
)
|
||||
XontribAdded value ->
|
||||
( { model | xontribs = Set.insert value.name model.xontribs }
|
||||
, Cmd.none
|
||||
)
|
||||
XontribRemoved value ->
|
||||
( { model | xontribs = Set.remove value.name model.xontribs }
|
||||
, Cmd.none
|
||||
)
|
||||
SaveClicked ->
|
||||
-- ( { model | error = Nothing, response = Nothing }
|
||||
( { model | error = Nothing}
|
||||
, saveSettings model
|
||||
)
|
||||
Response (Ok response) ->
|
||||
--( { model | error = Nothing, response = Just response }, Cmd.none )
|
||||
( { model | error = Nothing }, Cmd.none )
|
||||
Response (Err error) ->
|
||||
--( { model | error = Just error, response = Nothing }, Cmd.none )
|
||||
( { model | error = Just error }, Cmd.none )
|
||||
|
||||
encodeModel : Model -> Encode.Value
|
||||
encodeModel model =
|
||||
Encode.object
|
||||
[ ("prompt", Encode.string model.promptValue.value)
|
||||
, ("colors", Encode.string model.colorValue.name)
|
||||
, ("xontribs", Encode.set Encode.string model.xontribs)
|
||||
]
|
||||
|
||||
saveSettings : Model -> Cmd Msg
|
||||
saveSettings model =
|
||||
Http.post
|
||||
{ url = "/save"
|
||||
, body = Http.stringBody "application/json" (Encode.encode 0 (encodeModel model))
|
||||
, expect = Http.expectWhatever Response
|
||||
}
|
||||
|
||||
-- VIEWS
|
||||
|
||||
textHtml : String -> List (Html.Html msg)
|
||||
textHtml t =
|
||||
case Html.Parser.run t of
|
||||
Ok nodes ->
|
||||
Html.Parser.Util.toVirtualDom nodes
|
||||
|
||||
Err _ ->
|
||||
[]
|
||||
|
||||
promptButton : PromptData -> (ListGroup.CustomItem Msg)
|
||||
promptButton pd =
|
||||
ListGroup.button
|
||||
[ ListGroup.attrs [ onClick (PromptSelect pd) ]
|
||||
, ListGroup.info
|
||||
]
|
||||
[ text pd.name
|
||||
, p [] []
|
||||
, span [] (textHtml pd.display)
|
||||
]
|
||||
|
||||
colorButton : ColorData -> (ListGroup.CustomItem Msg)
|
||||
colorButton cd =
|
||||
ListGroup.button
|
||||
[ ListGroup.attrs [ onClick (ColorSelect cd) ]
|
||||
, ListGroup.info
|
||||
]
|
||||
[ text cd.name
|
||||
, p [] []
|
||||
, span [] (textHtml cd.display)
|
||||
]
|
||||
|
||||
|
||||
centeredDeck : List (Card.Config msg) -> Html.Html msg
|
||||
centeredDeck cards =
|
||||
Html.div
|
||||
[ class "card-deck justify-content-center" ]
|
||||
(List.map Card.view cards)
|
||||
|
||||
xontribCard : Model -> XontribData -> Card.Config Msg
|
||||
xontribCard model xd =
|
||||
Card.config [ Card.attrs
|
||||
[ style "min-width" "20em"
|
||||
, style "max-width" "20em"
|
||||
, style "padding" "0.25em"
|
||||
, style "margin" "0.5em"
|
||||
] ]
|
||||
|> Card.headerH3 [] [ a [href xd.url] [ text xd.name ] ]
|
||||
|> Card.block [] [ Block.text [] ( textHtml xd.description ) ]
|
||||
|> Card.footer []
|
||||
[ if Set.member xd.name model.xontribs then
|
||||
Button.button [ Button.danger
|
||||
, Button.attrs [ onClick (XontribRemoved xd) ]
|
||||
] [ text "Remove" ]
|
||||
else
|
||||
Button.button [ Button.success
|
||||
, Button.attrs [ onClick (XontribAdded xd) ]
|
||||
] [ text "Add" ]
|
||||
]
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
div [style "padding" "0.75em 1.25em"]
|
||||
[ Grid.container []
|
||||
[ Grid.row []
|
||||
[ Grid.col [] [ div [ style "text-align" "left"] [ h2 [] [text "xonsh"] ] ]
|
||||
, Grid.col [] [ div [ style "text-align" "right"]
|
||||
[ Button.button [ Button.success
|
||||
, Button.attrs [ onClick SaveClicked ]
|
||||
] [ text "Save" ]
|
||||
] ]
|
||||
]
|
||||
]
|
||||
, p [] []
|
||||
, Tab.config TabMsg
|
||||
|> Tab.center
|
||||
|> Tab.items
|
||||
[ Tab.item
|
||||
{ id = "tabItemColors"
|
||||
, link = Tab.link [] [ text "Colors" ]
|
||||
, pane = Tab.pane []
|
||||
[ text ("Current Selection: " ++ model.colorValue.name)
|
||||
, p [] []
|
||||
, div [style "padding" "0.75em 1.25em"] (textHtml model.colorValue.display)
|
||||
, ListGroup.custom (List.map colorButton XonshData.colors)
|
||||
]
|
||||
}
|
||||
, Tab.item
|
||||
{ id = "tabItemPrompt"
|
||||
, link = Tab.link [] [ text "Prompt" ]
|
||||
, pane = Tab.pane []
|
||||
[ text ("Current Selection: " ++ model.promptValue.name)
|
||||
, p [] []
|
||||
, div [style "padding" "0.75em 1.25em"] (textHtml model.promptValue.display)
|
||||
, ListGroup.custom (List.map promptButton XonshData.prompts)
|
||||
]
|
||||
}
|
||||
, Tab.item
|
||||
{ id = "tabItemXontribs"
|
||||
, link = Tab.link [] [ text "Xontribs" ]
|
||||
, pane = Tab.pane [] [ centeredDeck (List.map (xontribCard model) XonshData.xontribs) ]
|
||||
}
|
||||
]
|
||||
|> Tab.view model.tabState
|
||||
]
|
||||
|
||||
|
||||
main : Program Decode.Value Model Msg
|
||||
main =
|
||||
Browser.element
|
||||
{ init = \_ -> init
|
||||
, view = view
|
||||
, update = update
|
||||
, subscriptions = \_ -> Sub.none
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
-- A collection of xonsh values for the web-ui
|
||||
-- This file has been auto-generated by elm-compile.xsh
|
||||
module XonshData exposing (..)
|
||||
|
||||
import List
|
||||
import String
|
||||
|
||||
|
||||
type alias PromptData =
|
||||
{ name : String
|
||||
, value : String
|
||||
, display : String
|
||||
}
|
||||
|
||||
prompts : List PromptData
|
||||
prompts =
|
||||
[ { name = "default", value = "{env_name}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{branch_color}{curr_branch: {}}{RESET} {BOLD_BLUE}{prompt_end}{RESET} ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"\">(env) </span><span style=\"color: #007f00; font-weight: bold\">lou@carcolh</span><span style=\"color: #00007f; font-weight: bold\"> ~/snail/stuff</span><span style=\"color: #ff0000; font-weight: bold\"> branch</span><span style=\"\"> </span><span style=\"color: #00007f; font-weight: bold\">$</span><span style=\"\"> </span></code></pre></div>" }
|
||||
, { name = "debian chroot", value = "{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{RESET}> ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #007f00; font-weight: bold\">lou@carcolh</span><span style=\"color: #00007f; font-weight: bold\"> ~/snail/stuff</span><span style=\"\">> </span></code></pre></div>" }
|
||||
, { name = "minimalist", value = "{BOLD_GREEN}{cwd_base}{RESET} ) ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #007f00; font-weight: bold\">stuff</span><span style=\"\"> ) </span></code></pre></div>" }
|
||||
, { name = "terlar", value = "{env_name}{BOLD_GREEN}{user}{RESET}@{hostname}:{BOLD_GREEN}{cwd}{RESET}|{gitstatus}\n{BOLD_INTENSE_RED}➤{RESET} ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"\">(env) </span><span style=\"color: #007f00; font-weight: bold\">lou</span><span style=\"\">@carcolh:</span><span style=\"color: #007f00; font-weight: bold\">~/snail/stuff</span><span style=\"\">|</span><span style=\"color: #007f7f\">branch|</span><span style=\"color: #00007f; font-weight: bold\">+2</span><span style=\"\">⚑7\n</span><span style=\"color: #ff0000; font-weight: bold\">➤</span><span style=\"\"> </span></code></pre></div>" }
|
||||
, { name = "default with git status", value = "{env_name}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{branch_color}{gitstatus: {}}{RESET} {BOLD_BLUE}{prompt_end}{RESET} ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"\">(env) </span><span style=\"color: #007f00; font-weight: bold\">lou@carcolh</span><span style=\"color: #00007f; font-weight: bold\"> ~/snail/stuff</span><span style=\"color: #ff0000; font-weight: bold\"> </span><span style=\"color: #007f7f\">branch|</span><span style=\"color: #00007f; font-weight: bold\">+2</span><span style=\"\">⚑7 </span><span style=\"color: #00007f; font-weight: bold\">$</span><span style=\"\"> </span></code></pre></div>" }
|
||||
, { name = "robbyrussell", value = "{BOLD_INTENSE_RED}➜ {CYAN}{cwd_base} {gitstatus}{RESET} ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #ff0000; font-weight: bold\">➜ </span><span style=\"color: #007f7f\">stuff branch|</span><span style=\"color: #00007f; font-weight: bold\">+2</span><span style=\"\">⚑7 </span></code></pre></div>" }
|
||||
, { name = "just a dollar", value = "$ ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"\">$ </span></code></pre></div>" }
|
||||
, { name = "simple pythonista", value = "{INTENSE_RED}{user}{RESET} at {INTENSE_PURPLE}{hostname}{RESET} in {BOLD_GREEN}{cwd}{RESET}\n↪ ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #ff0000\">lou</span><span style=\"\"> at </span><span style=\"color: #ff00ff\">carcolh</span><span style=\"\"> in </span><span style=\"color: #007f00; font-weight: bold\">~/snail/stuff</span><span style=\"\">\n↪ </span></code></pre></div>" }
|
||||
, { name = "informative", value = "[{localtime}] {YELLOW}{env_name} {BOLD_BLUE}{user}@{hostname} {BOLD_GREEN}{cwd} {gitstatus}{RESET}\n> ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"\">[15:56:07] </span><span style=\"color: #7f7fe0\">(env) </span><span style=\"color: #00007f; font-weight: bold\">lou@carcolh </span><span style=\"color: #007f00; font-weight: bold\">~/snail/stuff </span><span style=\"color: #007f7f\">branch|</span><span style=\"color: #00007f; font-weight: bold\">+2</span><span style=\"\">⚑7\n> </span></code></pre></div>" }
|
||||
, { name = "informative Version Control", value = "{YELLOW}{env_name} {BOLD_GREEN}{cwd} {gitstatus}{RESET} {prompt_end} ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #7f7fe0\">(env) </span><span style=\"color: #007f00; font-weight: bold\">~/snail/stuff </span><span style=\"color: #007f7f\">branch|</span><span style=\"color: #00007f; font-weight: bold\">+2</span><span style=\"\">⚑7 $ </span></code></pre></div>" }
|
||||
, { name = "classic", value = "{user}@{hostname} {BOLD_GREEN}{cwd}{RESET}> ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"\">lou@carcolh </span><span style=\"color: #007f00; font-weight: bold\">~/snail/stuff</span><span style=\"\">> </span></code></pre></div>" }
|
||||
, { name = "classic with git status", value = "{gitstatus} {RESET}{user}@{hostname} {BOLD_GREEN}{cwd}{RESET}> ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #007f7f\">branch|</span><span style=\"color: #00007f; font-weight: bold\">+2</span><span style=\"\">⚑7 lou@carcolh </span><span style=\"color: #007f00; font-weight: bold\">~/snail/stuff</span><span style=\"\">> </span></code></pre></div>" }
|
||||
, { name = "screen savvy", value = "{YELLOW}{user}@{PURPLE}{hostname}{BOLD_GREEN}{cwd}{RESET}> ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #7f7fe0\">lou@</span><span style=\"color: #7f007f\">carcolh</span><span style=\"color: #007f00; font-weight: bold\">~/snail/stuff</span><span style=\"\">> </span></code></pre></div>" }
|
||||
, { name = "sorin", value = "{CYAN}{cwd} {INTENSE_RED}❯{INTENSE_YELLOW}❯{INTENSE_GREEN}❯{RESET} ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #007f7f\">~/snail/stuff </span><span style=\"color: #ff0000\">❯</span><span style=\"color: #ffff00\">❯</span><span style=\"color: #00ff00\">❯</span><span style=\"\"> </span></code></pre></div>" }
|
||||
, { name = "acidhub", value = "❰{INTENSE_GREEN}{user}{RESET}❙{YELLOW}{cwd}{RESET}{env_name}❱{gitstatus}≻ ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"\">❰</span><span style=\"color: #00ff00\">lou</span><span style=\"\">❙</span><span style=\"color: #7f7fe0\">~/snail/stuff</span><span style=\"\">(env) ❱</span><span style=\"color: #007f7f\">branch|</span><span style=\"color: #00007f; font-weight: bold\">+2</span><span style=\"\">⚑7≻ </span></code></pre></div>" }
|
||||
, { name = "nim", value = "{INTENSE_GREEN}┬─[{YELLOW}{user}{RESET}@{BLUE}{hostname}{RESET}:{cwd}{INTENSE_GREEN}]─[{localtime}]─[{RESET}G:{INTENSE_GREEN}{curr_branch}=]\n{INTENSE_GREEN}╰─>{INTENSE_RED}{prompt_end}{RESET} ", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #00ff00\">┬─[</span><span style=\"color: #7f7fe0\">lou</span><span style=\"\">@</span><span style=\"color: #00007f\">carcolh</span><span style=\"\">:~/snail/stuff</span><span style=\"color: #00ff00\">]─[15:56:07]─[</span><span style=\"\">G:</span><span style=\"color: #00ff00\">branch=]\n╰─></span><span style=\"color: #ff0000\">$</span><span style=\"\"> </span></code></pre></div>" }
|
||||
]
|
||||
|
||||
type alias ColorData =
|
||||
{ name : String
|
||||
, display : String
|
||||
}
|
||||
|
||||
colors : List ColorData
|
||||
colors =
|
||||
[ { name = "default", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #007f00; font-weight: bold\">import</span> <span style=\"color: #0000ff; font-weight: bold\">sys</span>\necho <span style=\"color: #ff0000\">"Welcome $USER on"</span> <span style=\"color: #007f00; font-weight: bold\">@</span>(sys<span style=\"color: #555555\">.</span>platform)\n\n<span style=\"color: #007f00; font-weight: bold\">def</span> <span style=\"color: #0000ff\">func</span>(x<span style=\"color: #555555\">=42</span>):\n d <span style=\"color: #555555\">=</span> {<span style=\"color: #ff0000\">"xonsh"</span>: <span style=\"color: #007f00; font-weight: bold\">True</span>}\n <span style=\"color: #007f00; font-weight: bold\">return</span> d<span style=\"color: #555555\">.</span>get(<span style=\"color: #ff0000\">"xonsh"</span>) <span style=\"color: #7f007f; font-weight: bold\">and</span> you\n\n<span style=\"color: #007f7f; text-decoration: underline\"># This is a comment</span>\n<span style=\"color: #007f00; font-weight: bold\">!</span>[<span style=\"color: #007f00\">env</span> |<span style=\"color: #e5e5e5\"> </span><span style=\"color: #007f00\">uniq</span> |<span style=\"color: #e5e5e5\"> </span><span style=\"color: #007f00\">sort</span> |<span style=\"color: #e5e5e5\"> </span><span style=\"color: #007f00\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "abap", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #0000ff\">import</span> <span style=\"color: #000000\">sys</span>\n<span style=\"color: #000000\">echo</span> <span style=\"color: #55aa22\">"Welcome $USER on"</span> <span style=\"color: #0000ff\">@</span>(<span style=\"color: #000000\">sys</span>.<span style=\"color: #000000\">platform</span>)\n\n<span style=\"color: #0000ff\">def</span> <span style=\"color: #000000\">func</span>(<span style=\"color: #000000\">x</span>=<span style=\"color: #33aaff\">42</span>):\n <span style=\"color: #000000\">d</span> = {<span style=\"color: #55aa22\">"xonsh"</span>: <span style=\"color: #0000ff\">True</span>}\n <span style=\"color: #0000ff\">return</span> <span style=\"color: #000000\">d</span>.<span style=\"color: #000000\">get</span>(<span style=\"color: #55aa22\">"xonsh"</span>) <span style=\"color: #0000ff\">and</span> <span style=\"color: #000000\">you</span>\n\n<span style=\"color: #888888; font-style: italic\"># This is a comment</span>\n<span style=\"color: #0000ff\">!</span>[<span style=\"color: #000000\">env</span> | <span style=\"color: #000000\">uniq</span> | <span style=\"color: #000000\">sort</span> | <span style=\"color: #000000\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "algol", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"font-weight: bold; text-decoration: underline\">import</span> <span style=\"color: #666666; font-weight: bold; font-style: italic\">sys</span>\necho <span style=\"color: #666666; font-style: italic\">"Welcome $USER on"</span> <span style=\"font-weight: bold; text-decoration: underline\">@</span>(sys.platform)\n\n<span style=\"font-weight: bold; text-decoration: underline\">def</span> <span style=\"color: #666666; font-weight: bold; font-style: italic\">func</span>(x=42):\n d = {<span style=\"color: #666666; font-style: italic\">"xonsh"</span>: <span style=\"font-weight: bold; text-decoration: underline\">True</span>}\n <span style=\"font-weight: bold; text-decoration: underline\">return</span> d.get(<span style=\"color: #666666; font-style: italic\">"xonsh"</span>) <span style=\"font-weight: bold\">and</span> you\n\n<span style=\"color: #888888; font-style: italic\"># This is a comment</span>\n<span style=\"font-weight: bold; text-decoration: underline\">!</span>[<span style=\"font-weight: bold; font-style: italic\">env</span> | <span style=\"font-weight: bold; font-style: italic\">uniq</span> | <span style=\"font-weight: bold; font-style: italic\">sort</span> | <span style=\"font-weight: bold; font-style: italic\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "algol_nu", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"font-weight: bold\">import</span> <span style=\"color: #666666; font-weight: bold; font-style: italic\">sys</span>\necho <span style=\"color: #666666; font-style: italic\">"Welcome $USER on"</span> <span style=\"font-weight: bold\">@</span>(sys.platform)\n\n<span style=\"font-weight: bold\">def</span> <span style=\"color: #666666; font-weight: bold; font-style: italic\">func</span>(x=42):\n d = {<span style=\"color: #666666; font-style: italic\">"xonsh"</span>: <span style=\"font-weight: bold\">True</span>}\n <span style=\"font-weight: bold\">return</span> d.get(<span style=\"color: #666666; font-style: italic\">"xonsh"</span>) <span style=\"font-weight: bold\">and</span> you\n\n<span style=\"color: #888888; font-style: italic\"># This is a comment</span>\n<span style=\"font-weight: bold\">!</span>[<span style=\"font-weight: bold; font-style: italic\">env</span> | <span style=\"font-weight: bold; font-style: italic\">uniq</span> | <span style=\"font-weight: bold; font-style: italic\">sort</span> | <span style=\"font-weight: bold; font-style: italic\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "arduino", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #728E00\">import</span> <span style=\"color: #434f54\">sys</span>\n<span style=\"color: #434f54\">echo</span> <span style=\"color: #7F8C8D\">"Welcome $USER on"</span> <span style=\"color: #728E00\">@</span>(<span style=\"color: #434f54\">sys</span><span style=\"color: #728E00\">.</span><span style=\"color: #434f54\">platform</span>)\n\n<span style=\"color: #728E00\">def</span> <span style=\"color: #D35400\">func</span>(<span style=\"color: #434f54\">x</span><span style=\"color: #728E00\">=</span><span style=\"color: #8A7B52\">42</span>):\n <span style=\"color: #434f54\">d</span> <span style=\"color: #728E00\">=</span> {<span style=\"color: #7F8C8D\">"xonsh"</span>: <span style=\"color: #00979D\">True</span>}\n <span style=\"color: #728E00\">return</span> <span style=\"color: #434f54\">d</span><span style=\"color: #728E00\">.</span><span style=\"color: #434f54\">get</span>(<span style=\"color: #7F8C8D\">"xonsh"</span>) <span style=\"color: #728E00\">and</span> <span style=\"color: #434f54\">you</span>\n\n<span style=\"color: #95a5a6\"># This is a comment</span>\n<span style=\"color: #728E00\">!</span>[<span style=\"color: #728E00\">env</span> | <span style=\"color: #728E00\">uniq</span> | <span style=\"color: #728E00\">sort</span> | <span style=\"color: #728E00\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "autumn", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #0000aa\">import</span> <span style=\"color: #00aaaa; text-decoration: underline\">sys</span>\necho <span style=\"color: #aa5500\">"Welcome $USER on"</span> <span style=\"color: #0000aa\">@</span>(sys.platform)\n\n<span style=\"color: #0000aa\">def</span> <span style=\"color: #00aa00\">func</span>(x=<span style=\"color: #009999\">42</span>):\n d = {<span style=\"color: #aa5500\">"xonsh"</span>: <span style=\"color: #0000aa\">True</span>}\n <span style=\"color: #0000aa\">return</span> d.get(<span style=\"color: #aa5500\">"xonsh"</span>) <span style=\"color: #0000aa\">and</span> you\n\n<span style=\"color: #aaaaaa; font-style: italic\"># This is a comment</span>\n<span style=\"color: #0000aa\">!</span>[<span style=\"color: #00aaaa\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #00aaaa\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #00aaaa\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #00aaaa\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "borland", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #000080; font-weight: bold\">import</span> sys\necho <span style=\"color: #0000FF\">"Welcome $USER on"</span> <span style=\"color: #000080; font-weight: bold\">@</span>(sys.platform)\n\n<span style=\"color: #000080; font-weight: bold\">def</span> func(x=<span style=\"color: #0000FF\">42</span>):\n d = {<span style=\"color: #0000FF\">"xonsh"</span>: <span style=\"color: #000080; font-weight: bold\">True</span>}\n <span style=\"color: #000080; font-weight: bold\">return</span> d.get(<span style=\"color: #0000FF\">"xonsh"</span>) <span style=\"font-weight: bold\">and</span> you\n\n<span style=\"color: #008800; font-style: italic\"># This is a comment</span>\n<span style=\"color: #000080; font-weight: bold\">!</span>[env |<span style=\"color: #bbbbbb\"> </span>uniq |<span style=\"color: #bbbbbb\"> </span>sort |<span style=\"color: #bbbbbb\"> </span>grep PATH]\n</code></pre></div>" }
|
||||
, { name = "bw", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"font-weight: bold\">import</span> <span style=\"font-weight: bold\">sys</span>\necho <span style=\"font-style: italic\">"Welcome $USER on"</span> <span style=\"font-weight: bold\">@</span>(sys.platform)\n\n<span style=\"font-weight: bold\">def</span> func(x=42):\n d = {<span style=\"font-style: italic\">"xonsh"</span>: <span style=\"font-weight: bold\">True</span>}\n <span style=\"font-weight: bold\">return</span> d.get(<span style=\"font-style: italic\">"xonsh"</span>) <span style=\"font-weight: bold\">and</span> you\n\n<span style=\"font-style: italic\"># This is a comment</span>\n<span style=\"font-weight: bold\">!</span>[env | uniq | sort | grep PATH]\n</code></pre></div>" }
|
||||
, { name = "colorful", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #008800; font-weight: bold\">import</span> <span style=\"color: #0e84b5; font-weight: bold\">sys</span>\necho <span style=\"background-color: #fff0f0\">"Welcome $USER on"</span> <span style=\"color: #008800; font-weight: bold\">@</span>(sys<span style=\"color: #333333\">.</span>platform)\n\n<span style=\"color: #008800; font-weight: bold\">def</span> <span style=\"color: #0066BB; font-weight: bold\">func</span>(x<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">42</span>):\n d <span style=\"color: #333333\">=</span> {<span style=\"background-color: #fff0f0\">"xonsh"</span>: <span style=\"color: #008800; font-weight: bold\">True</span>}\n <span style=\"color: #008800; font-weight: bold\">return</span> d<span style=\"color: #333333\">.</span>get(<span style=\"background-color: #fff0f0\">"xonsh"</span>) <span style=\"color: #000000; font-weight: bold\">and</span> you\n\n<span style=\"color: #888888\"># This is a comment</span>\n<span style=\"color: #008800; font-weight: bold\">!</span>[<span style=\"color: #007020\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007020\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007020\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007020\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "emacs", display = "<div class=\"highlight\" style=\"background: #f8f8f8; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #070707; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #AA22FF; font-weight: bold\">import</span> <span style=\"color: #0000FF; font-weight: bold\">sys</span>\necho <span style=\"color: #BB4444\">"Welcome $USER on"</span> <span style=\"color: #AA22FF; font-weight: bold\">@</span>(sys<span style=\"color: #666666\">.</span>platform)\n\n<span style=\"color: #AA22FF; font-weight: bold\">def</span> <span style=\"color: #00A000\">func</span>(x<span style=\"color: #666666\">=42</span>):\n d <span style=\"color: #666666\">=</span> {<span style=\"color: #BB4444\">"xonsh"</span>: <span style=\"color: #AA22FF; font-weight: bold\">True</span>}\n <span style=\"color: #AA22FF; font-weight: bold\">return</span> d<span style=\"color: #666666\">.</span>get(<span style=\"color: #BB4444\">"xonsh"</span>) <span style=\"color: #AA22FF; font-weight: bold\">and</span> you\n\n<span style=\"color: #008800; font-style: italic\"># This is a comment</span>\n<span style=\"color: #AA22FF; font-weight: bold\">!</span>[<span style=\"color: #AA22FF\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #AA22FF\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #AA22FF\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #AA22FF\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "friendly", display = "<div class=\"highlight\" style=\"background: #f0f0f0; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #0f0f0f; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #007020; font-weight: bold\">import</span> <span style=\"color: #0e84b5; font-weight: bold\">sys</span>\necho <span style=\"color: #4070a0\">"Welcome $USER on"</span> <span style=\"color: #007020; font-weight: bold\">@</span>(sys<span style=\"color: #666666\">.</span>platform)\n\n<span style=\"color: #007020; font-weight: bold\">def</span> <span style=\"color: #06287e\">func</span>(x<span style=\"color: #666666\">=</span><span style=\"color: #40a070\">42</span>):\n d <span style=\"color: #666666\">=</span> {<span style=\"color: #4070a0\">"xonsh"</span>: <span style=\"color: #007020; font-weight: bold\">True</span>}\n <span style=\"color: #007020; font-weight: bold\">return</span> d<span style=\"color: #666666\">.</span>get(<span style=\"color: #4070a0\">"xonsh"</span>) <span style=\"color: #007020; font-weight: bold\">and</span> you\n\n<span style=\"color: #60a0b0; font-style: italic\"># This is a comment</span>\n<span style=\"color: #007020; font-weight: bold\">!</span>[<span style=\"color: #007020\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007020\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007020\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007020\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "fruity", display = "<div class=\"highlight\" style=\"background: #111111; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #ffffff; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #fb660a; font-weight: bold\">import</span> <span style=\"color: #ffffff\">sys</span>\n<span style=\"color: #ffffff\">echo</span> <span style=\"color: #0086d2\">"Welcome $USER on"</span> <span style=\"color: #fb660a; font-weight: bold\">@</span><span style=\"color: #ffffff\">(sys.platform)</span>\n\n<span style=\"color: #fb660a; font-weight: bold\">def</span> <span style=\"color: #ff0086; font-weight: bold\">func</span><span style=\"color: #ffffff\">(x=</span><span style=\"color: #0086f7; font-weight: bold\">42</span><span style=\"color: #ffffff\">):</span>\n <span style=\"color: #ffffff\">d</span> <span style=\"color: #ffffff\">=</span> <span style=\"color: #ffffff\">{</span><span style=\"color: #0086d2\">"xonsh"</span><span style=\"color: #ffffff\">:</span> <span style=\"color: #fb660a; font-weight: bold\">True</span><span style=\"color: #ffffff\">}</span>\n <span style=\"color: #fb660a; font-weight: bold\">return</span> <span style=\"color: #ffffff\">d.get(</span><span style=\"color: #0086d2\">"xonsh"</span><span style=\"color: #ffffff\">)</span> <span style=\"color: #ffffff\">and</span> <span style=\"color: #ffffff\">you</span>\n\n<span style=\"color: #008800; font-style: italic; background-color: #0f140f\"># This is a comment</span>\n<span style=\"color: #fb660a; font-weight: bold\">!</span><span style=\"color: #ffffff\">[env</span> <span style=\"color: #ffffff\">|</span><span style=\"color: #888888\"> </span><span style=\"color: #ffffff\">uniq</span> <span style=\"color: #ffffff\">|</span><span style=\"color: #888888\"> </span><span style=\"color: #ffffff\">sort</span> <span style=\"color: #ffffff\">|</span><span style=\"color: #888888\"> </span><span style=\"color: #ffffff\">grep</span> PATH<span style=\"color: #ffffff\">]</span>\n</code></pre></div>" }
|
||||
, { name = "igor", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #0000FF\">import</span> sys\necho <span style=\"color: #009C00\">"Welcome $USER on"</span> <span style=\"color: #0000FF\">@</span>(sys.platform)\n\n<span style=\"color: #0000FF\">def</span> <span style=\"color: #C34E00\">func</span>(x=42):\n d = {<span style=\"color: #009C00\">"xonsh"</span>: <span style=\"color: #0000FF\">True</span>}\n <span style=\"color: #0000FF\">return</span> d.get(<span style=\"color: #009C00\">"xonsh"</span>) and you\n\n<span style=\"color: #FF0000; font-style: italic\"># This is a comment</span>\n<span style=\"color: #0000FF\">!</span>[env | uniq | sort | grep PATH]\n</code></pre></div>" }
|
||||
, { name = "inkpot", display = "<div class=\"highlight\" style=\"background: #1e1e27; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #cfbfad; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #808bed\">import</span> <span style=\"color: #ff0000\">sys</span>\n<span style=\"color: #cfbfad\">echo</span> <span style=\"color: #ffcd8b; background-color: #404040\">"Welcome $USER on"</span> <span style=\"color: #808bed\">@</span><span style=\"color: #cfbfad\">(sys</span><span style=\"color: #666666\">.</span><span style=\"color: #cfbfad\">platform)</span>\n\n<span style=\"color: #808bed\">def</span> <span style=\"color: #c080d0\">func</span><span style=\"color: #cfbfad\">(x</span><span style=\"color: #666666\">=</span><span style=\"color: #f0ad6d\">42</span><span style=\"color: #cfbfad\">):</span>\n <span style=\"color: #cfbfad\">d</span> <span style=\"color: #666666\">=</span> <span style=\"color: #cfbfad\">{</span><span style=\"color: #ffcd8b; background-color: #404040\">"xonsh"</span><span style=\"color: #cfbfad\">:</span> <span style=\"color: #808bed\">True</span><span style=\"color: #cfbfad\">}</span>\n <span style=\"color: #808bed\">return</span> <span style=\"color: #cfbfad\">d</span><span style=\"color: #666666\">.</span><span style=\"color: #cfbfad\">get(</span><span style=\"color: #ffcd8b; background-color: #404040\">"xonsh"</span><span style=\"color: #cfbfad\">)</span> <span style=\"color: #666666\">and</span> <span style=\"color: #cfbfad\">you</span>\n\n<span style=\"color: #cd8b00\"># This is a comment</span>\n<span style=\"color: #808bed\">!</span><span style=\"color: #cfbfad\">[</span><span style=\"color: #808bed\">env</span> <span style=\"color: #cfbfad\">|</span><span style=\"color: #434357\"> </span><span style=\"color: #808bed\">uniq</span> <span style=\"color: #cfbfad\">|</span><span style=\"color: #434357\"> </span><span style=\"color: #808bed\">sort</span> <span style=\"color: #cfbfad\">|</span><span style=\"color: #434357\"> </span><span style=\"color: #808bed\">grep</span> PATH<span style=\"color: #cfbfad\">]</span>\n</code></pre></div>" }
|
||||
, { name = "lovelace", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #2838b0\">import</span> <span style=\"color: #289870\">sys</span>\necho <span style=\"color: #b83838\">"Welcome $USER on"</span> <span style=\"color: #2838b0\">@</span><span style=\"color: #888888\">(</span>sys<span style=\"color: #666666\">.</span>platform<span style=\"color: #888888\">)</span>\n\n<span style=\"color: #2838b0\">def</span> <span style=\"color: #785840\">func</span><span style=\"color: #888888\">(</span>x<span style=\"color: #666666\">=</span><span style=\"color: #444444\">42</span><span style=\"color: #888888\">):</span>\n d <span style=\"color: #666666\">=</span> <span style=\"color: #888888\">{</span><span style=\"color: #b83838\">"xonsh"</span><span style=\"color: #888888\">:</span> <span style=\"color: #444444; font-style: italic\">True</span><span style=\"color: #888888\">}</span>\n <span style=\"color: #2838b0\">return</span> d<span style=\"color: #666666\">.</span>get<span style=\"color: #888888\">(</span><span style=\"color: #b83838\">"xonsh"</span><span style=\"color: #888888\">)</span> <span style=\"color: #a848a8\">and</span> you\n\n<span style=\"color: #888888; font-style: italic\"># This is a comment</span>\n<span style=\"color: #2838b0\">!</span><span style=\"color: #888888\">[</span><span style=\"color: #388038\">env</span> <span style=\"color: #888888\">|</span><span style=\"color: #a89028\"> </span><span style=\"color: #388038\">uniq</span> <span style=\"color: #888888\">|</span><span style=\"color: #a89028\"> </span><span style=\"color: #388038\">sort</span> <span style=\"color: #888888\">|</span><span style=\"color: #a89028\"> </span><span style=\"color: #388038\">grep</span> PATH<span style=\"color: #888888\">]</span>\n</code></pre></div>" }
|
||||
, { name = "manni", display = "<div class=\"highlight\" style=\"background: #f0f3f3; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #0f0c0c; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #006699; font-weight: bold\">import</span> <span style=\"color: #00CCFF; font-weight: bold\">sys</span>\necho <span style=\"color: #CC3300\">"Welcome $USER on"</span> <span style=\"color: #006699; font-weight: bold\">@</span>(sys<span style=\"color: #555555\">.</span>platform)\n\n<span style=\"color: #006699; font-weight: bold\">def</span> <span style=\"color: #CC00FF\">func</span>(x<span style=\"color: #555555\">=</span><span style=\"color: #FF6600\">42</span>):\n d <span style=\"color: #555555\">=</span> {<span style=\"color: #CC3300\">"xonsh"</span>: <span style=\"color: #006699; font-weight: bold\">True</span>}\n <span style=\"color: #006699; font-weight: bold\">return</span> d<span style=\"color: #555555\">.</span>get(<span style=\"color: #CC3300\">"xonsh"</span>) <span style=\"color: #000000; font-weight: bold\">and</span> you\n\n<span style=\"color: #0099FF; font-style: italic\"># This is a comment</span>\n<span style=\"color: #006699; font-weight: bold\">!</span>[<span style=\"color: #336666\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #336666\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #336666\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #336666\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "monokai", display = "<div class=\"highlight\" style=\"background: #272822; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #f8f8f2; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #f92672\">import</span> <span style=\"color: #f8f8f2\">sys</span>\n<span style=\"color: #f8f8f2\">echo</span> <span style=\"color: #e6db74\">"Welcome $USER on"</span> <span style=\"color: #66d9ef\">@</span><span style=\"color: #f8f8f2\">(sys</span><span style=\"color: #f92672\">.</span><span style=\"color: #f8f8f2\">platform)</span>\n\n<span style=\"color: #66d9ef\">def</span> <span style=\"color: #a6e22e\">func</span><span style=\"color: #f8f8f2\">(x</span><span style=\"color: #f92672\">=</span><span style=\"color: #ae81ff\">42</span><span style=\"color: #f8f8f2\">):</span>\n <span style=\"color: #f8f8f2\">d</span> <span style=\"color: #f92672\">=</span> <span style=\"color: #f8f8f2\">{</span><span style=\"color: #e6db74\">"xonsh"</span><span style=\"color: #f8f8f2\">:</span> <span style=\"color: #66d9ef\">True</span><span style=\"color: #f8f8f2\">}</span>\n <span style=\"color: #66d9ef\">return</span> <span style=\"color: #f8f8f2\">d</span><span style=\"color: #f92672\">.</span><span style=\"color: #f8f8f2\">get(</span><span style=\"color: #e6db74\">"xonsh"</span><span style=\"color: #f8f8f2\">)</span> <span style=\"color: #f92672\">and</span> <span style=\"color: #f8f8f2\">you</span>\n\n<span style=\"color: #75715e\"># This is a comment</span>\n<span style=\"color: #66d9ef\">!</span><span style=\"color: #f8f8f2\">[env</span> <span style=\"color: #f8f8f2\">| uniq</span> <span style=\"color: #f8f8f2\">| sort</span> <span style=\"color: #f8f8f2\">| grep</span> PATH<span style=\"color: #f8f8f2\">]</span>\n</code></pre></div>" }
|
||||
, { name = "murphy", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #228899; font-weight: bold\">import</span> <span style=\"color: #0e84b5; font-weight: bold\">sys</span>\necho <span style=\"background-color: #e0e0ff\">"Welcome $USER on"</span> <span style=\"color: #228899; font-weight: bold\">@</span>(sys<span style=\"color: #333333\">.</span>platform)\n\n<span style=\"color: #228899; font-weight: bold\">def</span> <span style=\"color: #55eedd; font-weight: bold\">func</span>(x<span style=\"color: #333333\">=</span><span style=\"color: #6666ff; font-weight: bold\">42</span>):\n d <span style=\"color: #333333\">=</span> {<span style=\"background-color: #e0e0ff\">"xonsh"</span>: <span style=\"color: #228899; font-weight: bold\">True</span>}\n <span style=\"color: #228899; font-weight: bold\">return</span> d<span style=\"color: #333333\">.</span>get(<span style=\"background-color: #e0e0ff\">"xonsh"</span>) <span style=\"color: #000000; font-weight: bold\">and</span> you\n\n<span style=\"color: #666666; font-style: italic\"># This is a comment</span>\n<span style=\"color: #228899; font-weight: bold\">!</span>[<span style=\"color: #007722\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007722\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007722\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #007722\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "native", display = "<div class=\"highlight\" style=\"background: #202020; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #d0d0d0; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #6ab825; font-weight: bold\">import</span> <span style=\"color: #447fcf; text-decoration: underline\">sys</span>\n<span style=\"color: #d0d0d0\">echo</span> <span style=\"color: #ed9d13\">"Welcome $USER on"</span> <span style=\"color: #6ab825; font-weight: bold\">@</span><span style=\"color: #d0d0d0\">(sys.platform)</span>\n\n<span style=\"color: #6ab825; font-weight: bold\">def</span> <span style=\"color: #447fcf\">func</span><span style=\"color: #d0d0d0\">(x=</span><span style=\"color: #3677a9\">42</span><span style=\"color: #d0d0d0\">):</span>\n <span style=\"color: #d0d0d0\">d</span> <span style=\"color: #d0d0d0\">=</span> <span style=\"color: #d0d0d0\">{</span><span style=\"color: #ed9d13\">"xonsh"</span><span style=\"color: #d0d0d0\">:</span> <span style=\"color: #6ab825; font-weight: bold\">True</span><span style=\"color: #d0d0d0\">}</span>\n <span style=\"color: #6ab825; font-weight: bold\">return</span> <span style=\"color: #d0d0d0\">d.get(</span><span style=\"color: #ed9d13\">"xonsh"</span><span style=\"color: #d0d0d0\">)</span> <span style=\"color: #6ab825; font-weight: bold\">and</span> <span style=\"color: #d0d0d0\">you</span>\n\n<span style=\"color: #999999; font-style: italic\"># This is a comment</span>\n<span style=\"color: #6ab825; font-weight: bold\">!</span><span style=\"color: #d0d0d0\">[</span><span style=\"color: #24909d\">env</span> <span style=\"color: #d0d0d0\">|</span><span style=\"color: #666666\"> </span><span style=\"color: #24909d\">uniq</span> <span style=\"color: #d0d0d0\">|</span><span style=\"color: #666666\"> </span><span style=\"color: #24909d\">sort</span> <span style=\"color: #d0d0d0\">|</span><span style=\"color: #666666\"> </span><span style=\"color: #24909d\">grep</span> PATH<span style=\"color: #d0d0d0\">]</span>\n</code></pre></div>" }
|
||||
, { name = "paraiso-dark", display = "<div class=\"highlight\" style=\"background: #2f1e2e; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #e7e9db; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #5bc4bf\">import</span> <span style=\"color: #fec418\">sys</span>\n<span style=\"color: #e7e9db\">echo</span> <span style=\"color: #48b685\">"Welcome $USER on"</span> <span style=\"color: #815ba4\">@</span><span style=\"color: #e7e9db\">(sys</span><span style=\"color: #5bc4bf\">.</span><span style=\"color: #e7e9db\">platform)</span>\n\n<span style=\"color: #815ba4\">def</span> <span style=\"color: #06b6ef\">func</span><span style=\"color: #e7e9db\">(x</span><span style=\"color: #5bc4bf\">=</span><span style=\"color: #f99b15\">42</span><span style=\"color: #e7e9db\">):</span>\n <span style=\"color: #e7e9db\">d</span> <span style=\"color: #5bc4bf\">=</span> <span style=\"color: #e7e9db\">{</span><span style=\"color: #48b685\">"xonsh"</span><span style=\"color: #e7e9db\">:</span> <span style=\"color: #815ba4\">True</span><span style=\"color: #e7e9db\">}</span>\n <span style=\"color: #815ba4\">return</span> <span style=\"color: #e7e9db\">d</span><span style=\"color: #5bc4bf\">.</span><span style=\"color: #e7e9db\">get(</span><span style=\"color: #48b685\">"xonsh"</span><span style=\"color: #e7e9db\">)</span> <span style=\"color: #5bc4bf\">and</span> <span style=\"color: #e7e9db\">you</span>\n\n<span style=\"color: #776e71\"># This is a comment</span>\n<span style=\"color: #815ba4\">!</span><span style=\"color: #e7e9db\">[env</span> <span style=\"color: #e7e9db\">| uniq</span> <span style=\"color: #e7e9db\">| sort</span> <span style=\"color: #e7e9db\">| grep</span> PATH<span style=\"color: #e7e9db\">]</span>\n</code></pre></div>" }
|
||||
, { name = "paraiso-light", display = "<div class=\"highlight\" style=\"background: #e7e9db; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #2f1e2e; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #5bc4bf\">import</span> <span style=\"color: #fec418\">sys</span>\n<span style=\"color: #2f1e2e\">echo</span> <span style=\"color: #48b685\">"Welcome $USER on"</span> <span style=\"color: #815ba4\">@</span><span style=\"color: #2f1e2e\">(sys</span><span style=\"color: #5bc4bf\">.</span><span style=\"color: #2f1e2e\">platform)</span>\n\n<span style=\"color: #815ba4\">def</span> <span style=\"color: #06b6ef\">func</span><span style=\"color: #2f1e2e\">(x</span><span style=\"color: #5bc4bf\">=</span><span style=\"color: #f99b15\">42</span><span style=\"color: #2f1e2e\">):</span>\n <span style=\"color: #2f1e2e\">d</span> <span style=\"color: #5bc4bf\">=</span> <span style=\"color: #2f1e2e\">{</span><span style=\"color: #48b685\">"xonsh"</span><span style=\"color: #2f1e2e\">:</span> <span style=\"color: #815ba4\">True</span><span style=\"color: #2f1e2e\">}</span>\n <span style=\"color: #815ba4\">return</span> <span style=\"color: #2f1e2e\">d</span><span style=\"color: #5bc4bf\">.</span><span style=\"color: #2f1e2e\">get(</span><span style=\"color: #48b685\">"xonsh"</span><span style=\"color: #2f1e2e\">)</span> <span style=\"color: #5bc4bf\">and</span> <span style=\"color: #2f1e2e\">you</span>\n\n<span style=\"color: #8d8687\"># This is a comment</span>\n<span style=\"color: #815ba4\">!</span><span style=\"color: #2f1e2e\">[env</span> <span style=\"color: #2f1e2e\">| uniq</span> <span style=\"color: #2f1e2e\">| sort</span> <span style=\"color: #2f1e2e\">| grep</span> PATH<span style=\"color: #2f1e2e\">]</span>\n</code></pre></div>" }
|
||||
, { name = "pastie", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #008800; font-weight: bold\">import</span> <span style=\"color: #bb0066; font-weight: bold\">sys</span>\necho <span style=\"color: #dd2200; background-color: #fff0f0\">"Welcome $USER on"</span> <span style=\"color: #008800; font-weight: bold\">@</span>(sys.platform)\n\n<span style=\"color: #008800; font-weight: bold\">def</span> <span style=\"color: #0066bb; font-weight: bold\">func</span>(x=<span style=\"color: #0000DD; font-weight: bold\">42</span>):\n d = {<span style=\"color: #dd2200; background-color: #fff0f0\">"xonsh"</span>: <span style=\"color: #008800; font-weight: bold\">True</span>}\n <span style=\"color: #008800; font-weight: bold\">return</span> d.get(<span style=\"color: #dd2200; background-color: #fff0f0\">"xonsh"</span>) <span style=\"color: #008800\">and</span> you\n\n<span style=\"color: #888888\"># This is a comment</span>\n<span style=\"color: #008800; font-weight: bold\">!</span>[<span style=\"color: #003388\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #003388\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #003388\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #003388\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "perldoc", display = "<div class=\"highlight\" style=\"background: #eeeedd; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #111122; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #8B008B; font-weight: bold\">import</span> <span style=\"color: #008b45; text-decoration: underline\">sys</span>\necho <span style=\"color: #CD5555\">"Welcome $USER on"</span> <span style=\"color: #8B008B; font-weight: bold\">@</span>(sys.platform)\n\n<span style=\"color: #8B008B; font-weight: bold\">def</span> <span style=\"color: #008b45\">func</span>(x=<span style=\"color: #B452CD\">42</span>):\n d = {<span style=\"color: #CD5555\">"xonsh"</span>: <span style=\"color: #8B008B; font-weight: bold\">True</span>}\n <span style=\"color: #8B008B; font-weight: bold\">return</span> d.get(<span style=\"color: #CD5555\">"xonsh"</span>) <span style=\"color: #8B008B\">and</span> you\n\n<span style=\"color: #228B22\"># This is a comment</span>\n<span style=\"color: #8B008B; font-weight: bold\">!</span>[<span style=\"color: #658b00\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #658b00\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #658b00\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #658b00\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "rainbow_dash", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #4d4d4d; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #2c5dcd; font-weight: bold\">import</span> sys\necho <span style=\"color: #00cc66\">"Welcome $USER on"</span> <span style=\"color: #2c5dcd; font-weight: bold\">@</span>(sys<span style=\"color: #2c5dcd\">.</span>platform)\n\n<span style=\"color: #2c5dcd; font-weight: bold\">def</span> <span style=\"color: #ff8000; font-weight: bold\">func</span>(x<span style=\"color: #2c5dcd\">=</span><span style=\"color: #5918bb; font-weight: bold\">42</span>):\n d <span style=\"color: #2c5dcd\">=</span> {<span style=\"color: #00cc66\">"xonsh"</span>: <span style=\"color: #2c5dcd; font-weight: bold\">True</span>}\n <span style=\"color: #2c5dcd; font-weight: bold\">return</span> d<span style=\"color: #2c5dcd\">.</span>get(<span style=\"color: #00cc66\">"xonsh"</span>) <span style=\"color: #2c5dcd; font-weight: bold\">and</span> you\n\n<span style=\"color: #0080ff; font-style: italic\"># This is a comment</span>\n<span style=\"color: #2c5dcd; font-weight: bold\">!</span>[<span style=\"color: #5918bb; font-weight: bold\">env</span> |<span style=\"color: #cbcbcb\"> </span><span style=\"color: #5918bb; font-weight: bold\">uniq</span> |<span style=\"color: #cbcbcb\"> </span><span style=\"color: #5918bb; font-weight: bold\">sort</span> |<span style=\"color: #cbcbcb\"> </span><span style=\"color: #5918bb; font-weight: bold\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "rrt", display = "<div class=\"highlight\" style=\"background: #000000; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #ffffff; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #ff0000\">import</span> sys\necho <span style=\"color: #87ceeb\">"Welcome $USER on"</span> <span style=\"color: #ff0000\">@</span>(sys.platform)\n\n<span style=\"color: #ff0000\">def</span> <span style=\"color: #ffff00\">func</span>(x=42):\n d = {<span style=\"color: #87ceeb\">"xonsh"</span>: <span style=\"color: #ff0000\">True</span>}\n <span style=\"color: #ff0000\">return</span> d.get(<span style=\"color: #87ceeb\">"xonsh"</span>) and you\n\n<span style=\"color: #00ff00\"># This is a comment</span>\n<span style=\"color: #ff0000\">!</span>[env | uniq | sort | grep PATH]\n</code></pre></div>" }
|
||||
, { name = "sas", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #2c2cff\">import</span> sys\necho <span style=\"color: #800080\">"Welcome $USER on"</span> <span style=\"color: #2c2cff\">@</span>(sys.platform)\n\n<span style=\"color: #2c2cff\">def</span> <span style=\"font-weight: bold; font-style: italic\">func</span>(x=<span style=\"color: #2e8b57; font-weight: bold\">42</span>):\n d = {<span style=\"color: #800080\">"xonsh"</span>: <span style=\"color: #2c2cff; font-weight: bold\">True</span>}\n <span style=\"color: #2c2cff\">return</span> d.get(<span style=\"color: #800080\">"xonsh"</span>) and you\n\n<span style=\"color: #008800; font-style: italic\"># This is a comment</span>\n<span style=\"color: #2c2cff\">!</span>[<span style=\"color: #2c2cff\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #2c2cff\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #2c2cff\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #2c2cff\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "solarized-dark", display = "<div class=\"highlight\" style=\"background: #002b36; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #839496; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #cb4b16\">import</span> <span style=\"color: #268bd2\">sys</span>\n<span style=\"color: #839496\">echo</span> <span style=\"color: #2aa198\">"Welcome $USER on"</span> <span style=\"color: #859900\">@</span><span style=\"color: #839496\">(sys</span><span style=\"color: #586e75\">.</span><span style=\"color: #839496\">platform)</span>\n\n<span style=\"color: #859900\">def</span> <span style=\"color: #268bd2\">func</span><span style=\"color: #839496\">(x</span><span style=\"color: #586e75\">=</span><span style=\"color: #2aa198\">42</span><span style=\"color: #839496\">):</span>\n <span style=\"color: #839496\">d</span> <span style=\"color: #586e75\">=</span> <span style=\"color: #839496\">{</span><span style=\"color: #2aa198\">"xonsh"</span><span style=\"color: #839496\">:</span> <span style=\"color: #2aa198\">True</span><span style=\"color: #839496\">}</span>\n <span style=\"color: #859900\">return</span> <span style=\"color: #839496\">d</span><span style=\"color: #586e75\">.</span><span style=\"color: #839496\">get(</span><span style=\"color: #2aa198\">"xonsh"</span><span style=\"color: #839496\">)</span> <span style=\"color: #859900\">and</span> <span style=\"color: #839496\">you</span>\n\n<span style=\"color: #586e75; font-style: italic\"># This is a comment</span>\n<span style=\"color: #859900\">!</span><span style=\"color: #839496\">[</span><span style=\"color: #268bd2\">env</span> <span style=\"color: #839496\">| </span><span style=\"color: #268bd2\">uniq</span> <span style=\"color: #839496\">| </span><span style=\"color: #268bd2\">sort</span> <span style=\"color: #839496\">| </span><span style=\"color: #268bd2\">grep</span> PATH<span style=\"color: #839496\">]</span>\n</code></pre></div>" }
|
||||
, { name = "solarized-light", display = "<div class=\"highlight\" style=\"background: #fdf6e3; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #657b83; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #cb4b16\">import</span> <span style=\"color: #268bd2\">sys</span>\n<span style=\"color: #657b83\">echo</span> <span style=\"color: #2aa198\">"Welcome $USER on"</span> <span style=\"color: #859900\">@</span><span style=\"color: #657b83\">(sys</span><span style=\"color: #93a1a1\">.</span><span style=\"color: #657b83\">platform)</span>\n\n<span style=\"color: #859900\">def</span> <span style=\"color: #268bd2\">func</span><span style=\"color: #657b83\">(x</span><span style=\"color: #93a1a1\">=</span><span style=\"color: #2aa198\">42</span><span style=\"color: #657b83\">):</span>\n <span style=\"color: #657b83\">d</span> <span style=\"color: #93a1a1\">=</span> <span style=\"color: #657b83\">{</span><span style=\"color: #2aa198\">"xonsh"</span><span style=\"color: #657b83\">:</span> <span style=\"color: #2aa198\">True</span><span style=\"color: #657b83\">}</span>\n <span style=\"color: #859900\">return</span> <span style=\"color: #657b83\">d</span><span style=\"color: #93a1a1\">.</span><span style=\"color: #657b83\">get(</span><span style=\"color: #2aa198\">"xonsh"</span><span style=\"color: #657b83\">)</span> <span style=\"color: #859900\">and</span> <span style=\"color: #657b83\">you</span>\n\n<span style=\"color: #93a1a1; font-style: italic\"># This is a comment</span>\n<span style=\"color: #859900\">!</span><span style=\"color: #657b83\">[</span><span style=\"color: #268bd2\">env</span> <span style=\"color: #657b83\">| </span><span style=\"color: #268bd2\">uniq</span> <span style=\"color: #657b83\">| </span><span style=\"color: #268bd2\">sort</span> <span style=\"color: #657b83\">| </span><span style=\"color: #268bd2\">grep</span> PATH<span style=\"color: #657b83\">]</span>\n</code></pre></div>" }
|
||||
, { name = "stata", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #111111; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #353580; font-weight: bold\">import</span> sys\necho <span style=\"color: #7a2424\">"Welcome $USER on"</span> <span style=\"color: #353580; font-weight: bold\">@</span>(sys.platform)\n\n<span style=\"color: #353580; font-weight: bold\">def</span> <span style=\"color: #2c2cff\">func</span>(x=<span style=\"color: #2c2cff\">42</span>):\n d = {<span style=\"color: #7a2424\">"xonsh"</span>: <span style=\"color: #353580; font-weight: bold\">True</span>}\n <span style=\"color: #353580; font-weight: bold\">return</span> d.get(<span style=\"color: #7a2424\">"xonsh"</span>) and you\n\n<span style=\"color: #008800; font-style: italic\"># This is a comment</span>\n<span style=\"color: #353580; font-weight: bold\">!</span>[env |<span style=\"color: #bbbbbb\"> </span>uniq |<span style=\"color: #bbbbbb\"> </span>sort |<span style=\"color: #bbbbbb\"> </span>grep PATH]\n</code></pre></div>" }
|
||||
, { name = "stata-dark", display = "<div class=\"highlight\" style=\"background: #232629; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #cccccc; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #7686bb; font-weight: bold\">import</span> sys\necho <span style=\"color: #51cc99\">"Welcome $USER on"</span> <span style=\"color: #7686bb; font-weight: bold\">@</span>(sys.platform)\n\n<span style=\"color: #7686bb; font-weight: bold\">def</span> <span style=\"color: #6a6aff\">func</span>(x=<span style=\"color: #4FB8CC\">42</span>):\n d = {<span style=\"color: #51cc99\">"xonsh"</span>: <span style=\"color: #7686bb; font-weight: bold\">True</span>}\n <span style=\"color: #7686bb; font-weight: bold\">return</span> d.get(<span style=\"color: #51cc99\">"xonsh"</span>) and you\n\n<span style=\"color: #777777; font-style: italic\"># This is a comment</span>\n<span style=\"color: #7686bb; font-weight: bold\">!</span>[env |<span style=\"color: #bbbbbb\"> </span>uniq |<span style=\"color: #bbbbbb\"> </span>sort |<span style=\"color: #bbbbbb\"> </span>grep PATH]\n</code></pre></div>" }
|
||||
, { name = "stata-light", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #111111; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #353580; font-weight: bold\">import</span> sys\necho <span style=\"color: #7a2424\">"Welcome $USER on"</span> <span style=\"color: #353580; font-weight: bold\">@</span>(sys.platform)\n\n<span style=\"color: #353580; font-weight: bold\">def</span> <span style=\"color: #2c2cff\">func</span>(x=<span style=\"color: #2c2cff\">42</span>):\n d = {<span style=\"color: #7a2424\">"xonsh"</span>: <span style=\"color: #353580; font-weight: bold\">True</span>}\n <span style=\"color: #353580; font-weight: bold\">return</span> d.get(<span style=\"color: #7a2424\">"xonsh"</span>) and you\n\n<span style=\"color: #008800; font-style: italic\"># This is a comment</span>\n<span style=\"color: #353580; font-weight: bold\">!</span>[env |<span style=\"color: #bbbbbb\"> </span>uniq |<span style=\"color: #bbbbbb\"> </span>sort |<span style=\"color: #bbbbbb\"> </span>grep PATH]\n</code></pre></div>" }
|
||||
, { name = "tango", display = "<div class=\"highlight\" style=\"background: #f8f8f8; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #070707; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #204a87; font-weight: bold\">import</span> <span style=\"color: #000000\">sys</span>\n<span style=\"color: #000000\">echo</span> <span style=\"color: #4e9a06\">"Welcome $USER on"</span> <span style=\"color: #204a87; font-weight: bold\">@</span><span style=\"color: #000000; font-weight: bold\">(</span><span style=\"color: #000000\">sys</span><span style=\"color: #ce5c00; font-weight: bold\">.</span><span style=\"color: #000000\">platform</span><span style=\"color: #000000; font-weight: bold\">)</span>\n\n<span style=\"color: #204a87; font-weight: bold\">def</span> <span style=\"color: #000000\">func</span><span style=\"color: #000000; font-weight: bold\">(</span><span style=\"color: #000000\">x</span><span style=\"color: #ce5c00; font-weight: bold\">=</span><span style=\"color: #0000cf; font-weight: bold\">42</span><span style=\"color: #000000; font-weight: bold\">):</span>\n <span style=\"color: #000000\">d</span> <span style=\"color: #ce5c00; font-weight: bold\">=</span> <span style=\"color: #000000; font-weight: bold\">{</span><span style=\"color: #4e9a06\">"xonsh"</span><span style=\"color: #000000; font-weight: bold\">:</span> <span style=\"color: #204a87; font-weight: bold\">True</span><span style=\"color: #000000; font-weight: bold\">}</span>\n <span style=\"color: #204a87; font-weight: bold\">return</span> <span style=\"color: #000000\">d</span><span style=\"color: #ce5c00; font-weight: bold\">.</span><span style=\"color: #000000\">get</span><span style=\"color: #000000; font-weight: bold\">(</span><span style=\"color: #4e9a06\">"xonsh"</span><span style=\"color: #000000; font-weight: bold\">)</span> <span style=\"color: #204a87; font-weight: bold\">and</span> <span style=\"color: #000000\">you</span>\n\n<span style=\"color: #8f5902; font-style: italic\"># This is a comment</span>\n<span style=\"color: #204a87; font-weight: bold\">!</span><span style=\"color: #000000; font-weight: bold\">[</span><span style=\"color: #204a87\">env</span> <span style=\"color: #000000; font-weight: bold\">|</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #204a87\">uniq</span> <span style=\"color: #000000; font-weight: bold\">|</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #204a87\">sort</span> <span style=\"color: #000000; font-weight: bold\">|</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #204a87\">grep</span> PATH<span style=\"color: #000000; font-weight: bold\">]</span>\n</code></pre></div>" }
|
||||
, { name = "trac", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"font-weight: bold\">import</span> <span style=\"color: #555555\">sys</span>\necho <span style=\"color: #bb8844\">"Welcome $USER on"</span> <span style=\"font-weight: bold\">@</span>(sys<span style=\"font-weight: bold\">.</span>platform)\n\n<span style=\"font-weight: bold\">def</span> <span style=\"color: #990000; font-weight: bold\">func</span>(x<span style=\"font-weight: bold\">=</span><span style=\"color: #009999\">42</span>):\n d <span style=\"font-weight: bold\">=</span> {<span style=\"color: #bb8844\">"xonsh"</span>: <span style=\"font-weight: bold\">True</span>}\n <span style=\"font-weight: bold\">return</span> d<span style=\"font-weight: bold\">.</span>get(<span style=\"color: #bb8844\">"xonsh"</span>) <span style=\"font-weight: bold\">and</span> you\n\n<span style=\"color: #999988; font-style: italic\"># This is a comment</span>\n<span style=\"font-weight: bold\">!</span>[<span style=\"color: #999999\">env</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #999999\">uniq</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #999999\">sort</span> |<span style=\"color: #bbbbbb\"> </span><span style=\"color: #999999\">grep</span> PATH]\n</code></pre></div>" }
|
||||
, { name = "vim", display = "<div class=\"highlight\" style=\"background: #000000; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #cccccc; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #cd00cd\">import</span> <span style=\"color: #cccccc\">sys</span>\n<span style=\"color: #cccccc\">echo</span> <span style=\"color: #cd0000\">"Welcome $USER on"</span> <span style=\"color: #cdcd00\">@</span><span style=\"color: #cccccc\">(sys</span><span style=\"color: #3399cc\">.</span><span style=\"color: #cccccc\">platform)</span>\n\n<span style=\"color: #cdcd00\">def</span> <span style=\"color: #cccccc\">func(x</span><span style=\"color: #3399cc\">=</span><span style=\"color: #cd00cd\">42</span><span style=\"color: #cccccc\">):</span>\n <span style=\"color: #cccccc\">d</span> <span style=\"color: #3399cc\">=</span> <span style=\"color: #cccccc\">{</span><span style=\"color: #cd0000\">"xonsh"</span><span style=\"color: #cccccc\">:</span> <span style=\"color: #cdcd00\">True</span><span style=\"color: #cccccc\">}</span>\n <span style=\"color: #cdcd00\">return</span> <span style=\"color: #cccccc\">d</span><span style=\"color: #3399cc\">.</span><span style=\"color: #cccccc\">get(</span><span style=\"color: #cd0000\">"xonsh"</span><span style=\"color: #cccccc\">)</span> <span style=\"color: #cdcd00\">and</span> <span style=\"color: #cccccc\">you</span>\n\n<span style=\"color: #000080\"># This is a comment</span>\n<span style=\"color: #cdcd00\">!</span><span style=\"color: #cccccc\">[</span><span style=\"color: #cd00cd\">env</span> <span style=\"color: #cccccc\">| </span><span style=\"color: #cd00cd\">uniq</span> <span style=\"color: #cccccc\">| </span><span style=\"color: #cd00cd\">sort</span> <span style=\"color: #cccccc\">| </span><span style=\"color: #cd00cd\">grep</span> PATH<span style=\"color: #cccccc\">]</span>\n</code></pre></div>" }
|
||||
, { name = "vs", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #0000ff\">import</span> sys\necho <span style=\"color: #a31515\">"Welcome $USER on"</span> <span style=\"color: #0000ff\">@</span>(sys.platform)\n\n<span style=\"color: #0000ff\">def</span> func(x=42):\n d = {<span style=\"color: #a31515\">"xonsh"</span>: <span style=\"color: #0000ff\">True</span>}\n <span style=\"color: #0000ff\">return</span> d.get(<span style=\"color: #a31515\">"xonsh"</span>) <span style=\"color: #0000ff\">and</span> you\n\n<span style=\"color: #008000\"># This is a comment</span>\n<span style=\"color: #0000ff\">!</span>[env | uniq | sort | grep PATH]\n</code></pre></div>" }
|
||||
, { name = "xcode", display = "<div class=\"highlight\" style=\"background: #ffffff; border-style: solid; border-radius: 5px\"><pre style=\"margin: 0em; padding: 0.5em 0.1em; color: #000000; line-height: 125%; margin: 0;\"><span></span><code><span style=\"color: #A90D91\">import</span> <span style=\"color: #000000\">sys</span>\n<span style=\"color: #000000\">echo</span> <span style=\"color: #C41A16\">"Welcome $USER on"</span> <span style=\"color: #A90D91\">@</span>(<span style=\"color: #000000\">sys.platform</span>)\n\n<span style=\"color: #A90D91\">def</span> <span style=\"color: #000000\">func</span>(<span style=\"color: #000000\">x=</span><span style=\"color: #1C01CE\">42</span>):\n <span style=\"color: #000000\">d</span> <span style=\"color: #000000\">=</span> {<span style=\"color: #C41A16\">"xonsh"</span>: <span style=\"color: #A90D91\">True</span>}\n <span style=\"color: #A90D91\">return</span> <span style=\"color: #000000\">d.get</span>(<span style=\"color: #C41A16\">"xonsh"</span>) <span style=\"color: #000000\">and</span> <span style=\"color: #000000\">you</span>\n\n<span style=\"color: #177500\"># This is a comment</span>\n<span style=\"color: #A90D91\">!</span>[<span style=\"color: #A90D91\">env</span> | <span style=\"color: #A90D91\">uniq</span> | <span style=\"color: #A90D91\">sort</span> | <span style=\"color: #A90D91\">grep</span> PATH]\n</code></pre></div>" }
|
||||
]
|
||||
|
||||
type alias XontribData =
|
||||
{ name : String
|
||||
, url : String
|
||||
, license : String
|
||||
, description : String
|
||||
}
|
||||
|
||||
xontribs : List XontribData
|
||||
xontribs =
|
||||
[ { name = "abbrevs", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Adds <span class=\"docutils literal\">abbrevs</span> dictionary to hold user-defined command abbreviations. The dictionary is searched as you type and the matching words are replaced at the command line by the corresponding dictionary contents once you hit 'Space' or 'Return' key. For instance a frequently used command such as <span class=\"docutils literal\">git status</span> can be abbreviated to <span class=\"docutils literal\">gst</span> as follows:</p>\n<pre class=\"literal-block\">$ xontrib load abbrevs\n$ abbrevs['gst'] = 'git status'\n$ gst # Once you hit <space> or <return>, 'gst' gets expanded to 'git status'.</pre>" }
|
||||
, { name = "apt_tabcomplete", url = "https://github.com/DangerOnTheRanger/xonsh-apt-tabcomplete", license = "BSD 2-clause", description = "<p>Adds tabcomplete functionality to apt-get/apt-cache inside of xonsh.</p>" }
|
||||
, { name = "argcomplete", url = "https://github.com/anki-code/xontrib-argcomplete", license = "", description = "<p>Argcomplete support to tab completion of python and xonsh scripts in xonsh.</p>" }
|
||||
, { name = "autojump", url = "https://github.com/wshanks/xontrib-autojump", license = "", description = "<p>autojump support for xonsh</p>" }
|
||||
, { name = "autovox", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Manages automatic activation of virtual environments.</p>" }
|
||||
, { name = "autoxsh", url = "https://github.com/Granitas/xonsh-autoxsh", license = "GPLv3", description = "<p>Adds automatic execution of xonsh script files called <span class=\"docutils literal\">.autoxsh</span> when enterting a directory with <span class=\"docutils literal\">cd</span> function</p>" }
|
||||
, { name = "avox", url = "https://github.com/AstraLuma/xontrib-avox", license = "GPLv3", description = "<p>Automatic (de)activation of virtual environments as you cd around</p>" }
|
||||
, { name = "bashisms", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Enables additional Bash-like syntax while at the command prompt. For example, the <span class=\"docutils literal\">!!</span> syntax for running the previous command is now usable. Note that these features are implemented as precommand events and these additions do not affect the xonsh language when run as script. That said, you might find them useful if you have strong muscle memory.</p>\n<p><strong>Warning:</strong> This xontrib may modify user command line input to implement its behavior. To see the modifications as they are applied (in unified diffformat), please set <span class=\"docutils literal\">$XONSH_DEBUG</span> to <span class=\"docutils literal\">2</span> or higher.</p>\n<p>The xontrib also adds commands: <span class=\"docutils literal\">alias</span>, <span class=\"docutils literal\">export</span>, <span class=\"docutils literal\">unset</span>, <span class=\"docutils literal\">set</span>, <span class=\"docutils literal\">shopt</span>, <span class=\"docutils literal\">complete</span>.</p>" }
|
||||
, { name = "base16_shell", url = "https://github.com/ErickTucto/xontrib-base16-shell", license = "", description = "<p>Change base16 shell themes</p>" }
|
||||
, { name = "coreutils", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Additional core utilities that are implemented in xonsh. The current list includes:</p>\n<ul class=\"simple\">\n<li><p>cat</p></li>\n<li><p>echo</p></li>\n<li><p>pwd</p></li>\n<li><p>tee</p></li>\n<li><p>tty</p></li>\n<li><p>yes</p></li>\n</ul>\n<p>In many cases, these may have a lower performance overhead than the posix command line utility with the same name. This is because these tools avoid the need for a full subprocess call. Additionally, these tools are cross-platform.</p>" }
|
||||
, { name = "direnv", url = "https://github.com/74th/xonsh-direnv", license = "MIT", description = "<p>Supports direnv.</p>" }
|
||||
, { name = "hist_navigator", url = "https://github.com/jnoortheen/xontrib-hist-navigator", license = "", description = "<p>Move through directory history with nextd and prevd also with keybindings.</p>" }
|
||||
, { name = "distributed", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>The distributed parallel computing library hooks for xonsh. Importantly this provides a substitute 'dworker' command which enables distributed workers to have access to xonsh builtins.</p>\n<p>Furthermore, this xontrib adds a 'DSubmitter' context manager for executing a block remotely. Moreover, this also adds a convenience function 'dsubmit()' for creating DSubmitter and Executor instances at the same time. Thus users may submit distributed jobs with:</p>\n<pre class=\"literal-block\">with dsubmit('127.0.0.1:8786', rtn='x') as dsub:\n x = $(echo I am elsewhere)\n\nres = dsub.future.result()\nprint(res)</pre>\n<p>This is useful for long running or non-blocking jobs.</p>" }
|
||||
, { name = "docker_tabcomplete", url = "https://github.com/xsteadfastx/xonsh-docker-tabcomplete", license = "MIT", description = "<p>Adds tabcomplete functionality to docker inside of xonsh.</p>" }
|
||||
, { name = "free_cwd", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Windows only xontrib, to release the lock on the current directory whenever the prompt is shown. Enabling this will allow the other programs or Windows Explorer to delete or rename the current or parent directories. Internally, it is accomplished by temporarily resetting CWD to the root drive folder while waiting at the prompt. This only works with the prompt_toolkit backend and can cause cause issues if any extensions are enabled that hook the prompt and relies on <span class=\"docutils literal\">os.getcwd()</span></p>" }
|
||||
, { name = "fzf-widgets", url = "https://github.com/laloch/xontrib-fzf-widgets", license = "GPLv3", description = "<p>Adds some fzf widgets to your xonsh shell.</p>" }
|
||||
, { name = "histcpy", url = "https://github.com/con-f-use/xontrib-histcpy", license = "GPLv3", description = "<p>Useful aliases and shortcuts for extracting links and textfrom command output history and putting them into the clipboard.</p>" }
|
||||
, { name = "jedi", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Use Jedi as xonsh's python completer.</p>" }
|
||||
, { name = "kitty", url = "https://github.com/scopatz/xontrib-kitty", license = "BSD-3-Clause", description = "<p>Xonsh hooks for the Kitty terminal emulator.</p>" }
|
||||
, { name = "mpl", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Matplotlib hooks for xonsh, including the new 'mpl' alias that displays the current figure on the screen.</p>" }
|
||||
, { name = "output_search", url = "https://github.com/anki-code/xontrib-output-search", license = "", description = "<p>Get identifiers, names, paths, URLs and words from the previous command output and use them for the next command.</p>" }
|
||||
, { name = "onepath", url = "https://github.com/anki-code/xontrib-onepath", license = "", description = "<p>When you click to a file or folder in graphical OS they will be opened in associated app.The xontrib-onepath brings the same logic for the xonsh shell. Type the filename or pathwithout preceding command and an associated action will be executed. The actions are customizable.</p>" }
|
||||
, { name = "pdb", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Simple built-in debugger. Runs pdb on reception of SIGUSR1 signal.</p>" }
|
||||
, { name = "pipeliner", url = "https://github.com/anki-code/xontrib-pipeliner", license = "", description = "<p>Let your pipe lines flow thru the Python code in xonsh.</p>" }
|
||||
, { name = "powerline", url = "https://github.com/santagada/xontrib-powerline", license = "MIT", description = "<p>Powerline for Xonsh shell</p>" }
|
||||
, { name = "prompt_bar", url = "https://github.com/anki-code/xontrib-prompt-bar", license = "", description = "<p>An elegance bar style for prompt.</p>" }
|
||||
, { name = "powerline-binding", url = "https://github.com/dyuri/xontrib-powerline-binding", license = "MIT", description = "<p>Uses powerline to render the xonsh prompt</p>" }
|
||||
, { name = "prompt_ret_code", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Adds return code info to the prompt</p>" }
|
||||
, { name = "prompt_vi_mode", url = "https://github.com/t184256/xontrib-prompt-vi-mode", license = "MIT", description = "<p>vi-mode status formatter for xonsh prompt</p>" }
|
||||
, { name = "pyenv", url = "https://github.com/dyuri/xontrib-pyenv", license = "MIT", description = "<p>pyenv integration for xonsh.</p>" }
|
||||
, { name = "readable-traceback", url = "https://github.com/6syun9/xontrib-readable-traceback", license = "MIT", description = "<p>Make traceback easier to see for xonsh.</p>" }
|
||||
, { name = "schedule", url = "https://github.com/AstraLuma/xontrib-schedule", license = "MIT", description = "<p>Xonsh Task Scheduling</p>" }
|
||||
, { name = "scrapy_tabcomplete", url = "https://github.com/Granitas/xonsh-scrapy-tabcomplete", license = "GPLv3", description = "<p>Adds tabcomplete functionality to scrapy inside of xonsh.</p>" }
|
||||
, { name = "ssh_agent", url = "https://github.com/dyuri/xontrib-ssh-agent", license = "MIT", description = "<p>ssh-agent integration</p>" }
|
||||
, { name = "vox", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Python virtual environment manager for xonsh.</p>" }
|
||||
, { name = "vox_tabcomplete", url = "https://github.com/Granitosaurus/xonsh-vox-tabcomplete", license = "GPLv3", description = "<p>Adds tabcomplete functionality to vox inside of xonsh.</p>" }
|
||||
, { name = "whole_word_jumping", url = "http://xon.sh", license = "BSD 3-clause", description = "<p>Jumping across whole words (non-whitespace) with Ctrl+Left/Right. Alt+Left/Right remains unmodified to jump over smaller word segments. Shift+Delete removes the whole word.</p>" }
|
||||
, { name = "xo", url = "https://github.com/scopatz/xo", license = "WTFPL", description = "<p>Adds an 'xo' alias to run the exofrills text editor in the current Python interpreter session. This shaves off a bit of the startup time when running your favorite, minimal text editor.</p>" }
|
||||
, { name = "xpg", url = "https://github.com/fengttt/xsh/tree/master/py", license = "Apache", description = "<p>Run/plot/explain sql query for PostgreSQL.</p>" }
|
||||
, { name = "z", url = "https://github.com/AstraLuma/xontrib-z", license = "GPLv3", description = "<p>Tracks your most used directories, based on 'frecency'.</p>" }
|
||||
]
|
|
@ -1,32 +0,0 @@
|
|||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"elm-src"
|
||||
],
|
||||
"elm-version": "0.19.0",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.1",
|
||||
"elm/core": "1.0.2",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/json": "1.1.2",
|
||||
"elm/url": "1.0.0",
|
||||
"hecrj/html-parser": "2.3.4",
|
||||
"rundis/elm-bootstrap": "5.2.0"
|
||||
},
|
||||
"indirect": {
|
||||
"avh4/elm-color": "1.0.0",
|
||||
"elm/bytes": "1.0.7",
|
||||
"elm/file": "1.0.3",
|
||||
"elm/parser": "1.1.0",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2",
|
||||
"rtfeldman/elm-hex": "1.0.0"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
69
xonsh/webconfig/file_writes.py
Normal file
69
xonsh/webconfig/file_writes.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
"""functions to update rc files"""
|
||||
import os
|
||||
import typing as tp
|
||||
|
||||
RENDERERS: tp.List[tp.Callable] = []
|
||||
|
||||
|
||||
def renderer(f):
|
||||
"""Adds decorated function to renderers list."""
|
||||
RENDERERS.append(f)
|
||||
|
||||
|
||||
@renderer
|
||||
def prompt(config):
|
||||
prompt = config.get("prompt")
|
||||
if prompt:
|
||||
yield f"$PROMPT = {prompt!r}"
|
||||
|
||||
|
||||
@renderer
|
||||
def colors(config):
|
||||
style = config.get("color")
|
||||
if style:
|
||||
yield f"$XONSH_COLOR_STYLE = {style!r}"
|
||||
|
||||
|
||||
@renderer
|
||||
def xontribs(config):
|
||||
xtribs = config.get("xontribs")
|
||||
if xtribs:
|
||||
yield "xontrib load " + " ".join(xtribs)
|
||||
|
||||
|
||||
def config_to_xonsh(
|
||||
config, prefix="# XONSH WEBCONFIG START", suffix="# XONSH WEBCONFIG END"
|
||||
):
|
||||
"""Turns config dict into xonsh code (str)."""
|
||||
lines = [prefix]
|
||||
for func in RENDERERS:
|
||||
lines.extend(func(config))
|
||||
lines.append(suffix)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def insert_into_xonshrc(
|
||||
config,
|
||||
xonshrc="~/.xonshrc",
|
||||
prefix="# XONSH WEBCONFIG START",
|
||||
suffix="# XONSH WEBCONFIG END",
|
||||
):
|
||||
"""Places a config dict into the xonshrc."""
|
||||
# get current contents
|
||||
fname = os.path.expanduser(xonshrc)
|
||||
if os.path.isfile(fname):
|
||||
with open(fname) as f:
|
||||
s = f.read()
|
||||
before, _, s = s.partition(prefix)
|
||||
_, _, after = s.partition(suffix)
|
||||
else:
|
||||
before = after = ""
|
||||
dname = os.path.dirname(fname)
|
||||
if dname:
|
||||
os.makedirs(dname, exist_ok=True)
|
||||
# compute new values
|
||||
new = config_to_xonsh(config, prefix=prefix, suffix=suffix)
|
||||
# write out the file
|
||||
with open(fname, "w", encoding="utf-8") as f:
|
||||
f.write(before + new + after)
|
||||
return fname
|
|
@ -1,19 +1,32 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Xonsh Web Config</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="/js/bootstrap.min.css">
|
||||
<script src="/js/app.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Xonsh Web Config</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="/js/bootstrap.min.css">
|
||||
<!-- <script src="/js/app.js"></script>-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="elm"></div>
|
||||
<script>
|
||||
var app = Elm.Main.init({
|
||||
node: document.getElementById('elm')
|
||||
});
|
||||
</script>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<a class="navbar-brand" href="#">
|
||||
<img src="/js/xonsh_sticker.svg" width="30" height="30" class="d-inline-block align-top" alt="">
|
||||
Xonsh
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<!-- <div class="collapse navbar-collapse" id="navbarSupportedContent">-->
|
||||
<ul class="navbar-nav mx-auto">
|
||||
$navlinks
|
||||
</ul>
|
||||
<!-- </div>-->
|
||||
</nav>
|
||||
<div class="container-lg m-4">
|
||||
$body
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
1
xonsh/webconfig/js/app.min.js
vendored
1
xonsh/webconfig/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
3827
xonsh/webconfig/js/xonsh_sticker.svg
Normal file
3827
xonsh/webconfig/js/xonsh_sticker.svg
Normal file
File diff suppressed because it is too large
Load diff
After Width: | Height: | Size: 340 KiB |
|
@ -1,103 +1,129 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
import cgi
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import socketserver
|
||||
from http import server
|
||||
from pprint import pprint
|
||||
from argparse import ArgumentParser
|
||||
import string
|
||||
import sys
|
||||
import typing as tp
|
||||
from argparse import ArgumentParser
|
||||
from http import server, HTTPStatus
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
from urllib import parse
|
||||
|
||||
from xonsh.built_ins import XSH
|
||||
from xonsh.webconfig import tags as t
|
||||
from xonsh.webconfig.file_writes import insert_into_xonshrc
|
||||
from xonsh.webconfig.routes import Routes
|
||||
|
||||
RENDERERS: tp.List[tp.Callable] = []
|
||||
|
||||
|
||||
def renderer(f):
|
||||
"""Adds decorated function to renderers list."""
|
||||
RENDERERS.append(f)
|
||||
|
||||
|
||||
@renderer
|
||||
def prompt(config):
|
||||
return ["$PROMPT = {!r}".format(config["prompt"])]
|
||||
|
||||
|
||||
@renderer
|
||||
def colors(config):
|
||||
style = config["colors"]
|
||||
if style == "default":
|
||||
return []
|
||||
return [f"$XONSH_COLOR_STYLE = {style!r}"]
|
||||
|
||||
|
||||
@renderer
|
||||
def xontribs(config):
|
||||
xtribs = config["xontribs"]
|
||||
if not xtribs:
|
||||
return []
|
||||
return ["xontrib load " + " ".join(xtribs)]
|
||||
|
||||
|
||||
def config_to_xonsh(
|
||||
config, prefix="# XONSH WEBCONFIG START", suffix="# XONSH WEBCONFIG END"
|
||||
):
|
||||
"""Turns config dict into xonsh code (str)."""
|
||||
lines = [prefix]
|
||||
for func in RENDERERS:
|
||||
lines.extend(func(config))
|
||||
lines.append(suffix)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def insert_into_xonshrc(
|
||||
config,
|
||||
xonshrc="~/.xonshrc",
|
||||
prefix="# XONSH WEBCONFIG START",
|
||||
suffix="# XONSH WEBCONFIG END",
|
||||
):
|
||||
"""Places a config dict into the xonshrc."""
|
||||
# get current contents
|
||||
fname = os.path.expanduser(xonshrc)
|
||||
if os.path.isfile(fname):
|
||||
with open(fname) as f:
|
||||
s = f.read()
|
||||
before, _, s = s.partition(prefix)
|
||||
_, _, after = s.partition(suffix)
|
||||
else:
|
||||
before = after = ""
|
||||
dname = os.path.dirname(fname)
|
||||
if dname:
|
||||
os.makedirs(dname, exist_ok=True)
|
||||
# compute new values
|
||||
new = config_to_xonsh(config, prefix=prefix, suffix=suffix)
|
||||
# write out the file
|
||||
with open(fname, "w", encoding="utf-8") as f:
|
||||
f.write(before + new + after)
|
||||
return fname
|
||||
|
||||
|
||||
class XonshConfigHTTPRequestHandler(server.SimpleHTTPRequestHandler):
|
||||
def _set_headers(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/html")
|
||||
def _write_headers(self, *headers: "tuple[str, str]"):
|
||||
for name, val in headers:
|
||||
self.send_header(name, val)
|
||||
self.end_headers()
|
||||
|
||||
def _write_data(self, data: "bytes|dict|str"):
|
||||
if isinstance(data, bytes):
|
||||
content_type = "text/html"
|
||||
elif isinstance(data, dict):
|
||||
content_type = "application/json"
|
||||
data = json.dumps(data).encode()
|
||||
else:
|
||||
content_type = "text/html"
|
||||
data = str(data).encode()
|
||||
self._write_headers(
|
||||
("Content-type", content_type),
|
||||
("Content-Length", str(len(data))),
|
||||
)
|
||||
self.wfile.write(data)
|
||||
self.wfile.flush()
|
||||
|
||||
def _send(
|
||||
self,
|
||||
data: "bytes|dict|str|None" = None,
|
||||
status: "None|int" = None,
|
||||
redirect: "str|None" = None,
|
||||
):
|
||||
status = status or (HTTPStatus.FOUND if redirect else HTTPStatus.OK)
|
||||
self.send_response(status)
|
||||
if data:
|
||||
self._write_data(data)
|
||||
elif redirect:
|
||||
self._write_headers(
|
||||
("Location", redirect),
|
||||
)
|
||||
|
||||
def _read(self):
|
||||
content_len = int(self.headers.get("content-length", 0))
|
||||
return self.rfile.read(content_len)
|
||||
|
||||
def render_get(self, route):
|
||||
try:
|
||||
webconfig = Path(__file__).parent
|
||||
except Exception:
|
||||
# in case of thread missing __file__ definition
|
||||
webconfig = Path.cwd()
|
||||
path = webconfig / "index.html"
|
||||
tmpl = string.Template(path.read_text())
|
||||
navlinks = t.to_str(route.get_nav_links())
|
||||
msgs = t.to_str(route.get_err_msgs())
|
||||
body = t.to_str(route.get()) # type: ignore
|
||||
data = tmpl.substitute(navlinks=navlinks, body=msgs + body)
|
||||
return self._send(data)
|
||||
|
||||
def _get_route(self, method: str):
|
||||
url = parse.urlparse(self.path)
|
||||
route_cls = Routes.registry.get(url.path)
|
||||
if route_cls and hasattr(route_cls, method):
|
||||
params = parse.parse_qs(url.query)
|
||||
return route_cls(url=url, params=params, xsh=XSH)
|
||||
|
||||
def do_GET(self) -> None:
|
||||
route = self._get_route("get")
|
||||
if route is not None:
|
||||
return self.render_get(route)
|
||||
return super().do_GET()
|
||||
|
||||
def _read_form(self):
|
||||
ctype, pdict = cgi.parse_header(self.headers.get("content-type"))
|
||||
# if ctype == "multipart/form-data":
|
||||
# postvars = cgi.parse_multipart(self.rfile, pdict)
|
||||
if ctype == "application/x-www-form-urlencoded":
|
||||
return parse.parse_qs(self._read(), keep_blank_values=True)
|
||||
return {}
|
||||
|
||||
def do_POST(self):
|
||||
"""Reads post request body"""
|
||||
self._set_headers()
|
||||
content_len = int(self.headers.get("content-length", 0))
|
||||
post_body = self.rfile.read(content_len)
|
||||
route = self._get_route("post")
|
||||
if route is not None:
|
||||
# redirect after form submission
|
||||
data = cgi.FieldStorage(
|
||||
self.rfile,
|
||||
headers=self.headers,
|
||||
environ={"REQUEST_METHOD": "POST"},
|
||||
keep_blank_values=True,
|
||||
)
|
||||
new_route = route.post(data) or route
|
||||
return self._send(redirect=new_route.path)
|
||||
post_body = self._read()
|
||||
config = json.loads(post_body)
|
||||
print("Web Config Values:")
|
||||
pprint(config)
|
||||
fname = insert_into_xonshrc(config)
|
||||
print("Wrote out to " + fname)
|
||||
self.wfile.write(b"received post request:<br>" + post_body)
|
||||
self._send(b"received post request:<br>" + post_body)
|
||||
|
||||
|
||||
def make_parser():
|
||||
p = ArgumentParser("xonfig web")
|
||||
p.add_argument(
|
||||
"--no-browser",
|
||||
"-n",
|
||||
action="store_false",
|
||||
dest="browser",
|
||||
default=True,
|
||||
|
@ -106,27 +132,26 @@ def make_parser():
|
|||
return p
|
||||
|
||||
|
||||
def main(args=None):
|
||||
p = make_parser()
|
||||
ns = p.parse_args(args=args)
|
||||
def bind_server_to(
|
||||
port: int = 8421, handler_cls=XonshConfigHTTPRequestHandler, browser=False
|
||||
):
|
||||
cls = socketserver.TCPServer
|
||||
# cls = socketserver.ThreadingTCPServer # required ctrl+c twice ?
|
||||
|
||||
webconfig_dir = os.path.dirname(__file__)
|
||||
if webconfig_dir:
|
||||
os.chdir(webconfig_dir)
|
||||
cls.allow_reuse_address = True
|
||||
|
||||
port = 8421
|
||||
Handler = XonshConfigHTTPRequestHandler
|
||||
while port <= 9310:
|
||||
try:
|
||||
with socketserver.TCPServer(("", port), Handler) as httpd:
|
||||
url = f"http://localhost:{port}"
|
||||
print(f"Web config started at '{url}'. Hit Crtl+C to stop.")
|
||||
if ns.browser:
|
||||
import webbrowser
|
||||
cls.allow_reuse_address = True
|
||||
|
||||
webbrowser.open(url)
|
||||
httpd.serve_forever()
|
||||
break
|
||||
httpd = cls(("", port), handler_cls)
|
||||
url = f"http://localhost:{port}"
|
||||
print(f"Web config started at '{url}'. Hit Crtl+C to stop.")
|
||||
if browser:
|
||||
import webbrowser
|
||||
|
||||
webbrowser.open(url)
|
||||
return httpd
|
||||
except OSError:
|
||||
type, value = sys.exc_info()[:2]
|
||||
if "Address already in use" not in str(value):
|
||||
|
@ -136,5 +161,28 @@ def main(args=None):
|
|||
port += 1
|
||||
|
||||
|
||||
def serve(browser=False):
|
||||
httpd = bind_server_to(browser=browser)
|
||||
|
||||
with contextlib.suppress(KeyboardInterrupt):
|
||||
with httpd:
|
||||
httpd.serve_forever()
|
||||
|
||||
|
||||
def main(args=None):
|
||||
from xonsh.main import setup
|
||||
|
||||
setup()
|
||||
|
||||
p = make_parser()
|
||||
ns = p.parse_args(args=args)
|
||||
|
||||
webconfig_dir = os.path.dirname(__file__)
|
||||
if webconfig_dir:
|
||||
os.chdir(webconfig_dir)
|
||||
serve(ns.browser)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# watchexec -r -e py -- python -m xonsh.webconfig --no-browser
|
||||
main()
|
||||
|
|
432
xonsh/webconfig/routes.py
Normal file
432
xonsh/webconfig/routes.py
Normal file
|
@ -0,0 +1,432 @@
|
|||
import cgi
|
||||
import inspect
|
||||
import sys
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from xonsh.environ import Env
|
||||
from .file_writes import insert_into_xonshrc
|
||||
from ..built_ins import XonshSession
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Type
|
||||
|
||||
import logging
|
||||
|
||||
from . import xonsh_data, tags as t
|
||||
from urllib import parse
|
||||
|
||||
|
||||
class Routes:
|
||||
path: str
|
||||
registry: "dict[str, Type[Routes]]" = {}
|
||||
navbar = False
|
||||
nav_title: "str|None" = None
|
||||
err_msgs: "list" = []
|
||||
"""session storage for error messages"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
url: "parse.ParseResult",
|
||||
params: "dict[str, list[str]]",
|
||||
xsh: "XonshSession",
|
||||
):
|
||||
self.url = url
|
||||
self.params = params
|
||||
self.env: "Env" = xsh.env
|
||||
self.xsh = xsh
|
||||
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
cls.registry[cls.path] = cls
|
||||
|
||||
def err(self, msg: str):
|
||||
html = xonsh_data.rst_to_html(msg)
|
||||
tree = t.etree.fromstring(html)
|
||||
self.err_msgs.append(tree)
|
||||
|
||||
def get_nav_links(self):
|
||||
for page in self.registry.values():
|
||||
klass = []
|
||||
if page.path == self.url.path:
|
||||
klass.append("active")
|
||||
|
||||
title = page.nav_title() if callable(page.nav_title) else page.nav_title
|
||||
if title:
|
||||
yield t.nav_item(*klass)[
|
||||
t.nav_link(href=page.path)[title],
|
||||
]
|
||||
|
||||
def get_err_msgs(self):
|
||||
if not self.err_msgs:
|
||||
return
|
||||
for msg in self.err_msgs:
|
||||
yield t.alert("alert-danger")[msg]
|
||||
self.err_msgs.clear()
|
||||
|
||||
def get_sel_url(self, name):
|
||||
params = parse.urlencode({"selected": name})
|
||||
return self.path + "?" + params
|
||||
|
||||
@staticmethod
|
||||
def get_display(display):
|
||||
try:
|
||||
display = t.etree.fromstring(display)
|
||||
except Exception as ex:
|
||||
logging.error(f"Failed to parse color-display {ex!r}. {display!r}")
|
||||
display = t.pre()[display]
|
||||
return display
|
||||
|
||||
def update_rc(self, **kwargs):
|
||||
# todo: handle updates and deletion as well
|
||||
insert_into_xonshrc(kwargs)
|
||||
|
||||
|
||||
class ColorsPage(Routes):
|
||||
path = "/"
|
||||
nav_title = "Colors"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.colors = dict(xonsh_data.render_colors())
|
||||
self.var_name = "XONSH_COLOR_STYLE"
|
||||
|
||||
def to_card(self, name: str, display: str):
|
||||
return t.card()[
|
||||
t.card_body()[
|
||||
t.card_title()[
|
||||
t.a("stretched-link", href=self.get_sel_url(name))[name]
|
||||
],
|
||||
self.get_display(display),
|
||||
]
|
||||
]
|
||||
|
||||
def get_cols(self):
|
||||
for name, display in self.colors.items():
|
||||
yield t.col_sm()[
|
||||
self.to_card(name, display),
|
||||
]
|
||||
|
||||
def _get_selected_header(self):
|
||||
selected = self.params.get("selected")
|
||||
current = self.env.get(self.var_name)
|
||||
if selected and selected != current:
|
||||
name = selected[0]
|
||||
# update env-variable
|
||||
form = t.inline_form(method="post")[
|
||||
t.btn_primary("ml-2", "p-1", type="submit", name=self.var_name)[
|
||||
f"Update ${self.var_name}",
|
||||
],
|
||||
]
|
||||
return (f"Selected: {name}", form), name
|
||||
return (f"Current: {current}",), current
|
||||
|
||||
def get_selected(self):
|
||||
header, name = self._get_selected_header()
|
||||
name = name if name in self.colors else "default"
|
||||
display = self.colors[name]
|
||||
|
||||
card = t.card()[
|
||||
t.card_header()[header],
|
||||
t.card_body()[self.get_display(display)],
|
||||
]
|
||||
|
||||
return t.row()[
|
||||
t.col()[card],
|
||||
]
|
||||
|
||||
def get(self):
|
||||
# banner
|
||||
yield self.get_selected()
|
||||
|
||||
yield t.br()
|
||||
yield t.br()
|
||||
# rest
|
||||
cols = list(self.get_cols())
|
||||
yield t.row()[cols]
|
||||
|
||||
def post(self, _):
|
||||
selected = self.params.get("selected")
|
||||
if selected:
|
||||
self.env[self.var_name] = selected[0]
|
||||
self.update_rc(color=selected[0])
|
||||
|
||||
|
||||
class PromptsPage(Routes):
|
||||
path = "/prompts"
|
||||
nav_title = "Prompts"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
prompts = xonsh_data.render_prompts(self.env)
|
||||
self.current = next(prompts)
|
||||
self.prompts = dict(prompts)
|
||||
self.var_name = "PROMPT"
|
||||
# todo: support updating RIGHT_PROMPT, BOTTOM_TOOLBAR
|
||||
|
||||
def to_card(self, name: str, display: str):
|
||||
return t.card()[
|
||||
t.card_body()[
|
||||
t.card_title()[
|
||||
t.a("stretched-link", href=self.get_sel_url(name))[name]
|
||||
],
|
||||
self.get_display(display),
|
||||
]
|
||||
]
|
||||
|
||||
def _get_selected_header(self):
|
||||
ps_names = self.params.get("selected")
|
||||
if ps_names:
|
||||
name = ps_names[0]
|
||||
if name in self.prompts:
|
||||
return f"Selected: {name}", name
|
||||
return "Current: ", None
|
||||
|
||||
def get_selected(self):
|
||||
header, cur_sel = self._get_selected_header()
|
||||
if cur_sel is None:
|
||||
prompt = self.current["value"]
|
||||
display = self.current["display"]
|
||||
else:
|
||||
cont = self.prompts[cur_sel]
|
||||
prompt: str = cont["value"]
|
||||
display = cont["display"]
|
||||
# update env-variable
|
||||
txt_area = t.textarea(
|
||||
"form-control",
|
||||
name=self.var_name,
|
||||
rows=str(len(prompt.splitlines())),
|
||||
)[prompt]
|
||||
|
||||
card = t.card()[
|
||||
t.card_header()[header],
|
||||
t.card_body()[
|
||||
t.card_title()["Edit"],
|
||||
txt_area,
|
||||
t.br(),
|
||||
t.card_title()["Preview"],
|
||||
t.p("text-muted")[
|
||||
"It is not a live preview. `Set` to get the updated view."
|
||||
],
|
||||
self.get_display(display),
|
||||
],
|
||||
t.card_footer("py-1")[
|
||||
t.btn_primary("py-1", type="submit")[
|
||||
"Set",
|
||||
],
|
||||
],
|
||||
]
|
||||
return t.row()[
|
||||
t.col()[t.form(method="post")[card]],
|
||||
]
|
||||
|
||||
def get_cols(self):
|
||||
for name, prompt in self.prompts.items():
|
||||
yield t.row()[
|
||||
t.col()[
|
||||
self.to_card(name, prompt["display"]),
|
||||
]
|
||||
]
|
||||
|
||||
def get(self):
|
||||
# banner
|
||||
yield self.get_selected()
|
||||
|
||||
yield t.br()
|
||||
yield t.br()
|
||||
# rest
|
||||
yield from self.get_cols()
|
||||
|
||||
def post(self, data: "cgi.FieldStorage"):
|
||||
if data:
|
||||
prompt = data.getvalue(self.var_name)
|
||||
self.env[self.var_name] = prompt
|
||||
self.update_rc(prompt=prompt)
|
||||
|
||||
|
||||
class XontribsPage(Routes):
|
||||
path = "/xontribs"
|
||||
nav_title = "Xontribs"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.xontribs = dict(xonsh_data.render_xontribs())
|
||||
|
||||
@staticmethod
|
||||
def mod_name(name):
|
||||
return f"xontrib.{name}"
|
||||
|
||||
@staticmethod
|
||||
def is_loaded(name):
|
||||
return XontribsPage.mod_name(name) in sys.modules
|
||||
|
||||
def xontrib_card(self, name, data):
|
||||
from xonsh.xontribs import find_xontrib
|
||||
|
||||
title = t.a(href=data["url"])[name]
|
||||
if find_xontrib(name):
|
||||
act_label = "Add"
|
||||
if self.is_loaded(name):
|
||||
act_label = "Remove"
|
||||
action = t.inline_form(method="post")[
|
||||
t.btn_primary("ml-2", "p-1", type="submit", name=name)[
|
||||
act_label,
|
||||
],
|
||||
]
|
||||
else:
|
||||
title = title("stretched-link") # add class
|
||||
action = ""
|
||||
return t.card()[
|
||||
t.card_header()[title, action],
|
||||
t.card_body()[
|
||||
self.get_display(data["display"]),
|
||||
],
|
||||
]
|
||||
|
||||
def get(self):
|
||||
for name, data in self.xontribs.items():
|
||||
yield t.row()[
|
||||
t.col()[
|
||||
self.xontrib_card(name, data),
|
||||
]
|
||||
]
|
||||
yield t.br()
|
||||
|
||||
def post(self, data: "cgi.FieldStorage"):
|
||||
if not data.keys():
|
||||
return
|
||||
name = data.keys()[0]
|
||||
if self.is_loaded(name):
|
||||
# todo: update rc file
|
||||
del sys.modules[self.mod_name(name)]
|
||||
else:
|
||||
from xonsh.xontribs import xontribs_load
|
||||
|
||||
_, err, _ = xontribs_load([name])
|
||||
if err:
|
||||
self.err(err)
|
||||
else:
|
||||
self.update_rc(xontribs=[name])
|
||||
|
||||
|
||||
class EnvVariablesPage(Routes):
|
||||
path = "/vars"
|
||||
nav_title = "Variables"
|
||||
|
||||
def get_header(self):
|
||||
yield t.tr()[
|
||||
t.th("text-right")["Name"],
|
||||
t.th()["Value"],
|
||||
]
|
||||
|
||||
def get_rows(self):
|
||||
for name in sorted(self.env.keys()):
|
||||
if not self.env.is_configurable(name):
|
||||
continue
|
||||
value = self.env[name]
|
||||
envvar = self.env.get_docs(name)
|
||||
html = xonsh_data.rst_to_html(envvar.doc)
|
||||
yield t.tr()[
|
||||
t.td("text-right")[str(name)],
|
||||
t.td()[
|
||||
t.p()[repr(value)],
|
||||
t.small()[self.get_display(html)],
|
||||
],
|
||||
]
|
||||
|
||||
def get_table(self):
|
||||
rows = list(self.get_rows())
|
||||
yield t.tbl("table-striped")[
|
||||
self.get_header(),
|
||||
rows,
|
||||
]
|
||||
|
||||
def get(self):
|
||||
yield t.div("table-responsive")[self.get_table()]
|
||||
|
||||
|
||||
class AliasesPage(Routes):
|
||||
path = "/alias"
|
||||
nav_title = "Aliases"
|
||||
|
||||
def get_header(self):
|
||||
yield t.tr()[
|
||||
t.th("text-right")["Name"],
|
||||
t.th()["Value"],
|
||||
]
|
||||
|
||||
def get_rows(self):
|
||||
if not self.xsh.aliases:
|
||||
return
|
||||
for name in sorted(self.xsh.aliases.keys()):
|
||||
alias = self.xsh.aliases[name]
|
||||
if callable(alias):
|
||||
continue
|
||||
# todo:
|
||||
# 1. do not edit default aliases as well
|
||||
# 2. way to update string aliases
|
||||
|
||||
yield t.tr()[
|
||||
t.td("text-right")[str(name)],
|
||||
t.td()[
|
||||
t.p()[repr(alias)],
|
||||
],
|
||||
]
|
||||
|
||||
def get_table(self):
|
||||
rows = list(self.get_rows())
|
||||
yield t.tbl("table-sm", "table-striped")[
|
||||
self.get_header(),
|
||||
rows,
|
||||
]
|
||||
|
||||
def get(self):
|
||||
yield t.div("table-responsive")[self.get_table()]
|
||||
|
||||
|
||||
class AbbrevsPage(Routes):
|
||||
path = "/abbrevs"
|
||||
mod_name = XontribsPage.mod_name("abbrevs")
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
# lazy import as to not load by accident
|
||||
from xontrib.abbrevs import abbrevs # type: ignore
|
||||
|
||||
self.abbrevs: "dict[str, str]" = abbrevs
|
||||
|
||||
@classmethod
|
||||
def nav_title(cls):
|
||||
if cls.mod_name in sys.modules:
|
||||
return "Abbrevs"
|
||||
|
||||
def get_header(self):
|
||||
yield t.tr()[
|
||||
t.th("text-right")["Name"],
|
||||
t.th()["Value"],
|
||||
]
|
||||
|
||||
def get_rows(self):
|
||||
for name in sorted(self.abbrevs.keys()):
|
||||
alias = self.abbrevs[name]
|
||||
if callable(alias):
|
||||
display = inspect.getsource(alias)
|
||||
else:
|
||||
display = str(alias)
|
||||
# todo:
|
||||
# 2. way to update
|
||||
|
||||
yield t.tr()[
|
||||
t.td("text-right")[str(name)],
|
||||
t.td()[
|
||||
t.p()[repr(display)],
|
||||
],
|
||||
]
|
||||
|
||||
def get_table(self):
|
||||
rows = list(self.get_rows())
|
||||
yield t.tbl("table-sm", "table-striped")[
|
||||
self.get_header(),
|
||||
rows,
|
||||
]
|
||||
|
||||
def get(self):
|
||||
yield t.div("table-responsive")[self.get_table()]
|
141
xonsh/webconfig/tags.py
Normal file
141
xonsh/webconfig/tags.py
Normal file
|
@ -0,0 +1,141 @@
|
|||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Iterable
|
||||
import xml.etree.ElementTree as etree
|
||||
from functools import partial
|
||||
|
||||
|
||||
class Elem(etree.Element):
|
||||
def __init__(
|
||||
self,
|
||||
tag: "str",
|
||||
*cls: str,
|
||||
**kwargs: "str",
|
||||
):
|
||||
super().__init__(tag)
|
||||
self.set_attrib(*cls, **kwargs)
|
||||
|
||||
def __getitem__(self, item: "int|str|Elem|Iterable[Elem]"): # type: ignore
|
||||
"""nice sub-tree"""
|
||||
if isinstance(item, int):
|
||||
return super().__getitem__(item)
|
||||
if isinstance(item, str):
|
||||
self.text = (self.text or "") + item
|
||||
elif isinstance(item, etree.Element):
|
||||
self.append(item)
|
||||
else:
|
||||
for ele in item:
|
||||
try:
|
||||
_ = self[ele] # recursive call
|
||||
except Exception as ex:
|
||||
logging.error(
|
||||
f"Failed to append to node list. {ex!r} : {item!r}>{ele!r} : {self.to_str()!r}"
|
||||
)
|
||||
break
|
||||
return self
|
||||
|
||||
def set_attrib(self, *cls: str, **kwargs: str):
|
||||
klass = " ".join(cls)
|
||||
classes = [klass, self.attrib.pop("class", "")]
|
||||
cls_str = " ".join(filter(None, classes))
|
||||
if cls_str:
|
||||
self.attrib["class"] = cls_str
|
||||
self.attrib.update(kwargs)
|
||||
|
||||
def __call__(self, *cls: str, **kwargs: str):
|
||||
self.set_attrib(*cls, **kwargs)
|
||||
return self
|
||||
|
||||
def to_str(self) -> bytes:
|
||||
return etree.tostring(self)
|
||||
|
||||
|
||||
div = partial(Elem, "div")
|
||||
row = partial(div, "row")
|
||||
col = partial(div, "col")
|
||||
col_sm = partial(div, "col-sm")
|
||||
col_md = partial(div, "col-md")
|
||||
|
||||
alert = partial(div, "alert", role="alert")
|
||||
|
||||
br = partial(Elem, "br")
|
||||
|
||||
h3 = partial(Elem, "h3")
|
||||
h4 = partial(Elem, "h4")
|
||||
h5 = partial(Elem, "h5")
|
||||
card_title = partial(h5, "card-title")
|
||||
|
||||
li = partial(Elem, "li")
|
||||
nav_item = partial(li, "nav-item")
|
||||
|
||||
p = partial(Elem, "p")
|
||||
small = partial(Elem, "small")
|
||||
pre = partial(Elem, "pre")
|
||||
code = partial(Elem, "code")
|
||||
|
||||
a = partial(Elem, "a")
|
||||
nav_link = partial(a, "nav-link")
|
||||
|
||||
form = partial(Elem, "form")
|
||||
inline_form = partial(form, "d-inline")
|
||||
|
||||
card = partial(div, "card")
|
||||
card_header = partial(div, "card-header")
|
||||
card_body = partial(div, "card-body")
|
||||
card_text = partial(div, "card-text")
|
||||
card_footer = partial(div, "card-footer")
|
||||
|
||||
textarea = partial(Elem, "textarea")
|
||||
|
||||
table = partial(Elem, "table")
|
||||
tbl = partial(table, "table") # bootstrap table
|
||||
tr = partial(Elem, "tr")
|
||||
th = partial(Elem, "th")
|
||||
td = partial(Elem, "td")
|
||||
|
||||
btn = partial(Elem, "button", "btn", type="button")
|
||||
btn_primary = partial(btn, "btn-primary")
|
||||
btn_primary_sm = partial(btn_primary, "btn-sm")
|
||||
|
||||
|
||||
def to_pretty(txt: str):
|
||||
import xml.dom.minidom
|
||||
|
||||
dom = xml.dom.minidom.parseString(txt)
|
||||
txt = dom.toprettyxml()
|
||||
return "".join(txt.splitlines(keepends=True)[1:])
|
||||
|
||||
|
||||
def to_str(elems: "Iterable[Elem]|Elem", debug=False) -> str:
|
||||
def _to_str():
|
||||
if isinstance(elems, etree.Element):
|
||||
yield etree.tostring(elems)
|
||||
else:
|
||||
for idx, el in enumerate(elems):
|
||||
try:
|
||||
yield etree.tostring(el)
|
||||
except Exception:
|
||||
logging.error(
|
||||
f"Failed to serialize {el!r}. ({elems!r}.{idx!r})",
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
txt = b"".join(_to_str()).decode()
|
||||
if debug:
|
||||
txt = to_pretty(txt)
|
||||
return txt
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
nav = nav_item()[
|
||||
nav_link(href="/")["Colors"],
|
||||
]
|
||||
gen = to_str(nav, debug=True)
|
||||
print(gen)
|
||||
assert gen.splitlines() == [
|
||||
'<li class="nav-item">',
|
||||
'\t<a class="nav-link" href="/">Colors</a>',
|
||||
"</li>",
|
||||
]
|
215
xonsh/webconfig/xonsh_data.py
Normal file
215
xonsh/webconfig/xonsh_data.py
Normal file
|
@ -0,0 +1,215 @@
|
|||
"""script for compiling elm source and dumping it to the js folder."""
|
||||
import functools
|
||||
import io
|
||||
import logging
|
||||
|
||||
import pygments
|
||||
|
||||
from xonsh.color_tools import rgb_to_ints
|
||||
from xonsh.prompt.base import PromptFormatter, default_prompt
|
||||
from xonsh.pyghooks import (
|
||||
XonshStyle,
|
||||
xonsh_style_proxy,
|
||||
XonshHtmlFormatter,
|
||||
Token,
|
||||
XonshLexer,
|
||||
)
|
||||
from xonsh.pygments_cache import get_all_styles
|
||||
from xonsh.style_tools import partial_color_tokenize
|
||||
from xonsh.xontribs_meta import get_xontribs, Xontrib
|
||||
|
||||
|
||||
# $RAISE_SUBPROC_ERROR = True
|
||||
# $XONSH_SHOW_TRACEBACK = False
|
||||
|
||||
#
|
||||
# helper funcs
|
||||
#
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=4)
|
||||
def get_rst_formatter(**kwargs):
|
||||
from pygments.formatters.html import HtmlFormatter
|
||||
from pygments.lexers.markup import RstLexer
|
||||
|
||||
return RstLexer(), HtmlFormatter(**kwargs)
|
||||
|
||||
|
||||
def escape(s):
|
||||
return s.replace(r"\n", "<br/>")
|
||||
|
||||
|
||||
def invert_color(orig):
|
||||
r, g, b = rgb_to_ints(orig)
|
||||
inverted = [255 - r, 255 - g, 255 - b]
|
||||
new = [hex(n)[2:] for n in inverted]
|
||||
new = [n if len(n) == 2 else "0" + n for n in new]
|
||||
return "".join(new)
|
||||
|
||||
|
||||
def html_format(s, style="default"):
|
||||
buf = io.StringIO()
|
||||
proxy_style = xonsh_style_proxy(XonshStyle(style))
|
||||
# make sure we have a foreground color
|
||||
fgcolor = proxy_style._styles[Token.Text][0]
|
||||
if not fgcolor:
|
||||
fgcolor = invert_color(proxy_style.background_color[1:].strip("#"))
|
||||
# need to generate stream before creating formatter so that all tokens actually exist
|
||||
if isinstance(s, str):
|
||||
token_stream = partial_color_tokenize(s)
|
||||
else:
|
||||
token_stream = s
|
||||
formatter = XonshHtmlFormatter(
|
||||
wrapcode=True,
|
||||
noclasses=True,
|
||||
style=proxy_style,
|
||||
prestyles="margin: 0em; padding: 0.5em 0.1em; color: #" + fgcolor,
|
||||
cssstyles="border-style: solid; border-radius: 5px",
|
||||
)
|
||||
formatter.format(token_stream, buf)
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
def rst_to_html(text):
|
||||
try:
|
||||
from pygments import highlight
|
||||
|
||||
lexer, formatter = get_rst_formatter(
|
||||
noclasses=True,
|
||||
cssstyles="background: transparent",
|
||||
style="monokai", # a dark bg style
|
||||
)
|
||||
return highlight(text, lexer, formatter)
|
||||
except ImportError:
|
||||
return text
|
||||
|
||||
|
||||
# render prompts
|
||||
def get_named_prompts():
|
||||
return [
|
||||
(
|
||||
"default",
|
||||
default_prompt(),
|
||||
),
|
||||
("debian chroot", "{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{RESET}> "),
|
||||
("minimalist", "{BOLD_GREEN}{cwd_base}{RESET} ) "),
|
||||
(
|
||||
"terlar",
|
||||
"{env_name}{BOLD_GREEN}{user}{RESET}@{hostname}:"
|
||||
"{BOLD_GREEN}{cwd}{RESET}|{gitstatus}\\n{BOLD_INTENSE_RED}➤{RESET} ",
|
||||
),
|
||||
(
|
||||
"default with git status",
|
||||
"{env_name}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}"
|
||||
"{branch_color}{gitstatus: {}}{RESET} {BOLD_BLUE}"
|
||||
"{prompt_end}{RESET} ",
|
||||
),
|
||||
("robbyrussell", "{BOLD_INTENSE_RED}➜ {CYAN}{cwd_base} {gitstatus}{RESET} "),
|
||||
("just a dollar", "$ "),
|
||||
(
|
||||
"simple pythonista",
|
||||
"{INTENSE_RED}{user}{RESET} at {INTENSE_PURPLE}{hostname}{RESET} "
|
||||
"in {BOLD_GREEN}{cwd}{RESET}\\n↪ ",
|
||||
),
|
||||
(
|
||||
"informative",
|
||||
"[{localtime}] {YELLOW}{env_name} {BOLD_BLUE}{user}@{hostname} "
|
||||
"{BOLD_GREEN}{cwd} {gitstatus}{RESET}\\n> ",
|
||||
),
|
||||
(
|
||||
"informative Version Control",
|
||||
"{YELLOW}{env_name} " "{BOLD_GREEN}{cwd} {gitstatus}{RESET} {prompt_end} ",
|
||||
),
|
||||
("classic", "{user}@{hostname} {BOLD_GREEN}{cwd}{RESET}> "),
|
||||
(
|
||||
"classic with git status",
|
||||
"{gitstatus} {RESET}{user}@{hostname} {BOLD_GREEN}{cwd}{RESET}> ",
|
||||
),
|
||||
("screen savvy", "{YELLOW}{user}@{PURPLE}{hostname}{BOLD_GREEN}{cwd}{RESET}> "),
|
||||
(
|
||||
"sorin",
|
||||
"{CYAN}{cwd} {INTENSE_RED}❯{INTENSE_YELLOW}❯{INTENSE_GREEN}❯{RESET} ",
|
||||
),
|
||||
(
|
||||
"acidhub",
|
||||
"❰{INTENSE_GREEN}{user}{RESET}❙{YELLOW}{cwd}{RESET}{env_name}❱{gitstatus}≻ ",
|
||||
),
|
||||
(
|
||||
"nim",
|
||||
"{INTENSE_GREEN}┬─[{YELLOW}{user}{RESET}@{BLUE}{hostname}{RESET}:{cwd}"
|
||||
"{INTENSE_GREEN}]─[{localtime}]─[{RESET}G:{INTENSE_GREEN}{curr_branch}=]"
|
||||
"\\n{INTENSE_GREEN}╰─>{INTENSE_RED}{prompt_end}{RESET} ",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def get_initial(env, prompt_format, fields):
|
||||
template = env.get_stringified("PROMPT")
|
||||
return {
|
||||
"value": template,
|
||||
"display": escape(html_format(prompt_format(template, fields=fields))),
|
||||
}
|
||||
|
||||
|
||||
def render_prompts(env):
|
||||
prompt_format = PromptFormatter()
|
||||
fields = dict(env.get("PROMPT_FIELDS") or {})
|
||||
fields.update(
|
||||
cwd="~/snail/stuff",
|
||||
cwd_base="stuff",
|
||||
user="lou",
|
||||
hostname="carcolh",
|
||||
env_name=fields["env_prefix"] + "env" + fields["env_postfix"],
|
||||
curr_branch="branch",
|
||||
gitstatus="{CYAN}branch|{BOLD_BLUE}+2{RESET}⚑7",
|
||||
branch_color="{BOLD_INTENSE_RED}",
|
||||
localtime="15:56:07",
|
||||
)
|
||||
yield get_initial(env, prompt_format, fields)
|
||||
for name, template in get_named_prompts():
|
||||
display = html_format(prompt_format(template, fields=fields))
|
||||
yield name, {
|
||||
"value": template,
|
||||
"display": escape(display),
|
||||
}
|
||||
|
||||
|
||||
def render_colors():
|
||||
source = (
|
||||
"import sys\n"
|
||||
'echo "Welcome $USER on" @(sys.platform)\n\n'
|
||||
"def func(x=42):\n"
|
||||
' d = {"xonsh": True}\n'
|
||||
' return d.get("xonsh") and you\n\n'
|
||||
"# This is a comment\n"
|
||||
"![env | uniq | sort | grep PATH]\n"
|
||||
)
|
||||
lexer = XonshLexer()
|
||||
lexer.add_filter("tokenmerge")
|
||||
token_stream = list(pygments.lex(source, lexer=lexer))
|
||||
token_stream = [(t, s.replace("\n", "\\n")) for t, s in token_stream]
|
||||
styles = sorted(get_all_styles())
|
||||
styles.insert(0, styles.pop(styles.index("default")))
|
||||
for style in styles:
|
||||
try:
|
||||
display = html_format(token_stream, style=style)
|
||||
except Exception as ex:
|
||||
logging.error(
|
||||
f"Failed to format Xonsh code {ex!r}. {style!r}", exc_info=True
|
||||
)
|
||||
display = source
|
||||
yield style, escape(display)
|
||||
|
||||
|
||||
def format_xontrib(xontrib: Xontrib):
|
||||
return {
|
||||
"url": xontrib.url,
|
||||
"license": xontrib.package.license if xontrib.package else "",
|
||||
"display": escape(rst_to_html(xontrib.description)),
|
||||
}
|
||||
|
||||
|
||||
def render_xontribs():
|
||||
md = get_xontribs()
|
||||
for xontrib_name, xontrib in md.items():
|
||||
yield xontrib_name, format_xontrib(xontrib)
|
|
@ -698,13 +698,13 @@ def _web(
|
|||
|
||||
Parameters
|
||||
----------
|
||||
browser : --nb, --no-browser
|
||||
browser : --nb, --no-browser, -n
|
||||
don't open browser
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
from xonsh.webconfig import main
|
||||
|
||||
subprocess.run([sys.executable, "-m", "xonsh.webconfig"] + _args[1:])
|
||||
main.main(_args[1:])
|
||||
|
||||
|
||||
def _jupyter_kernel(
|
||||
|
@ -802,7 +802,7 @@ class XonfigAlias(ArgParserAlias):
|
|||
return parser
|
||||
|
||||
|
||||
xonfig_main = XonfigAlias()
|
||||
xonfig_main = XonfigAlias(threadable=False)
|
||||
|
||||
|
||||
@lazyobject
|
||||
|
|
|
@ -54,7 +54,7 @@ def prompt_xontrib_install(names: tp.List[str]):
|
|||
if xontrib.package:
|
||||
packages.append(xontrib.package.name)
|
||||
|
||||
print(
|
||||
return (
|
||||
"The following xontribs are enabled but not installed: \n"
|
||||
" {xontribs}\n"
|
||||
"To install them run \n"
|
||||
|
@ -110,6 +110,8 @@ def xontribs_load(
|
|||
"""
|
||||
ctx = XSH.ctx
|
||||
res = ExitCode.OK
|
||||
stdout = None
|
||||
stderr = None
|
||||
for name in names:
|
||||
if verbose:
|
||||
print(f"loading xontrib {name!r}")
|
||||
|
@ -120,9 +122,9 @@ def xontribs_load(
|
|||
print_exception(f"Failed to load xontrib {name}.")
|
||||
if hasattr(update_context, "bad_imports"):
|
||||
res = ExitCode.NOT_FOUND
|
||||
prompt_xontrib_install(update_context.bad_imports) # type: ignore
|
||||
stderr = prompt_xontrib_install(update_context.bad_imports) # type: ignore
|
||||
del update_context.bad_imports # type: ignore
|
||||
return res
|
||||
return stdout, stderr, res
|
||||
|
||||
|
||||
def xontrib_installed(names: tp.Set[str]):
|
||||
|
|
Loading…
Add table
Reference in a new issue