6

DrawX 17/04/2022 -- ASCII and Unicode Art (etch-a-sketch style)

 2 years ago
source link: https://www.vim.org/scripts/script.php?script_id=5915%2317%2F04%2F2022
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ASCII and Unicode Art (etch-a-sketch style) : vim online

DrawX : ASCII and Unicode Art (etch-a-sketch style)

 script karma  Rating 10/6, Downloaded by 467  Comments, bugs, improvements  Vim wiki

created by Richard Bentley-Green   script type utility   description NOTE: Version 16/05/21 onwards changes the mapping for entering trace mode from '<leader>0' to '<leader>00'. This is unfortunate, but was necessary in order to accommodate some of the new paste operations

**GUI PASTE BUG** It has come to my attention that there seems to be a bug in some GUI vim versions that means that getregtype() does not return the correct value for the default clipboard register. I have seen this myself with nvim-qt on Windows but I have read reports of it on other GUI versions (not just nvim, but possibly limited to Windows). Anyway, this bug will cause <Leader>\0p (and P) mappings to refuse to work. A way around this seems to be to use another register (specify "<reg> for yank and paste), or you may find that using "0<Leader>0p (or P) works ok to paste the last yank to the default register. Or just use the terminal version of vim :-)

INTRODUCTION

DrawX makes ASCII-art drawing relatively easy. You can draw boxes and lines, and there is support for easily including special characters in your drawings. As well as supporting standard ASCII characters, it also supports a number of different line-drawing styles courtesy of the wider Unicode character set

There are two (actually quite separate) main drawing functions provided;-

1/ Box and ellipse drawing - This allows quick drawing of arbitrary-sized boxes and ellipses, optionally filled with blank space

2/ Tracing - This allows you to move the cursor around and trace a path as you go. Support is provided for joining lines, and placing special characters etc

There is also a flood-fill operation that allows you to fill any arbitrary shape with any character you like

There are also some special cut and paste operations that are better suited than the standard operations to dealing with ASCII art; they all operate in-place rather than performing any delete or insert operations. They also provide support for centre cut-out, upside-down and back-to-front pasting

There are several built-in drawing styles. You can also defined your own based on any character you like, so you can draw an ellipse with '@' characters if you want

NOTE: I really have no idea what the minimum vim version requirement is to run DrawX and I don't know of a practical way of finding out (I've only used it on v8.2). The best I can suggest is to try it; it will probably work and if it doesn't then let me know and I'll see if I can sort it

*** If you have any suggestions for improving this, then please let me know. If you think it's rubbish then PLEASE let me know why - it's far more useful than just 'voting it down' (which really doesn't help at all). Contact details are in the top of the README file ***

Here is a (rather uninspiring) example. I know it doesn't display very well because it needs a fixed-width font, but it's better than nothing and should give you an idea...

┌────────────┐       ╔════════════╗
    │Here's a Box     │       ║Here's a Box     ║
    └─────┬──────┘       ╚═════╤══════╝
                 │                                  │
                 ╰────────┬───────╯
                                    │
                   ╭╌╌╌╌╌╌╌┴╌╌╌╌╌╌╌╮
                   ╎And another Box     ╎
                   ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯

┏━━━━━┓
                ■┃◍   ◍┃■
                 ┃ ═══ ┃
                 ┗━━╦━━┛
             ┌──┳━━━╩━━━┳──┐
             │ ┌┨ ┏┅┅┅┓ ┠┐ │
             │ │┃ ┗┅┅┅┛ ┃│ │
             │ │┃ DrawX ┃│ │
             │ │┃       ┃│ │
             └─┘┃       ┃└─┘
                ┗┳━┳━┳━┳┛
                 ┃ ┃ ┃ ┃
                 ┃ ┃ ┃ ┃
                 ┃ ┃ ┃ ┃
                 ┗━┛ ┗━┛

Copy and paste upside-down and back-to-front....

┏┓
  ══════┃┃
════════┃┃══
┌────────────┐
│┌──┐    ┌──┐│
││  │┌─┐ │  ││
│└──┘│ │ └──┘│
└────┴─┴─────┘

┌─────┬─┬────┐
│┌──┐ │ │┌──┐│
││  │ └─┘│  ││
│└──┘    └──┘│
└────────────┘
══┃┃════════
   ┃┃══════
   ┗┛
(yea I know - that looks really rubbish!)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK