mirror of
https://github.com/httpie/cli.git
synced 2025-01-12 08:38:28 +01:00
Fixed colorama initialization (#36).
This commit is contained in:
parent
19f760450f
commit
0a673613ef
@ -89,7 +89,7 @@ def get_output(args, env, response):
|
|||||||
prettifier = OutputProcessor(
|
prettifier = OutputProcessor(
|
||||||
env, pygments_style=args.style)
|
env, pygments_style=args.style)
|
||||||
|
|
||||||
output = []
|
buf = []
|
||||||
|
|
||||||
if do_output_request:
|
if do_output_request:
|
||||||
req = HTTPMessage.from_request(response.request).format(
|
req = HTTPMessage.from_request(response.request).format(
|
||||||
@ -97,10 +97,10 @@ def get_output(args, env, response):
|
|||||||
with_headers=cliparse.OUT_REQ_HEAD in args.output_options,
|
with_headers=cliparse.OUT_REQ_HEAD in args.output_options,
|
||||||
with_body=cliparse.OUT_REQ_BODY in args.output_options
|
with_body=cliparse.OUT_REQ_BODY in args.output_options
|
||||||
)
|
)
|
||||||
output.append(req)
|
buf.append(req)
|
||||||
output.append('\n')
|
buf.append('\n')
|
||||||
if do_output_response:
|
if do_output_response:
|
||||||
output.append('\n')
|
buf.append('\n')
|
||||||
|
|
||||||
if do_output_response:
|
if do_output_response:
|
||||||
resp = HTTPMessage.from_response(response).format(
|
resp = HTTPMessage.from_response(response).format(
|
||||||
@ -108,15 +108,14 @@ def get_output(args, env, response):
|
|||||||
with_headers=cliparse.OUT_RESP_HEAD in args.output_options,
|
with_headers=cliparse.OUT_RESP_HEAD in args.output_options,
|
||||||
with_body=cliparse.OUT_RESP_BODY in args.output_options
|
with_body=cliparse.OUT_RESP_BODY in args.output_options
|
||||||
)
|
)
|
||||||
output.append(resp)
|
buf.append(resp)
|
||||||
output.append('\n')
|
buf.append('\n')
|
||||||
|
|
||||||
return ''.join(output)
|
return ''.join(buf)
|
||||||
|
|
||||||
|
|
||||||
def main(args=sys.argv[1:], env=Environment()):
|
def main(args=sys.argv[1:], env=Environment()):
|
||||||
parser = cli.parser
|
args = cli.parser.parse_args(args=args, env=env)
|
||||||
args = parser.parse_args(args=args, env=env)
|
|
||||||
response = get_response(args)
|
response = get_response(args)
|
||||||
output = get_output(args, env, response)
|
output = get_output(args, env, response)
|
||||||
output_bytes = output.encode('utf8')
|
output_bytes = output.encode('utf8')
|
||||||
|
@ -1,13 +1,22 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from requests.compat import urlparse
|
from requests.compat import urlparse, is_windows
|
||||||
|
|
||||||
|
|
||||||
class Environment(object):
|
class Environment(object):
|
||||||
stdin_isatty = sys.stdin.isatty()
|
stdin_isatty = sys.stdin.isatty()
|
||||||
stdin = sys.stdin
|
stdin = sys.stdin
|
||||||
|
|
||||||
|
if is_windows:
|
||||||
|
# `colorama` patches `sys.stdout` so its initialization
|
||||||
|
# needs to happen before the default environment is set.
|
||||||
|
import colorama
|
||||||
|
colorama.init()
|
||||||
|
del colorama
|
||||||
|
|
||||||
stdout_isatty = sys.stdout.isatty()
|
stdout_isatty = sys.stdout.isatty()
|
||||||
stdout = sys.stdout
|
stdout = sys.stdout
|
||||||
|
|
||||||
# Can be set to 0 to disable colors completely.
|
# Can be set to 0 to disable colors completely.
|
||||||
colors = 256 if '256color' in os.environ.get('TERM', '') else 88
|
colors = 256 if '256color' in os.environ.get('TERM', '') else 88
|
||||||
|
|
||||||
|
@ -18,10 +18,6 @@ from . import solarized
|
|||||||
|
|
||||||
DEFAULT_STYLE = 'solarized'
|
DEFAULT_STYLE = 'solarized'
|
||||||
AVAILABLE_STYLES = [DEFAULT_STYLE] + list(STYLE_MAP.keys())
|
AVAILABLE_STYLES = [DEFAULT_STYLE] + list(STYLE_MAP.keys())
|
||||||
if is_windows:
|
|
||||||
import colorama
|
|
||||||
colorama.init()
|
|
||||||
# 256 looks better on Windows
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPLexer(lexer.RegexLexer):
|
class HTTPLexer(lexer.RegexLexer):
|
||||||
|
Loading…
Reference in New Issue
Block a user