Ejemplo n.º 1
0
def maybe_install(nvim: Nvim) -> None:
    UPDATE_LOG.parent.mkdir(parents=True, exist_ok=True)
    try:
        coded = UPDATE_LOG.read_text()
        before: datetime = decode(datetime,
                                  coded,
                                  decoders=(datetime_str_decoder, ))
    except (FileNotFoundError, DecodeError):
        before = datetime(year=1949, month=9, day=21, tzinfo=timezone.utc)

    now = datetime.now(tz=timezone.utc)
    diff = now - before
    if diff.days > 7:
        ans = ask_mc(
            nvim,
            question=LANG("update?"),
            answers=LANG("ask yes/no"),
            answer_key={
                1: 1,
                2: 2
            },
        )
        if ans:
            coded = encode(now, encoders=(datetime_str_encoder, ))
            UPDATE_LOG.write_text(coded)

        if ans == 1:
            open_term(nvim, executable, INSTALL_SCRIPT, "deps", "packages")
Ejemplo n.º 2
0
def dump_session(state: State) -> None:
    session = Session(
        index=state.index, show_hidden=state.show_hidden, enable_vc=state.enable_vc
    )
    json = encode(session)

    path = _session_path(state.root.path)
    path.parent.mkdir(mode=FOLDER_MODE, parents=True, exist_ok=True)
    with path.open("w") as fd:
        dump(json, fd, ensure_ascii=False, check_circular=False, indent=2)
Ejemplo n.º 3
0
def dump_session(state: State, use_xdg: bool) -> None:
    session = Session(
        index=state.index, show_hidden=state.show_hidden, enable_vc=state.enable_vc
    )
    json = encode(session)

    path = _session_path(state.root.path, use_xdg=use_xdg)
    path.parent.mkdir(mode=FOLDER_MODE, parents=True, exist_ok=True)
    json = dumps(json, ensure_ascii=False, check_circular=False, indent=2)
    path.write_text(json, "UTF-8")
Ejemplo n.º 4
0
def main() -> None:
    ls_colours = load_ls_colours()
    icon_colours = load_icon_colours()
    icons, text_colours = load_text_decors()
    artifact = Artifact(
        icons=icons,
        ls_colours=ls_colours,
        icon_colours=icon_colours,
        text_colours=text_colours,
    )

    json = recur_sort(encode(artifact))
    with ARTIFACT.open("w") as fd:
        dump(json, fd, ensure_ascii=False, check_circular=False, indent=2)
Ejemplo n.º 5
0
def pprn(fmt: PrintFmt, text: str, resp: Resp, l_pad: int) -> Iterator[str]:
    if fmt is PrintFmt.json:
        yield dumps(
            recur_sort(encode(resp)),
            check_circular=False,
            ensure_ascii=False,
        )
    elif fmt is PrintFmt.pretty:
        cols, _ = get_terminal_size()
        yield "#" * cols
        yield linesep

        yield resp.language.name
        yield linesep * 2

        for match in _parse_matches(text, resp.matches):
            yield cols * "*"
            yield linesep
            yield from _pprn_match(match, l_pad=l_pad)

        yield "#" * cols
    else:
        never(fmt)
Ejemplo n.º 6
0
"""


def _encode_spec(spec: LspAttrs) -> Mapping[str, Any]:
    config: MutableMapping[str, Any] = {}
    if spec.args is not None:
        config["cmd"] = (spec.bin, *spec.args)
    if spec.filetypes:
        config["filetypes"] = spec.filetypes
    if spec.init_options:
        config["init_options"] = spec.init_options
    if spec.settings:
        config["settings"] = spec.settings

    return config


for spec in lsp_specs:
    if which(spec.bin):
        config = _encode_spec(spec)
        args = (
            _find_root.name,
            _on_attach.name,
            spec.server,
            encode(config),
            encode(spec.root),
        )
        atomic.exec_lua(_LSP_INIT, args)

atomic.command("doautoall Filetype")