mirror of
https://github.com/httpie/cli.git
synced 2024-11-07 16:34:35 +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(
|
||||
env, pygments_style=args.style)
|
||||
|
||||
output = []
|
||||
buf = []
|
||||
|
||||
if do_output_request:
|
||||
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_body=cliparse.OUT_REQ_BODY in args.output_options
|
||||
)
|
||||
output.append(req)
|
||||
output.append('\n')
|
||||
buf.append(req)
|
||||
buf.append('\n')
|
||||
if do_output_response:
|
||||
output.append('\n')
|
||||
buf.append('\n')
|
||||
|
||||
if do_output_response:
|
||||
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_body=cliparse.OUT_RESP_BODY in args.output_options
|
||||
)
|
||||
output.append(resp)
|
||||
output.append('\n')
|
||||
buf.append(resp)
|
||||
buf.append('\n')
|
||||
|
||||
return ''.join(output)
|
||||
return ''.join(buf)
|
||||
|
||||
|
||||
def main(args=sys.argv[1:], env=Environment()):
|
||||
parser = cli.parser
|
||||
args = parser.parse_args(args=args, env=env)
|
||||
args = cli.parser.parse_args(args=args, env=env)
|
||||
response = get_response(args)
|
||||
output = get_output(args, env, response)
|
||||
output_bytes = output.encode('utf8')
|
||||
|
@ -1,13 +1,22 @@
|
||||
import os
|
||||
import sys
|
||||
from requests.compat import urlparse
|
||||
from requests.compat import urlparse, is_windows
|
||||
|
||||
|
||||
class Environment(object):
|
||||
stdin_isatty = sys.stdin.isatty()
|
||||
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 = sys.stdout
|
||||
|
||||
# Can be set to 0 to disable colors completely.
|
||||
colors = 256 if '256color' in os.environ.get('TERM', '') else 88
|
||||
|
||||
|
@ -18,10 +18,6 @@ from . import solarized
|
||||
|
||||
DEFAULT_STYLE = 'solarized'
|
||||
AVAILABLE_STYLES = [DEFAULT_STYLE] + list(STYLE_MAP.keys())
|
||||
if is_windows:
|
||||
import colorama
|
||||
colorama.init()
|
||||
# 256 looks better on Windows
|
||||
|
||||
|
||||
class HTTPLexer(lexer.RegexLexer):
|
||||
|
Loading…
Reference in New Issue
Block a user