Exemplo n.º 1
0
class ApplicationConfig(BaseApplicationConfig):  # pragma: no cover
    """Configures the CLI application."""

    _STYLES = [
        Style("c1").fg("cyan"),
        Style("info").fg("blue"),
        Style("comment").fg("green"),
        Style("error").fg("red").bold(),
        Style("warning").fg("yellow"),
        Style("debug").fg("black").bold(),
        Style("link").fg("blue").underlined(),
        Style("h1").fg("blue").bold().underlined(),
        Style("h2").fg("blue").underlined(),
    ]

    def configure(self) -> None:  # noqa: D102
        super(ApplicationConfig, self).configure()

        for style in ApplicationConfig._STYLES:
            self.add_style(style)

        self.add_option(
            "config",
            "c",
            Option.REQUIRED_VALUE | Option.STRING,
            "Load configuration from a TOML file",
        )

        self.add_option(
            "out",
            "o",
            Option.REQUIRED_VALUE | Option.STRING,
            "the desired output type (json, toml)",
        )
Exemplo n.º 2
0
    def init_styles(self, io):
        from clikit.api.formatter import Style

        for color in self.colors:
            style = Style(color).fg(color)
            io.output.formatter.add_style(style)
            io.error_output.formatter.add_style(style)
Exemplo n.º 3
0
    def add_style(self, name, fg=None, bg=None, options=None):
        """
        Adds a new style
        """
        style = Style(name)
        if fg is not None:
            style.fg(fg)

        if bg is not None:
            style.bg(bg)

        if options is not None:
            if "bold" in options:
                style.bold()

            if "underline" in options:
                style.underlined()

        self._io.output.formatter.add_style(style)
        self._io.error_output.formatter.add_style(style)
Exemplo n.º 4
0
    def __init__(self):  # type: () -> None
        styles = [
            Style("info").fg("green"),
            Style("comment").fg("cyan"),
            Style("question").fg("blue"),
            Style("error").fg("red").bold(),
            Style("b").bold(),
            Style("u").underlined(),
            Style("c1").fg("cyan"),
            Style("c2").fg("yellow"),
        ]

        super(DefaultStyleSet, self).__init__(styles)
Exemplo n.º 5
0
    def add_style(self, name, fg=None, bg=None, options=None):
        """
        Adds a new style
        """
        style = Style(name)
        if fg is not None:
            style.fg(fg)

        if bg is not None:
            style.bg(bg)

        if options is not None:
            if "bold" in options:
                style.bold()

            if "underline" in options:
                style.underlined()

        self._io.output.formatter.add_style(style)
        self._io.error_output.formatter.add_style(style)
Exemplo n.º 6
0
    def configure(self):
        super(ApplicationConfig, self).configure()

        self.add_style(Style("c1").fg("cyan"))
        self.add_style(Style("info").fg("blue"))
        self.add_style(Style("comment").fg("green"))
        self.add_style(Style("error").fg("red").bold())
        self.add_style(Style("warning").fg("yellow"))
        self.add_style(Style("debug").fg("black").bold())

        self.add_event_listener(PRE_HANDLE, self.register_command_loggers)
        self.add_event_listener(PRE_HANDLE, self.set_env)
Exemplo n.º 7
0
    def configure(self):
        super(ApplicationConfig, self).configure()

        self.add_style(Style("c1").fg("cyan"))
        self.add_style(Style("c2").fg("default").bold())
        self.add_style(Style("info").fg("blue"))
        self.add_style(Style("comment").fg("green"))
        self.add_style(Style("error").fg("red").bold())
        self.add_style(Style("warning").fg("yellow").bold())
        self.add_style(Style("debug").fg("default").dark())
        self.add_style(Style("success").fg("green"))

        # Dark variants
        self.add_style(Style("c1_dark").fg("cyan").dark())
        self.add_style(Style("c2_dark").fg("default").bold().dark())
        self.add_style(Style("success_dark").fg("green").dark())

        self.add_event_listener(PRE_HANDLE, self.register_command_loggers)
        self.add_event_listener(PRE_HANDLE, self.set_env)
        self.add_event_listener(PRE_HANDLE, self.set_installer)

        if PY36:
            from poetry.mixology.solutions.providers import (
                PythonRequirementSolutionProvider, )

            self._solution_provider_repository.register_solution_providers(
                [PythonRequirementSolutionProvider])
Exemplo n.º 8
0
    def __init__(self):  # type: () -> None
        styles = [
            Style("info").fg("white").bold(),
            Style("output").bg("light_gray").fg("black"),
            Style("comment").fg("cyan").bold(),
            Style("question").fg("magenta").bold(),
            Style("success").fg("green").bold(),
            Style("warning").fg("yellow").bold(),
            Style("error").fg("red").bold(),
            Style("b").bold(),
            Style("blink").blinking(),
            Style("u").underlined(),
            Style("c1").fg("cyan"),
            Style("bc1").fg("cyan").bold(),
            Style("c2").fg("yellow"),
        ]

        super(GotStyleSet, self).__init__(styles)
Exemplo n.º 9
0
    def _autocomplete(self, io):  # type: (IO) -> str
        """
        Autocomplete a question.
        """
        autocomplete = self._autocomplete_values

        ret = ""

        i = 0
        ofs = -1
        matches = [x for x in autocomplete]
        num_matches = len(matches)

        stty_mode = decode(subprocess.check_output(["stty", "-g"])).rstrip("\n")

        # Disable icanon (so we can read each keypress) and echo (we'll do echoing here instead)
        subprocess.check_output(["stty", "-icanon", "-echo"])

        # Add highlighted text style
        style = Style("hl").fg("black").bg("white")
        io.error_output.formatter.add_style(style)

        # Read a keypress
        while True:
            c = io.read(1)

            # Backspace character
            if c == "\177":
                if num_matches == 0 and i != 0:
                    i -= 1
                    # Move cursor backwards
                    io.error("\033[1D")

                if i == 0:
                    ofs = -1
                    matches = [x for x in autocomplete]
                    num_matches = len(matches)
                else:
                    num_matches = 0

                # Pop the last character off the end of our string
                ret = ret[:i]
            # Did we read an escape sequence
            elif c == "\033":
                c += io.read(2)

                # A = Up Arrow. B = Down Arrow
                if c[2] == "A" or c[2] == "B":
                    if c[2] == "A" and ofs == -1:
                        ofs = 0

                    if num_matches == 0:
                        continue

                    ofs += -1 if c[2] == "A" else 1
                    ofs = (num_matches + ofs) % num_matches
            elif ord(c) < 32:
                if c == "\t" or c == "\n":
                    if num_matches > 0 and ofs != -1:
                        ret = matches[ofs]
                        # Echo out remaining chars for current match
                        io.error(ret[i:])
                        i = len(ret)

                    if c == "\n":
                        io.error(c)
                        break

                    num_matches = 0

                continue
            else:
                io.error(c)
                ret += c
                i += 1

                num_matches = 0
                ofs = 0

                for value in autocomplete:
                    # If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
                    if value.startswith(ret) and i != len(value):
                        num_matches += 1
                        matches[num_matches - 1] = value

            # Erase characters from cursor to end of line
            io.error("\033[K")

            if num_matches > 0 and ofs != -1:
                # Save cursor position
                io.error("\0337")
                # Write highlighted text
                io.error("<hl>" + matches[ofs][i:] + "</hl>")
                # Restore cursor position
                io.error("\0338")

        subprocess.call(["stty", "{}".format(decode(stty_mode))])

        return ret