From 3933ea92db78a80fa4d4ac2d9d9f33a6fa5c9183 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Wed, 8 Dec 2021 13:53:12 +0300 Subject: [PATCH 1/7] Implement new `pie` and `pie-light` styles --- CHANGELOG.md | 1 + docs/README.md | 2 + httpie/output/formatters/colors.py | 229 +++++++++++++++++++++++++++-- httpie/output/lexers/http.py | 72 ++++++++- 4 files changed, 289 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e3b9a5f4f..329bcf82ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). - Added support for _receiving_ multiple HTTP headers lines with the same name. ([#1207](https://github.com/httpie/httpie/issues/1207)) - Added support for basic JSON types on `--form`/`--multipart` when using JSON only operators (`:=`/`:=@`). ([#1212](https://github.com/httpie/httpie/issues/1212)) - Added support for automatically enabling `--stream` when `Content-Type` is `text/event-stream`. ([#376](https://github.com/httpie/httpie/issues/376)) +- Added new `pie` (and `pie-light`) styles that match with the [HTTPie for Web and Desktop](https://httpie.io/app). ([#1237](https://github.com/httpie/httpie/issues/1237)) - Broken plugins will no longer crash the whole application. ([#1204](https://github.com/httpie/httpie/issues/1204)) ## [2.6.0](https://github.com/httpie/httpie/compare/2.5.0...2.6.0) (2021-10-14) diff --git a/docs/README.md b/docs/README.md index 5fd320db97..44b8acd81a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1721,6 +1721,8 @@ There are dozens of styles available, here are just a few notable ones: | --------: | ----------------------------------------------------------------------------------------------------------------------------------- | | `auto` | Follows your terminal ANSI color styles. This is the default style used by HTTPie | | `default` | Default styles of the underlying Pygments library. Not actually used by default by HTTPie. You can enable it with `--style=default` | +| `pie` | HTTPie's original brand style. Also used in the HTTPie for Web and Desktop. | +|`pie-light`| Like `pie`, but for terminals with light background colors. | | `monokai` | A popular color scheme. Enable with `--style=monokai` | | `fruity` | A bold, colorful scheme. Enable with `--style=fruity` | | … | See `$ http --help` for all the possible `--style` values | diff --git a/httpie/output/formatters/colors.py b/httpie/output/formatters/colors.py index b2db70ff37..aae4b90f78 100644 --- a/httpie/output/formatters/colors.py +++ b/httpie/output/formatters/colors.py @@ -1,6 +1,7 @@ import json -from typing import Optional, Type +from typing import Optional, Type, Tuple +import pygments.formatters import pygments.lexer import pygments.lexers import pygments.style @@ -22,7 +23,15 @@ AUTO_STYLE = 'auto' # Follows terminal ANSI color styles DEFAULT_STYLE = AUTO_STYLE -SOLARIZED_STYLE = 'solarized' # Bundled here + +# Bundled here +SOLARIZED_STYLE = 'solarized' +PIE_STYLES = { + 'pie', + 'pie-light', + 'pie-dark' +} + if is_windows: # Colors on Windows via colorama don't look that # great and fruity seems to give the best result there. @@ -30,7 +39,8 @@ BUNDLED_STYLES = { SOLARIZED_STYLE, - AUTO_STYLE + AUTO_STYLE, + *PIE_STYLES, } @@ -66,22 +76,23 @@ def __init__( if use_auto_style or not has_256_colors: http_lexer = PygmentsHttpLexer() formatter = TerminalFormatter() + body_formatter = formatter + header_formatter = formatter else: from ..lexers.http import SimplifiedHTTPLexer - http_lexer = SimplifiedHTTPLexer() - formatter = Terminal256Formatter( - style=self.get_style_class(color_scheme) - ) + header_formatter, body_formatter, precise = self.get_formatters(color_scheme) + http_lexer = SimplifiedHTTPLexer(precise=precise) self.explicit_json = explicit_json # --json - self.formatter = formatter + self.header_formatter = header_formatter + self.body_formatter = body_formatter self.http_lexer = http_lexer def format_headers(self, headers: str) -> str: return pygments.highlight( code=headers, lexer=self.http_lexer, - formatter=self.formatter, + formatter=self.header_formatter, ).strip() def format_body(self, body: str, mime: str) -> str: @@ -90,7 +101,7 @@ def format_body(self, body: str, mime: str) -> str: body = pygments.highlight( code=body, lexer=lexer, - formatter=self.formatter, + formatter=self.body_formatter, ) return body @@ -104,6 +115,25 @@ def get_lexer_for_body( body=body, ) + def get_formatters(self, color_scheme: str) -> Tuple[ + pygments.formatter.Formatter, + pygments.formatter.Formatter, + bool + ]: + if color_scheme in PIE_STYLES: + header_style, body_style = PIE_STYLES[color_scheme] + precise = True + else: + header_style = self.get_style_class(color_scheme) + body_style = header_style + precise = False + + return ( + Terminal256Formatter(style=header_style), + Terminal256Formatter(style=body_style), + precise + ) + @staticmethod def get_style_class(color_scheme: str) -> Type[pygments.style.Style]: try: @@ -237,3 +267,182 @@ class Solarized256Style(pygments.style.Style): pygments.token.Token: BASE1, pygments.token.Token.Other: ORANGE, } + + +LIGHT_COLORS = { + 'accent': '#52AB66', + 'backdrop': '#000000', + 'borders': '#1C1818', + 'canvas': '#E3E3E3', + 'code-aqua': '#698799', + 'code-blue': '#3B5EBA', + 'code-gray': '#7D7D7D', + 'code-green': '#52AB66', + 'code-orange': '#E3822B', + 'code-pink': '#C26EC2', + 'code-primary': '#4F4D4D', + 'code-purple': '#8745BA', + 'code-red': '#C7382E', + 'code-yellow': '#BABA29', + 'focus': '#698FEB', + 'form-bg': '#EDEDEB', + 'hover': '#307842', + 'primary': '#1C1818', + 'secondary': '#1C1818', + 'selection': '#77DB8F', + 'tertiary': '#1C1818', +} + + +DARK_COLORS = { + 'accent': '#73DC8C', + 'backdrop': '#7F7F7F', + 'borders': '#F5F5F0', + 'canvas': '#1C1818', + 'code-aqua': '#8CB4CD', + 'code-blue': '#4B78E6', + 'code-gray': '#7D7D7D', + 'code-green': '#73DC8C', + 'code-orange': '#FFA24E', + 'code-pink': '#FA9BFA', + 'code-primary': '#D1D1CF', + 'code-purple': '#B464F0', + 'code-red': '#FF665B', + 'code-yellow': '#DBDE52', + 'focus': '#3B5EBA', + 'form-bg': '#231F1F', + 'hover': '#A1E8B0', + 'primary': '#F5F5F0', + 'secondary': '#F5F5F0', + 'selection': '#77DB8F', + 'tertiary': '#F5F5F0', +} + + +def format_style(raw_styles, color_mapping): + def format_value(value): + return " ".join( + color_mapping[part] + if part in color_mapping else part + for part in value.split() + ) + + return { + key: format_value(value) + for key, value in raw_styles.items() + } + + +def make_styles(name, raw_styles): + for mode, color_mapping in [ + ('light', LIGHT_COLORS), + ('dark', DARK_COLORS) + ]: + yield type( + name.format(mode=mode.title()), + (pygments.style.Style,), + { + "styles": format_style(raw_styles, color_mapping) + } + ) + + +PieLightHeaderStyle, PieDarkHeaderStyle = make_styles( + 'Pie{mode}HeaderStyle', + { + # HTTP line / Headers / Etc. + pygments.token.Name.Namespace: 'bold primary', + pygments.token.Keyword.Reserved: 'bold code-gray', + pygments.token.Operator: 'bold code-gray', + pygments.token.Number: 'bold code-gray', + pygments.token.Name.Function.Magic: 'bold code-green', + pygments.token.Name.Exception: 'bold code-green', + pygments.token.Name.Attribute: 'code-blue', + pygments.token.String: 'primary', + + # HTTP Methods + pygments.token.Name.Function: 'bold code-gray', + pygments.token.Name.Function.HTTP.GET: 'bold code-green', + pygments.token.Name.Function.HTTP.HEAD: 'bold code-green', + pygments.token.Name.Function.HTTP.POST: 'bold code-yellow', + pygments.token.Name.Function.HTTP.PUT: 'bold code-orange', + pygments.token.Name.Function.HTTP.PATCH: 'bold code-orange', + pygments.token.Name.Function.HTTP.DELETE: 'bold code-red', + + # HTTP status codes + pygments.token.Number.HTTP.INFO: 'bold code-aqua', + pygments.token.Number.HTTP.OK: 'bold code-green', + pygments.token.Number.HTTP.REDIRECT: 'bold code-yellow', + pygments.token.Number.HTTP.CLIENT_ERR: 'bold code-orange', + pygments.token.Number.HTTP.SERVER_ERR: 'bold code-red', + } +) + + +PieLightBodyStyle, PieDarkBodyStyle = make_styles( + 'Pie{mode}BodyStyle', + { + # {}[]: + pygments.token.Punctuation: 'code-gray', + + # Keys + pygments.token.Name.Tag: 'code-pink', + + # Values + pygments.token.Literal.String: 'code-green', + pygments.token.Literal.String.Double: 'code-green', + pygments.token.Literal.Number: 'code-aqua', + pygments.token.Keyword: 'code-orange', + + # Other stuff + pygments.token.Text: 'primary', + pygments.token.Name.Attribute: 'primary', + pygments.token.Name.Builtin: 'code-blue', + pygments.token.Name.Builtin.Pseudo: 'code-blue', + pygments.token.Name.Class: 'code-blue', + pygments.token.Name.Constant: 'code-orange', + pygments.token.Name.Decorator: 'code-blue', + pygments.token.Name.Entity: 'code-orange', + pygments.token.Name.Exception: 'code-yellow', + pygments.token.Name.Function: 'code-blue', + pygments.token.Name.Variable: 'code-blue', + pygments.token.String: 'code-aqua', + pygments.token.String.Backtick: 'secondary', + pygments.token.String.Char: 'code-aqua', + pygments.token.String.Doc: 'code-aqua', + pygments.token.String.Escape: 'code-red', + pygments.token.String.Heredoc: 'code-aqua', + pygments.token.String.Regex: 'code-red', + pygments.token.Number: 'code-aqua', + pygments.token.Operator: 'primary', + pygments.token.Operator.Word: 'code-green', + pygments.token.Comment: 'secondary', + pygments.token.Comment.Preproc: 'code-green', + pygments.token.Comment.Special: 'code-green', + pygments.token.Generic.Deleted: 'code-aqua', + pygments.token.Generic.Emph: 'italic', + pygments.token.Generic.Error: 'code-red', + pygments.token.Generic.Heading: 'code-orange', + pygments.token.Generic.Inserted: 'code-green', + pygments.token.Generic.Strong: 'bold', + pygments.token.Generic.Subheading: 'code-orange', + pygments.token.Token: 'primary', + pygments.token.Token.Other: 'code-orange', + } +) + + +PIE_STYLES = { + 'pie': ( + PieDarkHeaderStyle, + PieDarkBodyStyle, + ), + 'pie-light': ( + PieLightHeaderStyle, + PieLightBodyStyle, + ), + 'pie-dark': ( + PieDarkHeaderStyle, + PieDarkBodyStyle, + ) +} diff --git a/httpie/output/lexers/http.py b/httpie/output/lexers/http.py index 4c2b00d252..0b8b612a0e 100644 --- a/httpie/output/lexers/http.py +++ b/httpie/output/lexers/http.py @@ -1,6 +1,70 @@ +import re import pygments +RE_STATUS_LINE = re.compile(r'(\d{3})( +)(.+)') + +STATUS_TYPES = { + '1': pygments.token.Number.HTTP.INFO, + '2': pygments.token.Number.HTTP.OK, + '3': pygments.token.Number.HTTP.REDIRECT, + '4': pygments.token.Number.HTTP.CLIENT_ERR, + '5': pygments.token.Number.HTTP.SERVER_ERR, +} + +RESPONSE_TYPES = { + 'GET': pygments.token.Name.Function.HTTP.GET, + 'HEAD': pygments.token.Name.Function.HTTP.HEAD, + 'POST': pygments.token.Name.Function.HTTP.POST, + 'PUT': pygments.token.Name.Function.HTTP.PUT, + 'PATCH': pygments.token.Name.Function.HTTP.PATCH, + 'DELETE': pygments.token.Name.Function.HTTP.DELETE, +} + + +def precise(lexer, precise_token, parent_token): + # Due to a pygments bug*, custom tokens will look bad + # on outside styles. Until it is fixed on upstream, we'll + # convey whether the client is using pie style or not + # through precise option and return more precise tokens + # depending on it's value. + # + # [0]: https://github.com/pygments/pygments/issues/1986 + if precise_token is None or not lexer.options.get("precise"): + return parent_token + else: + return precise_token + + +def http_response_type(lexer, match, ctx): + status_match = RE_STATUS_LINE.match(match.group()) + if status_match is None: + return None + + status_code, text, reason = status_match.groups() + status_type = precise( + lexer, + STATUS_TYPES.get(status_code[0]), + pygments.token.Number + ) + + groups = pygments.lexer.bygroups( + status_type, + pygments.token.Text, + status_type + ) + yield from groups(lexer, status_match, ctx) + + +def request_method(lexer, match, ctx): + response_type = precise( + lexer, + RESPONSE_TYPES.get(match.group()), + pygments.token.Name.Function + ) + yield match.start(), response_type, match.group() + + class SimplifiedHTTPLexer(pygments.lexer.RegexLexer): """Simplified HTTP lexer for Pygments. @@ -18,7 +82,7 @@ class SimplifiedHTTPLexer(pygments.lexer.RegexLexer): # Request-Line (r'([A-Z]+)( +)([^ ]+)( +)(HTTP)(/)(\d+\.\d+)', pygments.lexer.bygroups( - pygments.token.Name.Function, + request_method, pygments.token.Text, pygments.token.Name.Namespace, pygments.token.Text, @@ -27,15 +91,13 @@ class SimplifiedHTTPLexer(pygments.lexer.RegexLexer): pygments.token.Number )), # Response Status-Line - (r'(HTTP)(/)(\d+\.\d+)( +)(\d{3})( +)(.+)', + (r'(HTTP)(/)(\d+\.\d+)( +)(.+)', pygments.lexer.bygroups( pygments.token.Keyword.Reserved, # 'HTTP' pygments.token.Operator, # '/' pygments.token.Number, # Version pygments.token.Text, - pygments.token.Number, # Status code - pygments.token.Text, - pygments.token.Name.Exception, # Reason + http_response_type, # Status code and Reason )), # Header (r'(.*?)( *)(:)( *)(.+)', pygments.lexer.bygroups( From 4aab90479ede7b1d9a91401f450fe23fad62f595 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Thu, 16 Dec 2021 19:17:13 +0300 Subject: [PATCH 2/7] Change some pallete --- httpie/output/formatters/colors.py | 34 ++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/httpie/output/formatters/colors.py b/httpie/output/formatters/colors.py index aae4b90f78..ef70985ad6 100644 --- a/httpie/output/formatters/colors.py +++ b/httpie/output/formatters/colors.py @@ -272,32 +272,31 @@ class Solarized256Style(pygments.style.Style): LIGHT_COLORS = { 'accent': '#52AB66', 'backdrop': '#000000', - 'borders': '#1C1818', + 'borders': '#D3D3D3', 'canvas': '#E3E3E3', 'code-aqua': '#698799', 'code-blue': '#3B5EBA', 'code-gray': '#7D7D7D', 'code-green': '#52AB66', 'code-orange': '#E3822B', - 'code-pink': '#C26EC2', - 'code-primary': '#4F4D4D', + 'code-pink': '#8745BA', + 'code-primary': '#8745BA', 'code-purple': '#8745BA', 'code-red': '#C7382E', 'code-yellow': '#BABA29', 'focus': '#698FEB', 'form-bg': '#EDEDEB', 'hover': '#307842', - 'primary': '#1C1818', - 'secondary': '#1C1818', - 'selection': '#77DB8F', - 'tertiary': '#1C1818', + 'secondary': '#6C6969', + 'selection': '#C3E1CA', + 'tertiary': '#BBBABA', } DARK_COLORS = { 'accent': '#73DC8C', 'backdrop': '#7F7F7F', - 'borders': '#F5F5F0', + 'borders': '#2D2A29', 'canvas': '#1C1818', 'code-aqua': '#8CB4CD', 'code-blue': '#4B78E6', @@ -312,10 +311,9 @@ class Solarized256Style(pygments.style.Style): 'focus': '#3B5EBA', 'form-bg': '#231F1F', 'hover': '#A1E8B0', - 'primary': '#F5F5F0', - 'secondary': '#F5F5F0', - 'selection': '#77DB8F', - 'tertiary': '#F5F5F0', + 'secondary': '#9E9D9A', + 'selection': '#37523C', + 'tertiary': '#474344', } @@ -351,14 +349,14 @@ def make_styles(name, raw_styles): 'Pie{mode}HeaderStyle', { # HTTP line / Headers / Etc. - pygments.token.Name.Namespace: 'bold primary', + pygments.token.Name.Namespace: 'bold code-primary', pygments.token.Keyword.Reserved: 'bold code-gray', pygments.token.Operator: 'bold code-gray', pygments.token.Number: 'bold code-gray', pygments.token.Name.Function.Magic: 'bold code-green', pygments.token.Name.Exception: 'bold code-green', pygments.token.Name.Attribute: 'code-blue', - pygments.token.String: 'primary', + pygments.token.String: 'code-primary', # HTTP Methods pygments.token.Name.Function: 'bold code-gray', @@ -395,8 +393,8 @@ def make_styles(name, raw_styles): pygments.token.Keyword: 'code-orange', # Other stuff - pygments.token.Text: 'primary', - pygments.token.Name.Attribute: 'primary', + pygments.token.Text: 'code-primary', + pygments.token.Name.Attribute: 'code-primary', pygments.token.Name.Builtin: 'code-blue', pygments.token.Name.Builtin.Pseudo: 'code-blue', pygments.token.Name.Class: 'code-blue', @@ -414,7 +412,7 @@ def make_styles(name, raw_styles): pygments.token.String.Heredoc: 'code-aqua', pygments.token.String.Regex: 'code-red', pygments.token.Number: 'code-aqua', - pygments.token.Operator: 'primary', + pygments.token.Operator: 'code-primary', pygments.token.Operator.Word: 'code-green', pygments.token.Comment: 'secondary', pygments.token.Comment.Preproc: 'code-green', @@ -426,7 +424,7 @@ def make_styles(name, raw_styles): pygments.token.Generic.Inserted: 'code-green', pygments.token.Generic.Strong: 'bold', pygments.token.Generic.Subheading: 'code-orange', - pygments.token.Token: 'primary', + pygments.token.Token: 'code-primary', pygments.token.Token.Other: 'code-orange', } ) From 87ac7d8590e46e1f113007d3044877702f3c5750 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Fri, 17 Dec 2021 12:57:30 +0300 Subject: [PATCH 3/7] Integrate the color palette --- httpie/output/formatters/colors.py | 187 ++++++++++++----------------- httpie/output/ui/__init__.py | 0 httpie/output/ui/palette.py | 138 +++++++++++++++++++++ 3 files changed, 213 insertions(+), 112 deletions(-) create mode 100644 httpie/output/ui/__init__.py create mode 100644 httpie/output/ui/palette.py diff --git a/httpie/output/formatters/colors.py b/httpie/output/formatters/colors.py index ef70985ad6..3d6d82cd37 100644 --- a/httpie/output/formatters/colors.py +++ b/httpie/output/formatters/colors.py @@ -16,6 +16,7 @@ from pygments.util import ClassNotFound from ..lexers.json import EnhancedJsonLexer +from ..ui.palette import COLOR_PALETTE from ...compat import is_windows from ...context import Environment from ...plugins import FormatterPlugin @@ -269,59 +270,20 @@ class Solarized256Style(pygments.style.Style): } -LIGHT_COLORS = { - 'accent': '#52AB66', - 'backdrop': '#000000', - 'borders': '#D3D3D3', - 'canvas': '#E3E3E3', - 'code-aqua': '#698799', - 'code-blue': '#3B5EBA', - 'code-gray': '#7D7D7D', - 'code-green': '#52AB66', - 'code-orange': '#E3822B', - 'code-pink': '#8745BA', - 'code-primary': '#8745BA', - 'code-purple': '#8745BA', - 'code-red': '#C7382E', - 'code-yellow': '#BABA29', - 'focus': '#698FEB', - 'form-bg': '#EDEDEB', - 'hover': '#307842', - 'secondary': '#6C6969', - 'selection': '#C3E1CA', - 'tertiary': '#BBBABA', -} - - -DARK_COLORS = { - 'accent': '#73DC8C', - 'backdrop': '#7F7F7F', - 'borders': '#2D2A29', - 'canvas': '#1C1818', - 'code-aqua': '#8CB4CD', - 'code-blue': '#4B78E6', - 'code-gray': '#7D7D7D', - 'code-green': '#73DC8C', - 'code-orange': '#FFA24E', - 'code-pink': '#FA9BFA', - 'code-primary': '#D1D1CF', - 'code-purple': '#B464F0', - 'code-red': '#FF665B', - 'code-yellow': '#DBDE52', - 'focus': '#3B5EBA', - 'form-bg': '#231F1F', - 'hover': '#A1E8B0', - 'secondary': '#9E9D9A', - 'selection': '#37523C', - 'tertiary': '#474344', -} +def format_style(raw_styles, shade): + def get_shade(part): + if part not in COLOR_PALETTE: + return part + color_code = COLOR_PALETTE[part] + if isinstance(color_code, dict) and shade in color_code: + return color_code[shade] + else: + return color_code -def format_style(raw_styles, color_mapping): def format_value(value): return " ".join( - color_mapping[part] - if part in color_mapping else part + get_shade(part) for part in value.split() ) @@ -332,108 +294,109 @@ def format_value(value): def make_styles(name, raw_styles): - for mode, color_mapping in [ - ('light', LIGHT_COLORS), - ('dark', DARK_COLORS) + for mode, shade in [ + ('light', '700'), + ('universal', '600'), + ('dark', '500') ]: yield type( name.format(mode=mode.title()), (pygments.style.Style,), { - "styles": format_style(raw_styles, color_mapping) + 'styles': format_style(raw_styles, shade) } ) -PieLightHeaderStyle, PieDarkHeaderStyle = make_styles( +PieLightHeaderStyle, PieUniversalHeaderStyle, PieDarkHeaderStyle = make_styles( 'Pie{mode}HeaderStyle', { # HTTP line / Headers / Etc. - pygments.token.Name.Namespace: 'bold code-primary', - pygments.token.Keyword.Reserved: 'bold code-gray', - pygments.token.Operator: 'bold code-gray', - pygments.token.Number: 'bold code-gray', - pygments.token.Name.Function.Magic: 'bold code-green', - pygments.token.Name.Exception: 'bold code-green', - pygments.token.Name.Attribute: 'code-blue', - pygments.token.String: 'code-primary', + pygments.token.Name.Namespace: 'bold primary', + pygments.token.Keyword.Reserved: 'bold grey', + pygments.token.Operator: 'bold grey', + pygments.token.Number: 'bold grey', + pygments.token.Name.Function.Magic: 'bold green', + pygments.token.Name.Exception: 'bold green', + pygments.token.Name.Attribute: 'blue', + pygments.token.String: 'primary', # HTTP Methods - pygments.token.Name.Function: 'bold code-gray', - pygments.token.Name.Function.HTTP.GET: 'bold code-green', - pygments.token.Name.Function.HTTP.HEAD: 'bold code-green', - pygments.token.Name.Function.HTTP.POST: 'bold code-yellow', - pygments.token.Name.Function.HTTP.PUT: 'bold code-orange', - pygments.token.Name.Function.HTTP.PATCH: 'bold code-orange', - pygments.token.Name.Function.HTTP.DELETE: 'bold code-red', + pygments.token.Name.Function: 'bold grey', + pygments.token.Name.Function.HTTP.GET: 'bold green', + pygments.token.Name.Function.HTTP.HEAD: 'bold green', + pygments.token.Name.Function.HTTP.POST: 'bold yellow', + pygments.token.Name.Function.HTTP.PUT: 'bold orange', + pygments.token.Name.Function.HTTP.PATCH: 'bold orange', + pygments.token.Name.Function.HTTP.DELETE: 'bold red', # HTTP status codes - pygments.token.Number.HTTP.INFO: 'bold code-aqua', - pygments.token.Number.HTTP.OK: 'bold code-green', - pygments.token.Number.HTTP.REDIRECT: 'bold code-yellow', - pygments.token.Number.HTTP.CLIENT_ERR: 'bold code-orange', - pygments.token.Number.HTTP.SERVER_ERR: 'bold code-red', + pygments.token.Number.HTTP.INFO: 'bold aqua', + pygments.token.Number.HTTP.OK: 'bold green', + pygments.token.Number.HTTP.REDIRECT: 'bold yellow', + pygments.token.Number.HTTP.CLIENT_ERR: 'bold orange', + pygments.token.Number.HTTP.SERVER_ERR: 'bold red', } ) -PieLightBodyStyle, PieDarkBodyStyle = make_styles( +PieLightBodyStyle, PieUniversalBodyStyle, PieDarkBodyStyle = make_styles( 'Pie{mode}BodyStyle', { # {}[]: - pygments.token.Punctuation: 'code-gray', + pygments.token.Punctuation: 'grey', # Keys - pygments.token.Name.Tag: 'code-pink', + pygments.token.Name.Tag: 'pink', # Values - pygments.token.Literal.String: 'code-green', - pygments.token.Literal.String.Double: 'code-green', - pygments.token.Literal.Number: 'code-aqua', - pygments.token.Keyword: 'code-orange', + pygments.token.Literal.String: 'green', + pygments.token.Literal.String.Double: 'green', + pygments.token.Literal.Number: 'aqua', + pygments.token.Keyword: 'orange', # Other stuff - pygments.token.Text: 'code-primary', - pygments.token.Name.Attribute: 'code-primary', - pygments.token.Name.Builtin: 'code-blue', - pygments.token.Name.Builtin.Pseudo: 'code-blue', - pygments.token.Name.Class: 'code-blue', - pygments.token.Name.Constant: 'code-orange', - pygments.token.Name.Decorator: 'code-blue', - pygments.token.Name.Entity: 'code-orange', - pygments.token.Name.Exception: 'code-yellow', - pygments.token.Name.Function: 'code-blue', - pygments.token.Name.Variable: 'code-blue', - pygments.token.String: 'code-aqua', + pygments.token.Text: 'primary', + pygments.token.Name.Attribute: 'primary', + pygments.token.Name.Builtin: 'blue', + pygments.token.Name.Builtin.Pseudo: 'blue', + pygments.token.Name.Class: 'blue', + pygments.token.Name.Constant: 'orange', + pygments.token.Name.Decorator: 'blue', + pygments.token.Name.Entity: 'orange', + pygments.token.Name.Exception: 'yellow', + pygments.token.Name.Function: 'blue', + pygments.token.Name.Variable: 'blue', + pygments.token.String: 'aqua', pygments.token.String.Backtick: 'secondary', - pygments.token.String.Char: 'code-aqua', - pygments.token.String.Doc: 'code-aqua', - pygments.token.String.Escape: 'code-red', - pygments.token.String.Heredoc: 'code-aqua', - pygments.token.String.Regex: 'code-red', - pygments.token.Number: 'code-aqua', - pygments.token.Operator: 'code-primary', - pygments.token.Operator.Word: 'code-green', + pygments.token.String.Char: 'aqua', + pygments.token.String.Doc: 'aqua', + pygments.token.String.Escape: 'red', + pygments.token.String.Heredoc: 'aqua', + pygments.token.String.Regex: 'red', + pygments.token.Number: 'aqua', + pygments.token.Operator: 'primary', + pygments.token.Operator.Word: 'green', pygments.token.Comment: 'secondary', - pygments.token.Comment.Preproc: 'code-green', - pygments.token.Comment.Special: 'code-green', - pygments.token.Generic.Deleted: 'code-aqua', + pygments.token.Comment.Preproc: 'green', + pygments.token.Comment.Special: 'green', + pygments.token.Generic.Deleted: 'aqua', pygments.token.Generic.Emph: 'italic', - pygments.token.Generic.Error: 'code-red', - pygments.token.Generic.Heading: 'code-orange', - pygments.token.Generic.Inserted: 'code-green', + pygments.token.Generic.Error: 'red', + pygments.token.Generic.Heading: 'orange', + pygments.token.Generic.Inserted: 'green', pygments.token.Generic.Strong: 'bold', - pygments.token.Generic.Subheading: 'code-orange', - pygments.token.Token: 'code-primary', - pygments.token.Token.Other: 'code-orange', + pygments.token.Generic.Subheading: 'orange', + pygments.token.Token: 'primary', + pygments.token.Token.Other: 'orange', } ) PIE_STYLES = { 'pie': ( - PieDarkHeaderStyle, - PieDarkBodyStyle, + PieUniversalHeaderStyle, + PieUniversalBodyStyle, ), 'pie-light': ( PieLightHeaderStyle, diff --git a/httpie/output/ui/__init__.py b/httpie/output/ui/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/httpie/output/ui/palette.py b/httpie/output/ui/palette.py new file mode 100644 index 0000000000..4b01b4dfad --- /dev/null +++ b/httpie/output/ui/palette.py @@ -0,0 +1,138 @@ +# Copy the brand palette + +COLOR_PALETTE = { + 'transparent': 'transparent', + 'current': 'currentColor', + 'white': '#F5F5F0', + 'black': '#1C1818', + 'grey': { + '50': '#F5F5F0', + '100': '#EDEDEB', + '200': '#D1D1CF', + '300': '#B5B5B2', + '400': '#999999', + '500': '#7D7D7D', + '600': '#666663', + '700': '#4F4D4D', + '800': '#363636', + '900': '#1C1818', + 'DEFAULT': '#7D7D7D', + }, + 'aqua': { + '50': '#E8F0F5', + '100': '#D6E3ED', + '200': '#C4D9E5', + '300': '#B0CCDE', + '400': '#9EBFD6', + '500': '#8CB4CD', + '600': '#7A9EB5', + '700': '#698799', + '800': '#597082', + '900': '#455966', + 'DEFAULT': '#8CB4CD', + }, + 'purple': { + '50': '#F0E0FC', + '100': '#E3C7FA', + '200': '#D9ADF7', + '300': '#CC96F5', + '400': '#BF7DF2', + '500': '#B464F0', + '600': '#9E54D6', + '700': '#8745BA', + '800': '#70389E', + '900': '#5C2982', + 'DEFAULT': '#B464F0', + }, + 'orange': { + '50': '#FFEDDB', + '100': '#FFDEBF', + '200': '#FFCFA3', + '300': '#FFBF87', + '400': '#FFB06B', + '500': '#FFA24E', + '600': '#F2913D', + '700': '#E3822B', + '800': '#D6701C', + '900': '#C75E0A', + 'DEFAULT': '#FFA24E', + }, + 'red': { + '50': '#FFE0DE', + '100': '#FFC7C4', + '200': '#FFB0AB', + '300': '#FF968F', + '400': '#FF8075', + '500': '#FF665B', + '600': '#E34F45', + '700': '#C7382E', + '800': '#AD2117', + '900': '#910A00', + 'DEFAULT': '#FF665B', + }, + 'blue': { + '50': '#DBE3FA', + '100': '#BFCFF5', + '200': '#A1B8F2', + '300': '#85A3ED', + '400': '#698FEB', + '500': '#4B78E6', + '600': '#426BD1', + '700': '#3B5EBA', + '800': '#3354A6', + '900': '#2B478F', + 'DEFAULT': '#4B78E6', + }, + 'pink': { + '50': '#FFEBFF', + '100': '#FCDBFC', + '200': '#FCCCFC', + '300': '#FCBAFC', + '400': '#FAABFA', + '500': '#FA9BFA', + '600': '#DE85DE', + '700': '#C26EC2', + '800': '#A854A6', + '900': '#8C3D8A', + 'DEFAULT': '#FA9BFA', + }, + 'green': { + '50': '#E3F7E8', + '100': '#CCF2D6', + '200': '#B5EDC4', + '300': '#A1E8B0', + '400': '#8AE09E', + '500': '#73DC8C', + '600': '#63C27A', + '700': '#52AB66', + '800': '#429154', + '900': '#307842', + 'DEFAULT': '#73DC8C', + }, + 'yellow': { + '50': '#F7F7DB', + '100': '#F2F2BF', + '200': '#EDEDA6', + '300': '#E5E88A', + '400': '#E0E36E', + '500': '#DBDE52', + '600': '#CCCC3D', + '700': '#BABA29', + '800': '#ABA614', + '900': '#999400', + 'DEFAULT': '#DBDE52', + }, +} + +# Grey is the same no matter shade for the colors +COLOR_PALETTE['grey'] = { + shade: COLOR_PALETTE['grey']['500'] for shade in COLOR_PALETTE['grey'].keys() +} + +COLOR_PALETTE['primary'] = { + '700': COLOR_PALETTE['black'], + '600': 'ansibrightblack', + '500': COLOR_PALETTE['white'], +} + +COLOR_PALETTE['secondary'] = {'700': '#37523C', '600': '#6c6969', '500': '#6c6969'} From 65cf35a809bb0a4f1200899207db5cdc836d2530 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Fri, 17 Dec 2021 17:21:40 +0300 Subject: [PATCH 4/7] some docs --- docs/README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/README.md b/docs/README.md index 44b8acd81a..8d227f11da 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1717,15 +1717,16 @@ Syntax highlighting is applied to HTTP headers and bodies (where it makes sense) You can choose your preferred color scheme via the `--style` option if you don’t like the default one. There are dozens of styles available, here are just a few notable ones: -| Style | Description | -| --------: | ----------------------------------------------------------------------------------------------------------------------------------- | -| `auto` | Follows your terminal ANSI color styles. This is the default style used by HTTPie | -| `default` | Default styles of the underlying Pygments library. Not actually used by default by HTTPie. You can enable it with `--style=default` | -| `pie` | HTTPie's original brand style. Also used in the HTTPie for Web and Desktop. | -|`pie-light`| Like `pie`, but for terminals with light background colors. | -| `monokai` | A popular color scheme. Enable with `--style=monokai` | -| `fruity` | A bold, colorful scheme. Enable with `--style=fruity` | -| … | See `$ http --help` for all the possible `--style` values | +| Style | Description | +| ---------: | ------------------------------------------------------------------------------------------------------------------------------------ | +| `auto` | Follows your terminal ANSI color styles. This is the default style used by HTTPie | +| `default` | Default styles of the underlying Pygments library. Not actually used by default by HTTPie. You can enable it with `--style=default` | +| `pie-dark` | HTTPie's original brand style. Also used in the HTTPie for Web and Desktop. | +|`pie-light` | Like `pie`, but for terminals with light background colors. | +| `pie` | A general version of `pie-dark` and `pie-light` themes that can work with any terminal background | +| `monokai` | A popular color scheme. Enable with `--style=monokai` | +| `fruity` | A bold, colorful scheme. Enable with `--style=fruity` | +| … | See `$ http --help` for all the possible `--style` values | Use one of these options to control output processing: From 56bf02e78361a14ce61eaef0b7ba33994fbdfdcb Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Fri, 17 Dec 2021 17:23:51 +0300 Subject: [PATCH 5/7] some docs --- CHANGELOG.md | 2 +- docs/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 329bcf82ac..a5bea074d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). - Added support for _receiving_ multiple HTTP headers lines with the same name. ([#1207](https://github.com/httpie/httpie/issues/1207)) - Added support for basic JSON types on `--form`/`--multipart` when using JSON only operators (`:=`/`:=@`). ([#1212](https://github.com/httpie/httpie/issues/1212)) - Added support for automatically enabling `--stream` when `Content-Type` is `text/event-stream`. ([#376](https://github.com/httpie/httpie/issues/376)) -- Added new `pie` (and `pie-light`) styles that match with the [HTTPie for Web and Desktop](https://httpie.io/app). ([#1237](https://github.com/httpie/httpie/issues/1237)) +- Added new `pie-dark`/`pie-light` (and `pie`) styles that match with the [HTTPie for Web and Desktop](https://httpie.io/app). ([#1237](https://github.com/httpie/httpie/issues/1237)) - Broken plugins will no longer crash the whole application. ([#1204](https://github.com/httpie/httpie/issues/1204)) ## [2.6.0](https://github.com/httpie/httpie/compare/2.5.0...2.6.0) (2021-10-14) diff --git a/docs/README.md b/docs/README.md index 8d227f11da..c7573e8b65 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1722,7 +1722,7 @@ There are dozens of styles available, here are just a few notable ones: | `auto` | Follows your terminal ANSI color styles. This is the default style used by HTTPie | | `default` | Default styles of the underlying Pygments library. Not actually used by default by HTTPie. You can enable it with `--style=default` | | `pie-dark` | HTTPie's original brand style. Also used in the HTTPie for Web and Desktop. | -|`pie-light` | Like `pie`, but for terminals with light background colors. | +|`pie-light` | Like `pie-dark`, but for terminals with light background colors. | | `pie` | A general version of `pie-dark` and `pie-light` themes that can work with any terminal background | | `monokai` | A popular color scheme. Enable with `--style=monokai` | | `fruity` | A bold, colorful scheme. Enable with `--style=fruity` | From 6afcf210c67a6bb5b68d6b504d7d73ab1e44d227 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Fri, 17 Dec 2021 19:18:25 +0300 Subject: [PATCH 6/7] Rework on code generation --- httpie/output/formatters/colors.py | 226 +++++++++++++---------------- httpie/output/ui/palette.py | 22 +++ 2 files changed, 122 insertions(+), 126 deletions(-) diff --git a/httpie/output/formatters/colors.py b/httpie/output/formatters/colors.py index 3d6d82cd37..15040711da 100644 --- a/httpie/output/formatters/colors.py +++ b/httpie/output/formatters/colors.py @@ -16,7 +16,7 @@ from pygments.util import ClassNotFound from ..lexers.json import EnhancedJsonLexer -from ..ui.palette import COLOR_PALETTE +from ..ui.palette import COLOR_PALETTE, SHADE_NAMES, get_color from ...compat import is_windows from ...context import Environment from ...plugins import FormatterPlugin @@ -41,7 +41,6 @@ BUNDLED_STYLES = { SOLARIZED_STYLE, AUTO_STYLE, - *PIE_STYLES, } @@ -270,140 +269,115 @@ class Solarized256Style(pygments.style.Style): } -def format_style(raw_styles, shade): - def get_shade(part): - if part not in COLOR_PALETTE: - return part +PIE_HEADER_STYLE = { + # HTTP line / Headers / Etc. + pygments.token.Name.Namespace: 'bold primary', + pygments.token.Keyword.Reserved: 'bold grey', + pygments.token.Operator: 'bold grey', + pygments.token.Number: 'bold grey', + pygments.token.Name.Function.Magic: 'bold green', + pygments.token.Name.Exception: 'bold green', + pygments.token.Name.Attribute: 'blue', + pygments.token.String: 'primary', + + # HTTP Methods + pygments.token.Name.Function: 'bold grey', + pygments.token.Name.Function.HTTP.GET: 'bold green', + pygments.token.Name.Function.HTTP.HEAD: 'bold green', + pygments.token.Name.Function.HTTP.POST: 'bold yellow', + pygments.token.Name.Function.HTTP.PUT: 'bold orange', + pygments.token.Name.Function.HTTP.PATCH: 'bold orange', + pygments.token.Name.Function.HTTP.DELETE: 'bold red', + + # HTTP status codes + pygments.token.Number.HTTP.INFO: 'bold aqua', + pygments.token.Number.HTTP.OK: 'bold green', + pygments.token.Number.HTTP.REDIRECT: 'bold yellow', + pygments.token.Number.HTTP.CLIENT_ERR: 'bold orange', + pygments.token.Number.HTTP.SERVER_ERR: 'bold red', +} - color_code = COLOR_PALETTE[part] - if isinstance(color_code, dict) and shade in color_code: - return color_code[shade] - else: - return color_code +PIE_BODY_STYLE = { + # {}[]: + pygments.token.Punctuation: 'grey', + + # Keys + pygments.token.Name.Tag: 'pink', + + # Values + pygments.token.Literal.String: 'green', + pygments.token.Literal.String.Double: 'green', + pygments.token.Literal.Number: 'aqua', + pygments.token.Keyword: 'orange', + + # Other stuff + pygments.token.Text: 'primary', + pygments.token.Name.Attribute: 'primary', + pygments.token.Name.Builtin: 'blue', + pygments.token.Name.Builtin.Pseudo: 'blue', + pygments.token.Name.Class: 'blue', + pygments.token.Name.Constant: 'orange', + pygments.token.Name.Decorator: 'blue', + pygments.token.Name.Entity: 'orange', + pygments.token.Name.Exception: 'yellow', + pygments.token.Name.Function: 'blue', + pygments.token.Name.Variable: 'blue', + pygments.token.String: 'aqua', + pygments.token.String.Backtick: 'secondary', + pygments.token.String.Char: 'aqua', + pygments.token.String.Doc: 'aqua', + pygments.token.String.Escape: 'red', + pygments.token.String.Heredoc: 'aqua', + pygments.token.String.Regex: 'red', + pygments.token.Number: 'aqua', + pygments.token.Operator: 'primary', + pygments.token.Operator.Word: 'green', + pygments.token.Comment: 'secondary', + pygments.token.Comment.Preproc: 'green', + pygments.token.Comment.Special: 'green', + pygments.token.Generic.Deleted: 'aqua', + pygments.token.Generic.Emph: 'italic', + pygments.token.Generic.Error: 'red', + pygments.token.Generic.Heading: 'orange', + pygments.token.Generic.Inserted: 'green', + pygments.token.Generic.Strong: 'bold', + pygments.token.Generic.Subheading: 'orange', + pygments.token.Token: 'primary', + pygments.token.Token.Other: 'orange', +} + +def make_style(name, raw_styles, shade): def format_value(value): - return " ".join( - get_shade(part) + return ' '.join( + get_color(part, shade) or part for part in value.split() ) - return { - key: format_value(value) - for key, value in raw_styles.items() + bases = (pygments.style.Style,) + data = { + 'styles': { + key: format_value(value) + for key, value in raw_styles.items() + } } + return type(name, bases, data) -def make_styles(name, raw_styles): - for mode, shade in [ - ('light', '700'), - ('universal', '600'), - ('dark', '500') - ]: - yield type( - name.format(mode=mode.title()), - (pygments.style.Style,), - { - 'styles': format_style(raw_styles, shade) - } - ) +def make_styles(): + styles = {} + for shade, name in SHADE_NAMES.items(): + styles[name] = [ + make_style(name, style_map, shade) + for style_name, style_map in [ + (f'Pie{name}HeaderStyle', PIE_HEADER_STYLE), + (f'Pie{name}BodyStyle', PIE_BODY_STYLE), + ] + ] -PieLightHeaderStyle, PieUniversalHeaderStyle, PieDarkHeaderStyle = make_styles( - 'Pie{mode}HeaderStyle', - { - # HTTP line / Headers / Etc. - pygments.token.Name.Namespace: 'bold primary', - pygments.token.Keyword.Reserved: 'bold grey', - pygments.token.Operator: 'bold grey', - pygments.token.Number: 'bold grey', - pygments.token.Name.Function.Magic: 'bold green', - pygments.token.Name.Exception: 'bold green', - pygments.token.Name.Attribute: 'blue', - pygments.token.String: 'primary', - - # HTTP Methods - pygments.token.Name.Function: 'bold grey', - pygments.token.Name.Function.HTTP.GET: 'bold green', - pygments.token.Name.Function.HTTP.HEAD: 'bold green', - pygments.token.Name.Function.HTTP.POST: 'bold yellow', - pygments.token.Name.Function.HTTP.PUT: 'bold orange', - pygments.token.Name.Function.HTTP.PATCH: 'bold orange', - pygments.token.Name.Function.HTTP.DELETE: 'bold red', - - # HTTP status codes - pygments.token.Number.HTTP.INFO: 'bold aqua', - pygments.token.Number.HTTP.OK: 'bold green', - pygments.token.Number.HTTP.REDIRECT: 'bold yellow', - pygments.token.Number.HTTP.CLIENT_ERR: 'bold orange', - pygments.token.Number.HTTP.SERVER_ERR: 'bold red', - } -) - - -PieLightBodyStyle, PieUniversalBodyStyle, PieDarkBodyStyle = make_styles( - 'Pie{mode}BodyStyle', - { - # {}[]: - pygments.token.Punctuation: 'grey', - - # Keys - pygments.token.Name.Tag: 'pink', - - # Values - pygments.token.Literal.String: 'green', - pygments.token.Literal.String.Double: 'green', - pygments.token.Literal.Number: 'aqua', - pygments.token.Keyword: 'orange', - - # Other stuff - pygments.token.Text: 'primary', - pygments.token.Name.Attribute: 'primary', - pygments.token.Name.Builtin: 'blue', - pygments.token.Name.Builtin.Pseudo: 'blue', - pygments.token.Name.Class: 'blue', - pygments.token.Name.Constant: 'orange', - pygments.token.Name.Decorator: 'blue', - pygments.token.Name.Entity: 'orange', - pygments.token.Name.Exception: 'yellow', - pygments.token.Name.Function: 'blue', - pygments.token.Name.Variable: 'blue', - pygments.token.String: 'aqua', - pygments.token.String.Backtick: 'secondary', - pygments.token.String.Char: 'aqua', - pygments.token.String.Doc: 'aqua', - pygments.token.String.Escape: 'red', - pygments.token.String.Heredoc: 'aqua', - pygments.token.String.Regex: 'red', - pygments.token.Number: 'aqua', - pygments.token.Operator: 'primary', - pygments.token.Operator.Word: 'green', - pygments.token.Comment: 'secondary', - pygments.token.Comment.Preproc: 'green', - pygments.token.Comment.Special: 'green', - pygments.token.Generic.Deleted: 'aqua', - pygments.token.Generic.Emph: 'italic', - pygments.token.Generic.Error: 'red', - pygments.token.Generic.Heading: 'orange', - pygments.token.Generic.Inserted: 'green', - pygments.token.Generic.Strong: 'bold', - pygments.token.Generic.Subheading: 'orange', - pygments.token.Token: 'primary', - pygments.token.Token.Other: 'orange', - } -) + return styles -PIE_STYLES = { - 'pie': ( - PieUniversalHeaderStyle, - PieUniversalBodyStyle, - ), - 'pie-light': ( - PieLightHeaderStyle, - PieLightBodyStyle, - ), - 'pie-dark': ( - PieDarkHeaderStyle, - PieDarkBodyStyle, - ) -} +PIE_STYLES = make_styles() +BUNDLED_STYLES |= PIE_STYLES.keys() diff --git a/httpie/output/ui/palette.py b/httpie/output/ui/palette.py index 4b01b4dfad..2271541da4 100644 --- a/httpie/output/ui/palette.py +++ b/httpie/output/ui/palette.py @@ -1,4 +1,5 @@ # Copy the brand palette +from typing import Optional COLOR_PALETTE = { 'transparent': 'transparent', @@ -136,3 +137,24 @@ } COLOR_PALETTE['secondary'] = {'700': '#37523C', '600': '#6c6969', '500': '#6c6969'} + +SHADE_NAMES = { + '500': 'pie-dark', + '600': 'pie', + '700': 'pie-light' +} + +SHADES = [ + '50', + *map(str, range(100, 1000, 100)) +] + +def get_color(color: str, shade: str) -> Optional[str]: + if color not in COLOR_PALETTE: + return None + + color_code = COLOR_PALETTE[color] + if isinstance(color_code, dict) and shade in color_code: + return color_code[shade] + else: + return color_code From 2287a086b511564feb164209d72b2a81b85da820 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Fri, 17 Dec 2021 19:44:35 +0300 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Jakub Roztocil --- CHANGELOG.md | 2 +- docs/README.md | 4 ++-- httpie/output/formatters/colors.py | 13 +++---------- httpie/output/ui/palette.py | 1 + 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5bea074d2..eb8a917864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). - Added support for _receiving_ multiple HTTP headers lines with the same name. ([#1207](https://github.com/httpie/httpie/issues/1207)) - Added support for basic JSON types on `--form`/`--multipart` when using JSON only operators (`:=`/`:=@`). ([#1212](https://github.com/httpie/httpie/issues/1212)) - Added support for automatically enabling `--stream` when `Content-Type` is `text/event-stream`. ([#376](https://github.com/httpie/httpie/issues/376)) -- Added new `pie-dark`/`pie-light` (and `pie`) styles that match with the [HTTPie for Web and Desktop](https://httpie.io/app). ([#1237](https://github.com/httpie/httpie/issues/1237)) +- Added new `pie-dark`/`pie-light` (and `pie`) styles that match with [HTTPie for Web and Desktop](https://httpie.io/product). ([#1237](https://github.com/httpie/httpie/issues/1237)) - Broken plugins will no longer crash the whole application. ([#1204](https://github.com/httpie/httpie/issues/1204)) ## [2.6.0](https://github.com/httpie/httpie/compare/2.5.0...2.6.0) (2021-10-14) diff --git a/docs/README.md b/docs/README.md index c7573e8b65..9a81a72677 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1721,9 +1721,9 @@ There are dozens of styles available, here are just a few notable ones: | ---------: | ------------------------------------------------------------------------------------------------------------------------------------ | | `auto` | Follows your terminal ANSI color styles. This is the default style used by HTTPie | | `default` | Default styles of the underlying Pygments library. Not actually used by default by HTTPie. You can enable it with `--style=default` | -| `pie-dark` | HTTPie's original brand style. Also used in the HTTPie for Web and Desktop. | +| `pie-dark` | HTTPie’s original brand style. Also used in [HTTPie for Web and Desktop](https://httpie.io/product). | |`pie-light` | Like `pie-dark`, but for terminals with light background colors. | -| `pie` | A general version of `pie-dark` and `pie-light` themes that can work with any terminal background | +| `pie` | A generic version of `pie-dark` and `pie-light` themes that can work with any terminal background. Its universality requires compromises in terms of legibility, but it’s useful if you frequently switch your terminal between dark and light backgrounds. | | `monokai` | A popular color scheme. Enable with `--style=monokai` | | `fruity` | A bold, colorful scheme. Enable with `--style=fruity` | | … | See `$ http --help` for all the possible `--style` values | diff --git a/httpie/output/formatters/colors.py b/httpie/output/formatters/colors.py index 15040711da..757163f84b 100644 --- a/httpie/output/formatters/colors.py +++ b/httpie/output/formatters/colors.py @@ -16,7 +16,7 @@ from pygments.util import ClassNotFound from ..lexers.json import EnhancedJsonLexer -from ..ui.palette import COLOR_PALETTE, SHADE_NAMES, get_color +from ..ui.palette import SHADE_NAMES, get_color from ...compat import is_windows from ...context import Environment from ...plugins import FormatterPlugin @@ -24,14 +24,7 @@ AUTO_STYLE = 'auto' # Follows terminal ANSI color styles DEFAULT_STYLE = AUTO_STYLE - -# Bundled here -SOLARIZED_STYLE = 'solarized' -PIE_STYLES = { - 'pie', - 'pie-light', - 'pie-dark' -} +SOLARIZED_STYLE = 'solarized' # Bundled here if is_windows: # Colors on Windows via colorama don't look that @@ -40,7 +33,7 @@ BUNDLED_STYLES = { SOLARIZED_STYLE, - AUTO_STYLE, + AUTO_STYLE } diff --git a/httpie/output/ui/palette.py b/httpie/output/ui/palette.py index 2271541da4..a13aef058c 100644 --- a/httpie/output/ui/palette.py +++ b/httpie/output/ui/palette.py @@ -149,6 +149,7 @@ *map(str, range(100, 1000, 100)) ] + def get_color(color: str, shade: str) -> Optional[str]: if color not in COLOR_PALETTE: return None