Esempio n. 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
Esempio n. 2
0
def _settings(nvim: Nvim) -> Settings:
    yml = safe_load(CONFIG_YML.read_text("UTF-8"))
    user_config = nvim.vars.get(SETTINGS_VAR, {})
    u_conf = hydrate(user_config)

    if isinstance(u_conf, Mapping):
        if isinstance(display := u_conf.get("display"), Mapping):
            if isinstance(icons := display.get("icons"), Mapping):
                yml_icons = yml["display"]["icons"]
                if (aliases := icons.get("aliases")) is not None:
                    yml_icons["aliases"] = aliases
                if (mappings := icons.get("mappings")) is not None:
                    yml_icons["mappings"] = mappings
Esempio n. 3
0
def initial(nvim: Nvim, specs: Sequence[RpcSpec]) -> Settings:
    a_decode = new_decoder[Artifact](Artifact)
    c_decode = new_decoder[_UserConfig](_UserConfig)

    win = cur_win(nvim)
    artifacts = a_decode(safe_load(ARTIFACT.read_text("UTF-8")))

    user_config = nvim.vars.get(SETTINGS_VAR, {})
    config = c_decode(
        merge(
            safe_load(CONFIG_YML.read_text("UTF-8")), hydrate(user_config), replace=True
        )
    )
    options, view, theme = config.options, config.view, config.theme
    win_actual_opts: Mapping[str, Union[bool, str]] = {
        opt: cast(Union[bool, str], win_get_option(nvim, win=win, key=opt))
        for opt in view.window_options
    }

    icons, hl_context = load_theme(
        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,
    )

    use_icons = theme.icon_glyph_set not in {
        IconGlyphSetEnum.ascii,
        IconGlyphSetEnum.ascii_hollow,
    }

    view_opts = ViewOptions(
        hl_context=hl_context,
        icons=icons,
        sort_by=view.sort_by,
        use_icons=use_icons,
        time_fmt=view.time_format,
    )

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

    if extra_keys:
        raise DecodeError(
            path=(_UserOptions, sorted(legal_keys, key=strxfrm)),
            actual=None,
            missing_keys=(),
            extra_keys=sorted(extra_keys, key=strxfrm),
        )

    else:
        settings = Settings(
            close_on_open=options.close_on_open,
            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_actual_opts=win_actual_opts,
            win_local_opts=view.window_options,
            xdg=config.xdg,
            profiling=config.profiling,
        )

        return settings