def create_io( self, application, args, input_stream=None, output_stream=None, error_stream=None, ): if input_stream is None: input_stream = StandardInputStream() if output_stream is None: output_stream = StandardOutputStream() if error_stream is None: error_stream = ErrorOutputStream() style_set = application.config.style_set output_formatter = error_formatter = PlainFormatter(style_set) io = self.io_class( Input(input_stream), Output(output_stream, output_formatter), Output(error_stream, error_formatter), ) if args.has_token("-v"): io.set_verbosity(VERBOSE) io.set_interactive(False) return io
def __init__( self, input=None, output=None, error_output=None ): # type: (Optional[Input], Optional[Output], Optional[Output]) -> None if input is None: input_stream = StandardInputStream() input = Input(input_stream) if output is None: output_stream = StandardOutputStream() if output_stream.supports_ansi(): formatter = AnsiFormatter() else: formatter = PlainFormatter() output = Output(output_stream, formatter) if error_output is None: error_stream = ErrorOutputStream() if error_stream.supports_ansi(): formatter = AnsiFormatter() else: formatter = PlainFormatter() error_output = Output(error_stream, formatter) super(ConsoleIO, self).__init__(input, output, error_output)
def config(): # type: () -> Generator[ApplicationConfig] config = ApplicationConfig() config.set_catch_exceptions(False) config.set_terminate_after_run(False) config.set_io_factory( lambda app, args, input_stream, output_stream, error_stream: IO( Input(input_stream), Output(output_stream), Output(error_stream))) yield config
def create_io( self, application, args, input_stream=None, output_stream=None, error_stream=None, ): # type: (Application, RawArgs, InputStream, OutputStream, OutputStream) -> IO if input_stream is None: input_stream = StandardInputStream() if output_stream is None: output_stream = StandardOutputStream() if error_stream is None: error_stream = ErrorOutputStream() style_set = application.config.style_set if args.has_option_token("--no-ansi"): output_formatter = error_formatter = PlainFormatter(style_set) elif args.has_option_token("--ansi"): output_formatter = error_formatter = AnsiFormatter(style_set, True) else: if output_stream.supports_ansi(): output_formatter = AnsiFormatter(style_set) else: output_formatter = PlainFormatter(style_set) if error_stream.supports_ansi(): error_formatter = AnsiFormatter(style_set) else: error_formatter = PlainFormatter(style_set) io = self.io_class( Input(input_stream), Output(output_stream, output_formatter), Output(error_stream, error_formatter), ) if args.has_option_token("-vvv") or self.is_debug(): io.set_verbosity(DEBUG) elif args.has_option_token("-vv"): io.set_verbosity(VERY_VERBOSE) elif args.has_option_token("-v"): io.set_verbosity(VERBOSE) if args.has_option_token("--quiet") or args.has_option_token("-q"): io.set_quiet(True) if args.has_option_token("--no-interaction") or args.has_option_token( "-n"): io.set_interactive(False) return io
def __init__(self, input_data="", formatter=None): # type: (str, Optional[Formatter]) -> None if formatter is None: formatter = PlainFormatter() input = Input(StringInputStream(input_data)) output = Output(BufferedOutputStream(), formatter) error_output = Output(BufferedOutputStream(), formatter) super(BufferedIO, self).__init__(input, output, error_output)
def __init__(self, style_set): input_stream = StandardInputStream() input = Input(input_stream) output_stream = StandardOutputStream() if output_stream.supports_ansi(): formatter = AnsiFormatter(style_set) else: formatter = PlainFormatter(style_set) output = Output(output_stream, formatter) error_stream = ErrorOutputStream() if error_stream.supports_ansi(): formatter = AnsiFormatter() else: formatter = PlainFormatter() error_output = Output(error_stream, formatter) super(GotIO, self).__init__(input, output, error_output)
def create_io( self, application, args, input_stream=None, output_stream=None, error_stream=None, ): # type: (Application, RawArgs, InputStream, OutputStream, OutputStream) -> IO if input_stream is None: input_stream = StandardInputStream() if output_stream is None: output_stream = StandardOutputStream() if error_stream is None: error_stream = ErrorOutputStream() style_set = application.config.style_set if output_stream.supports_ansi(): output_formatter = AnsiFormatter(style_set) else: output_formatter = PlainFormatter(style_set) if error_stream.supports_ansi(): error_formatter = AnsiFormatter(style_set) else: error_formatter = PlainFormatter(style_set) io = self.io_class( Input(input_stream), Output(output_stream, output_formatter), Output(error_stream, error_formatter), ) resolved_command = application.resolve_command(args) # If the current command is the run one, skip option # check and interpret them as part of the executed command if resolved_command.command.name == "run": return io if args.has_option_token("--no-ansi"): formatter = PlainFormatter(style_set) io.output.set_formatter(formatter) io.error_output.set_formatter(formatter) elif args.has_option_token("--ansi"): formatter = AnsiFormatter(style_set, True) io.output.set_formatter(formatter) io.error_output.set_formatter(formatter) if args.has_option_token("-vvv") or self.is_debug(): io.set_verbosity(DEBUG) elif args.has_option_token("-vv"): io.set_verbosity(VERY_VERBOSE) elif args.has_option_token("-v"): io.set_verbosity(VERBOSE) if args.has_option_token("--quiet") or args.has_option_token("-q"): io.set_quiet(True) if args.has_option_token("--no-interaction") or args.has_option_token( "-n"): io.set_interactive(False) return io
def __init__(self): # type: () -> None input = Input(NullInputStream()) output = Output(NullOutputStream()) error_output = Output(NullOutputStream()) super(NullIO, self).__init__(input, output, error_output)