I’m currenly working on an ansible module for managing snap packages. Ansible allows modules to return information, such as stdout
of commands the module ran. I’d like to use this feature to provide users with snap
command output, for example when installing a package, and I’d prefer this output to be tidy.
Right now the output looks like this:
"stdout_lines": [
"",
"[|] Stop snap \"duckmarines\" services\u001b[K",
"[/] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
"[-] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
"[\\] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
"[|] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
"[/] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
"[-] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
"\u001b[Kduckmarines removed"
As you can see, a new line is appended each time the spinner changes, and the output is littered with escape sequences.
I’d like it to look more like this instead:
"stdout_lines": [
"",
"Stop snap \"duckmarines\" services",
"Remove security profile for snap \"duckmarines\"",
"Remove security profile for snap \"duckmarines\"",
"duckmarines removed"
I can of course filter it manually, but I think a “machine-friendly” output mode could be beneficial in a lot of other applications as well.