Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON highlighting corrupted by green background in Windows Terminal #1266

Closed
2 tasks done
wjrogers opened this issue Jan 11, 2022 · 6 comments · Fixed by #1268
Closed
2 tasks done

JSON highlighting corrupted by green background in Windows Terminal #1266

wjrogers opened this issue Jan 11, 2022 · 6 comments · Fixed by #1268
Labels
bug Something isn't working windows Windows specific issue

Comments

@wjrogers
Copy link

Checklist

  • I've searched for similar issues.
  • I'm using the latest version of HTTPie.

Minimal reproduction code and steps

  1. Request a JSON file using HTTPie in Windows Terminal, e.g. http -j GET https://raw.githubusercontent.com/httpie/httpie/master/tests/fixtures/test.json
  2. Observe corrupt/incorrect green background in JSON syntax highlighting

Windows Terminal version 1.11.3471.0
Windows 10 21H2 (19044.1415)
HTTPie 2.6.0
Python 3.10.1

JSON highlighting used to work correctly for me, but I'm not sure in exactly which version(s). I tested in Command Prompt, too, with the same result, so I don't think this is specific to Windows Terminal.


Debug output

>http -j --debug GET https://raw.githubusercontent.com/httpie/httpie/master/tests/fixtures/test.json
HTTPie 2.6.0
Requests 2.27.1
Pygments 2.11.2
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]
C:\Users\will\scoop\apps\python\current\python.exe
Windows 10

<Environment {'colors': 256,
 'config': {'default_options': []},
 'config_dir': WindowsPath('C:/Users/will/AppData/Roaming/httpie'),
 'devnull': <property object at 0x000002A31B077A10>,
 'is_windows': True,
 'log_error': <function Environment.log_error at 0x000002A31B097010>,
 'program_name': 'http',
 'stderr': <colorama.ansitowin32.StreamWrapper object at 0x000002A31B089D80>,
 'stderr_isatty': True,
 'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
 'stdin_encoding': 'utf-8',
 'stdin_isatty': True,
 'stdout': <colorama.ansitowin32.StreamWrapper object at 0x000002A31B089690>,
 'stdout_encoding': 'utf-8',
 'stdout_isatty': True}>

<PluginManager {'adapters': [],
 'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
          <class 'httpie.plugins.builtin.DigestAuthPlugin'>],
 'converters': [],
 'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
                <class 'httpie.output.formatters.json.JSONFormatter'>,
                <class 'httpie.output.formatters.xml.XMLFormatter'>,
                <class 'httpie.output.formatters.colors.ColorFormatter'>]}>

>>> requests.request(**{'auth': None,
 'data': '',
 'headers': {'User-Agent': b'HTTPie/2.6.0', 'Accept': b'application/json, */*;q=0.5', 'Content-Type': b'application/json'},
 'method': 'get',
 'params': <generator object MultiValueOrderedDict.items at 0x000002A31B178AC0>,
 'url': 'https://raw.githubusercontent.com/httpie/httpie/master/tests/fixtures/test.json'})

HTTP/1.1 200 OK
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Cache-Control: max-age=300
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 180
Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
Content-Type: text/plain; charset=utf-8
Date: Tue, 11 Jan 2022 15:00:58 GMT
ETag: W/"020a89035cfd7a956c3a3db63baedb50bec31c5b8516170321eeb60c2f338f55"
Expires: Tue, 11 Jan 2022 15:05:58 GMT
Source-Age: 79
Strict-Transport-Security: max-age=31536000
Vary: Authorization,Accept-Encoding,Origin
Via: 1.1 varnish
X-Cache: HIT
X-Cache-Hits: 1
X-Content-Type-Options: nosniff
X-Fastly-Request-ID: 3f9a95965264c43c85ce6b1c6b891280811ce375
X-Frame-Options: deny
X-GitHub-Request-Id: B0CA:18E9:14CFB7:1AFE2C:61DD9B58
X-Served-By: cache-iad-kcgs7200037-IAD
X-Timer: S1641913258.082057,VS0,VE1
X-XSS-Protection: 1; mode=block

{
    "name": "Jakub Roztočil",
    "unicode": "χρυσαφὶ 太陽 เลิศ ♜♞♝♛♚♝♞♜ оживлённым तान्यहानि 有朋"
}

Additional information, screenshots, or code examples

image

@wjrogers wjrogers added bug Something isn't working new Needs triage. Comments are welcome! labels Jan 11, 2022
@isidentical
Copy link
Contributor

@wjrogers does other styles work for you (http --help can show other alternatives)?

@wjrogers
Copy link
Author

@isidentical yes, actually! Some don't seem to do anything (i.e. the output is not colored), but auto works:

image

@isidentical
Copy link
Contributor

As as a quick workaround (until this issue gets resolved) you can actually set it as the default by adding the following to your config file (possibly located at %APPDATA%\httpie\config.json):

{
    "default_options": [
        "--style=auto"
    ]
}

We normally use fruity (a custom theme) as the default on windows (and auto on linux/mac os) because we had reports in the past that it was the best looking, though we probably should re-investigate this and perhaps use auto on all platforms.
https://github.com/httpie/httpie/blob/508788ca5688bbdfba24b1a810d3091c78eccf46/httpie/output/formatters/colors.py#L30-L34

@isidentical isidentical added windows Windows specific issue and removed new Needs triage. Comments are welcome! labels Jan 11, 2022
@mchodder
Copy link

I'm having this same issue and I can't seem to figure out how to get --style to work for me. I also can't find the config.json file. I'm operating on windows.

@isidentical
Copy link
Contributor

Hey @FftyShadesofCode! Would you mind trying http --style=auto pie.dev/get and sending the output as a screenshot?

@mchodder
Copy link

mchodder commented Jan 13, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Windows specific issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants