use isatty() before formatting -h text
Subject of the issue
step -h outputs terminal escape sequences even when standard output is not a TTY device. Programs like vi and less will visually display the formatting characters instead of formatting the text. Terminal escape sequences should be disabled if not outputting to a terminal. step should check isatty() before formatting output text.
Your environment
- OS - darwin/amd64
- Version - 0.15.3
Steps to reproduce
step -h | less
Expected behaviour
`step -h | less' does not display formatting characters.
Actual behaviour
step -h | less shows terminal escape sequence characters interleaved with help text.
Additional context
Why is the output of step certificate create -h 331 lines in length? Could help be cut down into a separate -h and --help?
With less, you can use step -h | less -R and it will be properly displayed, in fact some version of less do this automatically. Some other tools won't have this option.
Thanks!
On Fri, Jan 22, 2021 at 3:13 PM Mariano Cano [email protected] wrote:
With less, you can use step -h | less -R and it will be properly displayed, in fact some version of less do this automatically. Some other tools won't have this option.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/smallstep/cli/issues/408#issuecomment-765737468, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKJ2W4ZDIPDY6QGE5XX25TS3IBCJANCNFSM4WH6C56Q .
@amckinlay I've modified a script I found in Stack Overflow to do this:
#!/usr/bin/env python
import re
import sys
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
sys.stdout.write(ansi_escape.sub(b'', sys.stdin.read()))
$ step -h | ansi-escape
NAME
step -- plumbing for distributed systems
USAGE
step command [arguments]
OPTIONS
--help, -h
show help
--config=value
path to the config file to use for CLI flags
--version, -v
print the version
COMMANDS
help, h display help for the specified command or command group
version display the current version of the cli
base64 encodes and decodes using base64 representation
ca initialize and manage a certificate authority
certificate create, revoke, validate, bundle, and otherwise manage certificates
crypto useful cryptographic plumbing
oauth authorization and single sign-on using OAuth & OIDC
path print the configured step path and exit
ssh create and manage ssh certificates
ONLINE
This documentation is available online at https://smallstep.com/docs/cli
VERSION
Smallstep CLI/0.15.3 (darwin/amd64)
COPYRIGHT
(c) 2018-2020 Smallstep Labs, Inc.
FEEDBACK 😍 🍻
The step utility is not instrumented for usage statistics. It does not
phone home. But your feedback is extremely valuable. Any information you
can provide regarding how you’re using step helps. Please send us a
sentence or two, good or bad: [email protected] or ask in GitHub
Discussions.
Hello, I hit the same issue with Windows Server 2012 R2 cmd prompt and powershell terminal. It makes it difficult to impossible to generate certificates using any authentiction method. In addition, step-cli makes cmd/powershell terminal crash often).
It does not happen in cmd prompt from Windows 10 build 1909.
@ftoppi On windows we try to enable ENABLE_VIRTUAL_TERMINAL_INPUTand ENABLE_VIRTUAL_TERMINAL_PROCESSING according to https://docs.microsoft.com/en-us/windows/console/setconsolemode. If the commands fail we print something like Failed to set console mode: ..., can you see an error like that?
Can you try a couple of things for me:
- Does it happen if you change the character encoding to UTF-8 in your terminal?
- Does it happens with the new Windows Terminal https://github.com/microsoft/terminal
I want to change the input and markdown processors packages to something more portable, but I cannot tell you when this will happen.
@maraino in Windows 2012 R2, neither the flags nor changing encoding to UTF-8 (chcp 65001). I just reported it for awareness, the OS is "soon" out of extended support, I am not sure it's worth spending time on it.
Regarding Windows Terminal, it is not supported on Windows 2012 R2, so this settles that :-)
On Windows 10, cmd.exe is a bit funky but step cli works perfectly. Windows Terminal is completely fine as well.