示例#1
0
def initial(nvim: Nvim, specs: Sequence[RpcSpec]) -> Settings:
    artifacts: Artifact = decode(Artifact, safe_load(ARTIFACT.read_bytes()))

    user_config = nvim.vars.get(SETTINGS_VAR, {})
    config: _UserConfig = decode(
        _UserConfig,
        merge(safe_load(CONFIG_YML.read_bytes()),
              hydrate(user_config),
              replace=True),
    )
    options, view, theme = config.options, config.view, config.theme

    icons, hl_context = load_theme(
        nvim,
        artifact=artifacts,
        particular_mappings=theme.highlights,
        discrete_colours=theme.discrete_colour_map,
        icon_set=theme.icon_glyph_set,
        icon_colour_set=theme.icon_colour_set,
        text_colour_set=theme.text_colour_set,
    )

    view_opts = ViewOptions(
        hl_context=hl_context,
        icons=icons,
        sort_by=view.sort_by,
        use_icons=theme.icon_glyph_set is not IconGlyphSetEnum.ascii,
        time_fmt=view.time_format,
    )

    keymap = {f"CHAD{k}": v for k, v in config.keymap.items()}
    legal_keys = {name for name, _ in specs}
    extra_keys = keymap.keys() - legal_keys

    if extra_keys:
        raise DecodeError(
            path=(_UserOptions, _key_sort(legal_keys)),
            actual=None,
            missing_keys=(),
            extra_keys=_key_sort(extra_keys),
        )

    settings = Settings(
        follow=options.follow,
        ignores=config.ignore,
        keymap=keymap,
        lang=options.lang,
        mime=options.mimetypes,
        open_left=view.open_direction is _OpenDirection.left,
        page_increment=options.page_increment,
        polling_rate=float(options.polling_rate),
        session=options.session,
        show_hidden=options.show_hidden,
        version_ctl=options.version_control,
        view=view_opts,
        width=view.width,
        win_local_opts=view.window_options,
    )

    return settings
示例#2
0
def load_text_decors() -> Tuple[IconGlyphSet, TextColourSet]:
    yaml = safe_load(_ICON_BASE.read_bytes())
    json = loads(docker_run(_DOCKERFILE))
    data = merge(json, yaml)
    icon_spec: IconGlyphSet = decode(IconGlyphSet, data, strict=False)
    icon_set = IconGlyphSet(
        ascii=_process_icons(icon_spec.ascii),
        devicons=_process_icons(icon_spec.devicons),
        emoji=_process_icons(icon_spec.emoji),
    )
    colour_spec: TextColourSet = decode(TextColourSet, data, strict=False)
    colour_set = TextColourSet(
        nerdtree_syntax_light=_make_lightmode(_process_colours(colour_spec.nerdtree_syntax_light)),
        nerdtree_syntax_dark=_process_colours(colour_spec.nerdtree_syntax_dark),
    )
    return icon_set, colour_set