raystack/salt

[salt/printer] Spinner does not allow customising writer

Opened this issue · 0 comments

spy16 commented

Is your feature request related to a problem? Please describe.

The printer.Spin() function assumes writer is STDOUT and does not allow overriding it. Showing spinner in STDOUT can cause issues when the program also writes other useful data (may be structured) to STDOUT.

# This type of usage will be common but with spinner on STDOUT, it may end up writing some
# residual characters used for the spinner rendering into the file also.
$ myprogram-using-spinner dosomework > foo.json

Describe the solution you'd like

Usually, it's better to use STDERR in for logs, progress updates, etc. or at-least if the writer itself is configurable, the client program can override the writer to implement any behaviour (no-op, write-to-stderr, write-to-stdout, etc.)

Note: The printer package seem to be assuming STDOUT for almost everything. Also, formatting functions encode into byte slice and then print. Instead, all these can be refactored to accept writer and stream-encode (e.g., json.NewEncoder(writer).Encode(v) )