maaslalani / draw

Draw in your terminal
MIT License
466 stars 18 forks source link

Ability to draw on top of an "existing" terminal output #2

Open farzadmf opened 2 years ago

farzadmf commented 2 years ago

Describe the solution you'd like I think it would be nice to have the ability to draw on an existing output in the terminal.

An example use case:

Describe alternatives you've considered None

maaslalani commented 2 years ago

I think it would be really great if you could pass input to annotate over stdin so that way you can pipe to draw to start annotating output.

ls -lah | draw

One problem I can see though is that some programs will strip unicode characters when piped which means we'd lose color that way :(

caproven commented 2 years ago

Another potential factor is double-width (wide) characters. This may not be a concern for current user input, but wide chars could very well be piped into draw from other commands. Should there be handling for them?

Here's an example of using a wide char with the current version. I wrote out the text and then attempted to draw a single box around it: image

I bring this up because various CLIs have begun incorporating emojis in their output. Take for example the output of kind:

❯ kind create cluster
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.21.1) đŸ–ŧ
 ✓ Preparing nodes đŸ“Ļ
 ✓ Writing configuration 📜
 ✓ Starting control-plane 🕹ī¸
 ✓ Installing CNI 🔌
 ✓ Installing StorageClass 💾
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Thanks for using kind! 😊
maaslalani commented 2 years ago

Yes, there definitely should be handling for double-width characters: I think I have an idea on how to implement support but might be tricky.

Thinking out loud: my thinking is that we can reserve a special character to insert after (to the right of) any character that is > 2 character width in the grid and display that character as blank when View() is called. We can then ensure a box border doesn't lie on any of those special characters and if it does, move it to the right/left until it doesn't.