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.67k stars 3.68k forks source link

Trim trailing empty lines from CLI output #1547

Open olatoft opened 6 months ago

olatoft commented 6 months ago

Checklist


Enhancement request

The output from the CLI seems to always include 2 trailing empty lines. Could they be removed?

Example command: $ https google.com

Current output:

HTTP/1.1 301 Moved Permanently
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control: private, max-age=2592000
Content-Length: 220
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-qWBSXxuQK80KB3NcDHBMJw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Content-Type: text/html; charset=UTF-8
Date: Thu, 21 Dec 2023 11:01:33 GMT
Expires: Thu, 21 Dec 2023 11:01:33 GMT
Location: https://www.google.com/
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
Set-Cookie: CONSENT=PENDING+017; expires=Sat, 20-Dec-2025 11:01:33 GMT; path=/; domain=.google.com; Secure
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 0

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

The output I would like:

HTTP/1.1 301 Moved Permanently
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control: private, max-age=2592000
Content-Length: 220
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-qWBSXxuQK80KB3NcDHBMJw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Content-Type: text/html; charset=UTF-8
Date: Thu, 21 Dec 2023 11:01:33 GMT
Expires: Thu, 21 Dec 2023 11:01:33 GMT
Location: https://www.google.com/
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
Set-Cookie: CONSENT=PENDING+017; expires=Sat, 20-Dec-2025 11:01:33 GMT; path=/; domain=.google.com; Secure
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 0

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

So exactly the same, and still with an empty line for padding between sections like headers and body, but without the 2 trailing empty lines.


Problem it solves

Would give a shorter output. This means there would be a shorter distance to scroll up to some output, and in some cases there would be no need to scroll at all, since more actual output could fit in the window.


Additional information, screenshots, or code examples

Version: 3.2.1 OS: Ubuntu 23.10

vivekthedev commented 5 months ago

https://github.com/httpie/cli/blob/9e8e3691c8d40ca8dcdc90fbd9be12016eacdd56/httpie/output/writer.py#L22-L26

These lines append two newlines at the end of the output. I also thinks that it should append only a single newline.