I am shamelessly posting a request for something I would actually find useful. The task is to take an arbitrary ascii box drawing like this
|
+----+----+
| state A +---+
+---------+ |
|
+----v----+
| state B |
+---------+
... and turn it into something more beautiful using unicode box drawing characters, e.g.
│
╭────┴────╮
│ state A ├───╮
╰─────────╯ │
│
╭────v────╮
│ state B │
╰─────────╯
In more detail:
- convert only + - | characters - other characters should be unchanged
use
- BOX DRAWINGS LIGHT VERTICAL (U+2502) │
- BOX DRAWINGS LIGHT HORIZONTAL (U+2500) ─
- BOX DRAWINGS LIGHT ARC DOWN AND RIGHT (U+256D) ╭
- BOX DRAWINGS LIGHT ARC DOWN AND LEFT (U+256E) ╮
- BOX DRAWINGS LIGHT ARC UP AND LEFT (U+256F) ╯
- BOX DRAWINGS LIGHT ARC UP AND RIGHT (U+2570) ╰
- BOX DRAWINGS LIGHT VERTICAL AND LEFT (U+2524) ┤
- BOX DRAWINGS LIGHT VERTICAL AND RIGHT (U+251C) ├
- BOX DRAWINGS LIGHT DOWN AND HORIZONTAL (U+252C) ┬
- BOX DRAWINGS LIGHT UP AND HORIZONTAL (U+2534) ┴
BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL (U+253C) ┼
- always replaced with U+2500
- | always replaced with U+2502
- + is replaced with a unicode character that depends on the 4 characters north, south, east and west of it (if they exist)
- < and > are treated as vertical wall segments if north or south of a + (so that you can have arrows terminating in vertical walls of a box)
- v and ^ are treated as horizontal wall segments if east or west of a + (so that you can have arrows terminating in horizontal walls of a box)
- + is treated as a wall segment if either north, south, east or west of a + (so that lines can connect next to a box corner)
Testcases
+-+ +---+ +---+ |
| +-- |ABC| -+ | +++
+-+ ++--+ +---+ +-+
|
+--->
| +--+
+-v+ +---+ | | +-----+
|Hi| -> | +^-+ |world<-----+
+--+ +---+ | +-----+ |
| +--
|
---+---
|
Becomes
╭─╮ ╭───╮ ╭───╮ │
│ ├── │ABC│ ─┤ │ ╭┴╮
╰─╯ ╰┬──╯ ╰───╯ ╰─╯
│
╰───>
│ ╭──╮
╭─v╮ ╭───╮ │ │ ╭─────╮
│Hi│ ─> │ ╰^─╯ │world<─────╮
╰──╯ ╰───╯ │ ╰─────╯ │
│ ╰──
│
───┼───
│
Shortest code wins!
+
has lines around it everywhere? \$\endgroup\$