httpie / cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
https://httpie.io
BSD 3-Clause "New" or "Revised" License
32.73k stars 3.68k forks source link

On windows, colors are missing from wttr.in #1432

Open Gorthog opened 1 year ago

Gorthog commented 1 year ago

Checklist


Minimal reproduction code and steps

  1. from windows 11, call "http wttr.in/london"

Current result

widget have no colors

Expected result

widget have colors


Debug output

Please re-run the command with --debug, then copy the entire command & output and paste both below:

http --debug -p=b wttr.in/london
HTTPie 3.2.1
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:\Python310\python.exe
Windows 10

<Environment {'apply_warnings_filter': <function Environment.apply_warnings_filter at 0x0000024975C16CB0>,
 'args': Namespace(),
 'as_silent': <function Environment.as_silent at 0x0000024975C16B90>,
 'colors': 256,
 'config': {'default_options': []},
 'config_dir': WindowsPath('C:/Users/amirs/AppData/Roaming/httpie'),
 'devnull': <property object at 0x0000024975BCA660>,
 'is_windows': True,
 'log_error': <function Environment.log_error at 0x0000024975C16C20>,
 'program_name': 'http',
 'quiet': 0,
 'rich_console': <functools.cached_property object at 0x0000024975BD9E40>,
 'rich_error_console': <functools.cached_property object at 0x0000024975BDA080>,
 'show_displays': True,
 'stderr': <colorama.ansitowin32.StreamWrapper object at 0x0000024975BD9BA0>,
 '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 0x0000024975BD8190>,
 'stdout_encoding': 'utf-8',
 'stdout_isatty': True}>

<PluginManager {'adapters': [],
 'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
          <class 'httpie.plugins.builtin.DigestAuthPlugin'>,
          <class 'httpie.plugins.builtin.BearerAuthPlugin'>],
 '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': RequestJSONDataDict(),
 'headers': <HTTPHeadersDict('User-Agent': b'HTTPie/3.2.1')>,
 'method': 'get',
 'params': <generator object MultiValueOrderedDict.items at 0x0000024975F967A0>,
 'url': 'http://wttr.in/london'})

Weather report: london

      \   /     Clear
       .-.      20 °C
    ― (   ) ―   ← 17 km/h
       `-’      10 km
      /   \     0.0 mm
                                                       ┌─────────────┐
┌──────────────────────────────┬───────────────────────┤  Sun 28 Aug ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│    \  /       Partly cloudy  │     \   /     Sunny          │    \  /       Partly cloudy  │    \  /       Partly cloudy  │
│  _ /"".-.     20 °C          │      .-.      +23(24) °C     │  _ /"".-.     20 °C          │  _ /"".-.     18 °C          │
│    \_(   ).   ← 10-12 km/h   │   ― (   ) ―   ← 13-14 km/h   │    \_(   ).   ← 14-17 km/h   │    \_(   ).   ← 12-15 km/h   │
│    /(___(__)  10 km          │      `-’      10 km          │    /(___(__)  10 km          │    /(___(__)  10 km          │
│               0.0 mm | 0%    │     /   \     0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐
┌──────────────────────────────┬───────────────────────┤  Mon 29 Aug ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│     \   /     Sunny          │     \   /     Sunny          │     \   /     Sunny          │     \   /     Clear          │
│      .-.      18 °C          │      .-.      22 °C          │      .-.      20 °C          │      .-.      17 °C          │
│   ― (   ) ―   ↙ 14-17 km/h   │   ― (   ) ―   ↙ 15-17 km/h   │   ― (   ) ―   ← 16-19 km/h   │   ― (   ) ―   ↙ 16-21 km/h   │
│      `-’      10 km          │      `-’      10 km          │      `-’      10 km          │      `-’      10 km          │
│     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐
┌──────────────────────────────┬───────────────────────┤  Tue 30 Aug ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│    \  /       Partly cloudy  │     \   /     Sunny          │     \   /     Sunny          │     \   /     Clear          │
│  _ /"".-.     17 °C          │      .-.      22 °C          │      .-.      22 °C          │      .-.      17 °C          │
│    \_(   ).   ↙ 15-18 km/h   │   ― (   ) ―   ↙ 13-15 km/h   │   ― (   ) ―   ↙ 14-16 km/h   │   ― (   ) ―   ↙ 14-20 km/h   │
│    /(___(__)  10 km          │      `-’      10 km          │      `-’      10 km          │      `-’      10 km          │
│               0.0 mm | 0%    │     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
Location: London [51.509648,-0.099076]

Follow @igor_chubin for wttr.in updates

Additional information, screenshots, or code examples

http vs curl image

also on WSL, http works as expected.

faraazb commented 1 year ago

The response from wttr.in contains a number of ANSI escape sequences not supported by coloroma. Withhttp wttr.in --pretty format or even http wttr.in --pretty none, the escape sequences are processed by Windows Terminal and the colors appear as expected, but not in Command Prompt due to VT100 being disabled by default. I don't know how curl works around it.

Gorthog commented 1 year ago

As Windows Terminal will be the default command line for future Windows, I think it's reasonable to support it only and not Command Prompt. However, why by default http wttr.in does not show all colors on Windows Terminal? Is it limitation of colorma on Windows?

faraazb commented 1 year ago

Yes, colorama supports these ANSI sequences. However, response from wttr contains many unsupported ones (e.g. 38, 208, 214, 226). I think, the purpose of having colorama is to support Windows Console? Windows Terminal supports them by default. Maybe further detecting conhost and only then using colorama is a good solution.