jbyuki / venn.nvim

Draw ASCII diagrams in Neovim
MIT License
982 stars 22 forks source link

potential ascii diagram design #27

Open matu3ba opened 1 year ago

matu3ba commented 1 year ago

Also briefly mentioned in https://github.com/anuvyklack/hydra.nvim/issues/94. Besides overlapping logic for 1, overwrites, 2. + on intersections and arrow logic I suspect the selection logic can probably (hydra has many bugs) be done within hydra.

The idea description, hopefully dense enough.

-- symbols (-,|,^,<,>,/,\)
local venn_hint_ascii   = [[
 - and | moves^^   Confirmation moves^^^^
 ^ ^ _K_ ^ ^ ^ ^   _<C-h>_: ◄, _<C-j>_: ▼
 _H_ ^ ^ _L_ ^ ^   ^     ^       ^   ^  ^
 ^ ^ _J_ ^ ^ ^ ^   _<C-k>_: ▲, _<C-l>_: ►
 ◄ + ▲ = \ ^ ^ ^   ◄ + ◄ / ► + ► = - / -
 ► + ▲ = / ^ ^ ^   ▲ + ▲ / ▼ + ▼ = | / |
 ◄ + ▼ = \ ^ ^ ^   other followup symbol
 ► + ▼ = / ^ ^ ^   + ◄▼▲► = <v^> and ▼ = nop
 _F_: surround^^   _f_: surround     ^^ ^
 + corners ^  ^^   overwritten corners
                              _<C-c>_
]]

Capital letters overwrite intersections via +, so going 1 up from

------
      ^<- cursor
      |

yields

------+<- cursor
      |
      |

and likewise the boxing with F. C-hjkl are to indicate a direction for overwriting with necessary repeated pressing. The idea is that hk can be pressed very fast, so there is marginal slowdown and things like >>>>>> can be pressed much faster via > and dot-repeat anyway except for ^, which I think is acceptable with C-v5kr^ stored within a macro taking the count from another register (to be provided).

TODOs

general improvements

matu3ba commented 1 year ago

Maybe this one is more elaborative:

  -- * ascii mode
  --   + hjkl <v^>
  --   + hj as ◄▼ /
  --   + kl as ▲► /
  --   + kh as ◄▲ \
  --   + jl as ▼► \
  --   + boxes as
  --     +-----+
  --     |     |
  --     |     |
  --     +-----+
matu3ba commented 1 year ago

I did my part:

      +---------------------------+
       \                         /  +---+
        \                       /   |   |
         \                     /    |   |
          \                   /     |   |
           \                 /      +---+
            \               /
             \             /        +---+    |\           /|
              \           /         |   |    | \         / |
               \         /          |   |    |  \       /  |
                \       /           |   |    |   \     /   |
                 \     /            |   |    |    \   /    |
                  \   /             |   |    |     \ /     |
                   \ /              |   |    |      +      |
                    +               +---+    ---------------
-- simplified ascii art with hydra
-- symbols (-,|,^,<,>,/,\)
-- capital letters => -| movements
-- C-letters => <v^>
-- leader right clockwise (time running): \/ including movements
-- leader left clockwise (enough time): \/ without movements
local venn_hint_ascii   = [[
 - and | moves^^   Confirmation select^^^
 ^ ^ _K_ ^ ^ ^ ^   _<C-h>_: <, _<C-j>_: v
 _H_ ^ ^ _L_ ^ ^   ^     ^       ^   ^  ^
 ^ ^ _J_ ^ ^ ^ ^   _<C-k>_: ^, _<C-l>_: >
 ◄ + ▲ = \ ^ ^ ^   ◄ + ◄ / ► + ► = <- / ->
 ► + ▲ = / ^ ^ ^   ▲ + ▲ / ▼ + ▼ = | / |
 ◄ + ▼ = \ ^ ^ ^   other followup symbol
 ► + ▼ = / ^ ^ ^   + ◄▲► = <^> and ▼ = nop
                              _<C-c>_
]]
-- _F_: surround^^   _f_: surround     ^^ ^
-- + corners ^  ^^   overwritten corners

M.ascii_hydra = Hydra {
  name = 'Draw Ascii Diagram',
  hint = venn_hint_ascii,
  config = {
    color = 'pink',
    invoke_on_body = true,
    hint = {
      border = 'rounded',
    },
    on_enter = function() vim.wo.virtualedit = 'all' end,
  },
  mode = 'n',
  body = '<leader>va',
  heads = {
    { '<C-h>', 'r<' },
    { '<C-j>', 'rv' },
    { '<C-k>', 'r^' },
    { '<C-l>', 'r>' },
    { 'H', 'r-h' },
    { 'J', 'r|j' },
    { 'K', 'r|k' },
    { 'L', 'r-l' },
    { '<leader>hj', 'r/hj' },
    { '<leader>jh', 'r/' },
    { '<leader>hk', 'r\\hk' },
    { '<leader>kh', 'r\\' },
    { '<leader>lj', 'r\\jl' },
    { '<leader>jl', 'r\\' },
    { '<leader>kl', 'r/kl' },
    { '<leader>lk', 'r/' },
    { '<leader>n', 'r+' },
    { '<leader>h', 'r-hr<' },
    { '<leader>j', 'r|jrv' },
    { '<leader>k', 'r|kr^' },
    { '<leader>l', 'r-lr>' },
    { '<C-c>', nil, { exit = true } },
  },
}

If you give me some brief pointers, then I can implement myself.

matu3ba commented 1 year ago

Not sure if the left+right turn thing to distinguish /\ with and without movement is intuitive or another binding is better.

matu3ba commented 1 year ago

I guess this one has nicer hints, but I really hate that hydra does automatically include the bindings at the bottom line, if not specified in the hint.

-- simplified ascii art with hydra
-- symbols (-,|,^,<,>,/,\)
-- capital letters => -| movements
-- C-letters => <v^>
-- leader right clockwise (time running): \/ including movements
-- leader left clockwise (enough time): \/ without movements
local venn_hint_ascii   = [[
 -| moves: _H_ _J_ _K_ _L_
 <v^> arrow: _<C-h>_ _<C-j>_ _<C-k>_ _<C-l>_
 diagnoal + move: leader + clockwise like ◄ ▲
 _<leader>jh_ _<leader>hk_ _<leader>lj_ _<leader>kl_
 diagnoal + nomove: anticlockwise like ▲ + ◄
 _<leader>hj_ _<leader>kh_ _<leader>jl_ _<leader>lk_
 set +: _<leader>n_
 rectangle move + arrow, ie ► with ->
 _<leader>h_ _<leader>j_ _<leader>k_ _<leader>l_
                              _<C-c>_
]]
-- _F_: surround^^   _f_: surround     ^^ ^
-- + corners ^  ^^   overwritten corners

M.ascii_hydra = Hydra {
  name = 'Draw Ascii Diagram',
  hint = venn_hint_ascii,
  config = {
    color = 'pink',
    invoke_on_body = true,
    hint = {
      border = 'rounded',
    },
    on_enter = function() vim.wo.virtualedit = 'all' end,
  },
  mode = 'n',
  body = '<leader>va',
  heads = {
    { '<C-h>', 'r<' },
    { '<C-j>', 'rv' },
    { '<C-k>', 'r^' },
    { '<C-l>', 'r>' },
    { 'H', 'r-h' },
    { 'J', 'r|j' },
    { 'K', 'r|k' },
    { 'L', 'r-l' },
    { '<leader>jh', 'r/hj' },
    { '<leader>hj', 'r/' },
    { '<leader>hk', 'r\\hk' },
    { '<leader>kh', 'r\\' },
    { '<leader>lj', 'r\\jl' },
    { '<leader>jl', 'r\\' },
    { '<leader>kl', 'r/kl' },
    { '<leader>lk', 'r/' },
    { '<leader>n', 'r+' },
    { '<leader>h', 'r-hr<' },
    { '<leader>j', 'r|jrv' },
    { '<leader>k', 'r|kr^' },
    { '<leader>l', 'r-lr>' },

    { '<C-c>', nil, { exit = true } },
  },
}
jbyuki commented 1 year ago

If you give me some brief pointers, then I can implement myself.

In hydra or in venn? Or as a new wiki in this project page?

matu3ba commented 1 year ago

In hydra or in venn? Or as a new wiki in this project page?

in venn, for example in this issue.

jbyuki commented 1 year ago

I've sent you a write access request. This should allow to edit the wiki page freely and go for it. A link in the readme to this wiki would be nice once something is there.

jbyuki commented 1 year ago

Or I can pin the issue if you prefer. And link it in the readme.

matu3ba commented 1 year ago

Or I can pin the issue if you prefer. And link it in the readme.

pinning issue sounds better until a more final solution exists.