serokell / coffer

Multi-backend password store with multiple frontends
4 stars 2 forks source link

Reset ANSI control sequences after printing #48

Closed dcastro closed 2 years ago

dcastro commented 2 years ago

Clarification and motivation

The contents of a field may contain any and all unicode characters.

This means they can also include ANSI control sequences to, for example, turn the background red (\x1b[41;1m):

$ coffer create /dir/entry1 --field user="$(echo "\x1b[41;1mdiogo")"
$ coffer view /

image

This means that one field's control sequences can potentially affect the rest of coffer's output.

$ coffer create /dir/entry1 --field user="$(echo "\x1b[41;1mdiogo")"
$ coffer create /dir/entry2 --field user="leonid"                   
$ coffer view /    

image

To prevent this from happening, we should reset all ANSI control sequences (with \x1b[0m) after printing a field's contents.

We could use the ansi-terminal package to do this.

Because we're printing the field's contents in multiple different places, I think it would make sense to wrap the Text in a newtype, and write a Buildable instance that automatically appends the reset sequence.

Acceptance criteria