Sublime Forum

BoxDrawing -- Draw Lines and Boxes in Sublime Text

#1

In my daily work, I was finding I was going back to my old (no longer supported) programmer’s editor in order to do one last thing: draw reStructuredText tables because it had a feature that made this easy.

The BoxDrawing Package makes it even easier, with better behavior, and supports both ASCII and several Unicode character sets.

Demo: Drawing an ASCII Table

Some more examples:

┌─┬┐  ╔═╦╗  ╓─╥╖  ╒═╤╕    +------------+----------------+
│ ││  ║ ║║  ║ ║║  │ ││    | Column One | Column Two     |
├─┼┤  ╠═╬╣  ╟─╫╢  ╞═╪╡    +============+================+
└─┴┘  ╚═╩╝  ╙─╨╜  ╘═╧╛    |            |                |
╭───────────────────╮     +------------+----------------+
│  ╔═══╗ Some Text  │     |            |                |
│  ╚═╦═╝ in the box │░    +------------+----------------+
╞═╤══╩══╤═══════════╡░    |            |                |
│ ├──┬──┤           │░    +------------+----------------+
│ └──┴──┘           │░    |            |                |
╰───────────────────╯░    +------------+----------------+
  ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░

Features

  • Draw using intuitive key combinations with arrow keys.
  • Arrow-key bindings are temporary, while Box Drawing is turned ON. You turn it OFF again when you are done.
  • Intuitively overwrites characters where directed as if always in “overwrite” mode.
  • There is no need to add spaces to short lines. The package extends short lines with spaces automatically when needed, enabling you to conveniently draw wherever you direct it.
  • Initially uses ASCII or one of the Unicode box-drawing character sets, depending on a user-configurable setting. (See below.)
  • Conveniently switch between character sets with one keystroke.
  • Box drawing with the ASCII character set is compatible with the requirements of reStructuredText tables. (The ASCII table above is an example.)
  • The current state of the BoxDrawing Package can be seen:
    • Tools > BoxDrawing > sub-menu items, and
    • in the status bar for 4 seconds after each state change.
  • Supports these character sets:
    • ASCII
    • Unicode [Square Corners]
    • Unicode [Round Corners]
    • Unicode [2 Dashes]
    • Unicode [3 Dashes]
    • Unicode [4 Dashes]
    • Shadow Characters

Usage

  1. In any type of document, ensure there is just 1 selection (caret) and that no text is selected.

  2. Turn Box-Drawing ON using Alt-Keypad / or Tools > BoxDrawing > Enabled or from the Command Palette BoxDrawing: Toggle ON/OFF. (A temporary Status-Bar message “Box Drawing ON/OFF (<char_set>)” shows which mode the current View is in.) The Tools > BoxDrawing > Enabled menu item always shows the ON/OFF state for the current View by showing a checkmark () next to that menu item when Box Drawing is enabled.

  3. Draw using single lines using the arrow keys while the Alt key is held down.

  4. Draw using double lines using the arrow keys while the Alt-Shift keys are held down.

  5. Erase using the arrow keys while the Alt-Shift-Ctrl keys are held down.

  6. Change current character set using Alt-Keypad * or Tools > BoxDrawing > Change Character Set (char_set) or from the Command Palette BoxDrawing: Change Character Set. (A temporary Status-Bar message “Box Drawing ON/OFF: (char_set)” shows which character set is now current.) The Tools > BoxDrawing > Change Character Set (char_set) menu item always shows the current character set in parentheses.

  7. When you are done drawing, turn Box-Drawing OFF again with Alt-Keypad / or Tools > BoxDrawing > Enabled or from the Command Palette BoxDrawing: Toggle ON/OFF.

Key Bindings

This Package provides the following customizable key bindings:

Key Combination Meaning
Alt-Keypad / Turn Box Drawing ON or OFF
Alt-Keypad * Switch character sets (ASCII <==> Unicode)
Alt-(Left|Right|Up|Down) Draw with single lines[^1]
Alt-Shift-(Left|Right|Up|Down) Draw with double lines[^1]
Ctrl-Alt-Shift-(Left|Right|Up|Down) Erase[^1]

[^1]: when BoxDrawing is ON

When Box-Drawing is ON for a particular View, the Package temporarily overrides the normal key bindings for the arrow-key combinations for that View only. When Box Drawing is turned OFF again, normal key bindings for the arrow keys are resumed. Alt-Keypad / and Alt-Keypad * both remain bound to the ON/OFF and switch character sets Commands full time.

1 Like

#2

Hi @vwheeler63. This looks like a really cool plugin. I wonder whether you have met prettytable · PyPI which can automate these types of box, table decorations, column alignments etc, with a range of pre-built visual templates and apis.

I use the Formatter plugin to pipe my ST selected regions (or whole doc) out to prettytable. Formatter is really handy swiss-army knife as your can also pipe out to code beautifiers, minifiers, converters etc.

2 Likes

#3

Sweet! I’ll have a look!

Edit: Impressive!!

0 Likes

#4

Hi, @gbird!

I was looking at this this morning and noticed that it appears to have had about 110 installs per week up until the end of February and then it just dropped off to 3-10 per week, with more uninstalls than installs. It follows the pattern of a catastrophic update that broke it or something. Do you have any information about it?

Kind regards,
Vic

0 Likes

#5

No idea, sorry. It ‘just works’ for me. I discovered it after installing Formatter, a great Swiss-army-knife for beautifying, minifying and transforming content. It supports lots of plugins, of which PrettyTable is just one.

For me, PrettyTable fits within an ecosystem that I have for MD based authoring, and I have bootstrapped this into my own plugins to (for instance) convert a csv string into MD tables.

I’ll be honest, I have since refined this workflow, removing this dependancy in favour of my own native parser, so I don’t use it as much these days.

EDIT: I see now that you are raising concerns about Formatter, not PrettyTable. for me, Formatter has been rock solid and I use it regularly to fire off Prettier etc. It takes a fair high level of configuration to get it going, which might be enough for some to say ‘too hard’ and uninstall it. What’s its going though it ‘just works’ and I like the fact that I can really dial in my per-plugin settings.

0 Likes

#6

Good to know. Thank you.

0 Likes