jbyuki / venn.nvim

Draw ASCII diagrams in Neovim
MIT License
919 stars 20 forks source link

diagonal lines, inserting up and down arrow and other possible extensions #13

Closed matu3ba closed 1 year ago

matu3ba commented 2 years ago

example why this is cool

Only providing diagonal lines and have a way to insert up and down arrow should be sufficient for most cases.

However having the optional + in several cases could also simplify drawing.

The ultra interface would be of course a curve plotting from a selection via commands and interpolation of results, but thats quite some complexity.

jbyuki commented 2 years ago

That's cool indeed. There are some impressive ascii art in there.

One difference with them is that venn.nvim is using the special box-drawing characters instead of standard ASCII. I guess if you prefer this style DrawIt or one of its fork could be an option.

I see now that they are also diagonal characters , , . We could integrate them in venn.nvim somehow. I'm currently not sure how the drawing process would look like.

Plots would be cool indeed. I think it would have to be a separate plugin though.

JonathanLorimer commented 2 years ago

It would also be nice to be able to use a dashed ascii line instead of just a solid one.

matu3ba commented 2 years ago

I see now that they are also diagonal characters ╱, ╲, ╳. We could integrate them in venn.nvim somehow. I'm currently not sure how the drawing process would look like.

There are typically 2 modes for lines in inkscape: 1. accurate and 2. interpolated

As I understand it, the main implementation problem for both approaches is to get useful information for the console/terminal font to decide, if the non-accurate line interpolates

1.
  x
 /  
x
2.
x
|
x
3.
x
 \
  x

One needs to figure out the prescaling factor of the terminal font to know the diagonal offset (in this case / and \ need 2 character's right- and leftwards, but this might become arbitrary complex with utf8 symbol width.

Not sure, if the character width can be queried in a simple way from utf8. Otherwise offering an "ascii mode" with "ascii character detection" would be most failure-safe. The ascii check could be written in C, ie ported from my code: https://github.com/matu3ba/chepa

jbyuki commented 2 years ago

It would also be nice to be able to use a dashed ascii line instead of just a solid one.

This is a good idea and might be a recurring request. I have added two functions set_line and set_arrow to customize the style of lines and arrow for each direction. We might have a style parameter in the future.

For example to get the standard ascii style, you would set:

require"venn".set_line({ "s", "s" , " ", " " }, '|')
require"venn".set_line({ " ", "s" , " ", "s" }, '+')
require"venn".set_line({ "s", " " , " ", "s" }, '+')
require"venn".set_line({ " ", "s" , "s", " " }, '+')
require"venn".set_line({ "s", " " , "s", " " }, '+')
require"venn".set_line({ " ", "s" , "s", "s" }, '+')
require"venn".set_line({ "s", " " , "s", "s" }, '+')
require"venn".set_line({ "s", "s" , " ", "s" }, '+')
require"venn".set_line({ "s", "s" , "s", " " }, '+')
require"venn".set_line({ " ", " " , "s", "s" }, '-')
require"venn".set_arrow("up", '^')
require"venn".set_arrow("down", 'v')
require"venn".set_arrow("left", '<')
require"venn".set_arrow("right", '>')

Not sure, if the character width can be queried in a simple way from utf8.

The box-drawing characters are actually already multi-byte character so I needed to compute the width. There is one function in neovim, I don't recall the name anymore to get the displayed width of any string.

The main issue was more about how to keep a logical user interface for vim while allowing the drawing of diagonal characters. Draw a rectangle in Visual + VBox, to draw a rectangle. Draw a rectangle of width/height 1 to draw an arrow. I'm not sure where to fit diagonal lines.

rodhash commented 1 month ago

It would also be nice to be able to use a dashed ascii line instead of just a solid one.

This is a good idea and might be a recurring request. I have added two functions set_line and set_arrow to customize the style of lines and arrow for each direction. We might have a style parameter in the future.

For example to get the standard ascii style, you would set:

require"venn".set_line({ "s", "s" , " ", " " }, '|')
require"venn".set_line({ " ", "s" , " ", "s" }, '+')
require"venn".set_line({ "s", " " , " ", "s" }, '+')
require"venn".set_line({ " ", "s" , "s", " " }, '+')
require"venn".set_line({ "s", " " , "s", " " }, '+')
require"venn".set_line({ " ", "s" , "s", "s" }, '+')
require"venn".set_line({ "s", " " , "s", "s" }, '+')
require"venn".set_line({ "s", "s" , " ", "s" }, '+')
require"venn".set_line({ "s", "s" , "s", " " }, '+')
require"venn".set_line({ " ", " " , "s", "s" }, '-')
require"venn".set_arrow("up", '^')
require"venn".set_arrow("down", 'v')
require"venn".set_arrow("left", '<')
require"venn".set_arrow("right", '>')

Not sure, if the character width can be queried in a simple way from utf8.

The box-drawing characters are actually already multi-byte character so I needed to compute the width. There is one function in neovim, I don't recall the name anymore to get the displayed width of any string.

The main issue was more about how to keep a logical user interface for vim while allowing the drawing of diagonal characters. Draw a rectangle in Visual + VBox, to draw a rectangle. Draw a rectangle of width/height 1 to draw an arrow. I'm not sure where to fit diagonal lines.

Thanks,

It seems it works for the future lines drawn, it doesn't seem to change the existing lines .. is this expected? Any way to forcefully change all lines?

jbyuki commented 1 month ago

Thanks, It seems it works for the future lines drawn, it doesn't seem to change the existing lines .. is this expected? Any way to forcefully change all lines?

Yes this is expected. It should be viewed as a configuration that is put in the init.lua/init.vim for any future drawings. If you want to replace existing drawings, that's a completely different topic.