Skip to content

Instantly share code, notes, and snippets.

@mjf
Created July 22, 2011 13:52
Show Gist options
  • Save mjf/1099492 to your computer and use it in GitHub Desktop.
Save mjf/1099492 to your computer and use it in GitHub Desktop.
Transform ASCII-art tables into XTerm-art tables
#! /bin/sed -f
# Transform ASCII-art tables into XTerm-art tables
# Copyright (C) 2011 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
# Horizontal and vertical line crossing
s/-|-/-^[(0^On^[(B-/g
# Top side and vertical line crossing
s/-\.-/-^[(0^Ow^[(B-/g
# Bottom side and vertical line crossing
s/-'-/-^[(0^Ov^[(B-/g
# Top left corner and right side crossing
s/\.|/^[(0^Olu^[(B/g
# Top right corner and left side crossing
s/|\./^[(0^Otk^[(B/g
# Bottom right corner and left side crossing
s/|'/^[(0^Otj^[(B/g
# Bottom left corner and right side crossing
s/'|/^[(0^Omu^[(B/g
# Left side and horizontal line crossing
s/|-/^[(0^Ot^[(B-/g
# Right side and horizontal line crossing
s/-|/-^[(0^Ou^[(B/g
# Top left corner
s/\.-/^[(0^Ol^[(B-/g
# Top right corner
s/-\./-^[(0^Ok^[(B/g
# Bottom right corner
s/-'/-^[(0^Oj^[(B/g
# Bottom left corner
s/'-/^[(0^Om^[(B-/g
# Horizontal line
s/-/^[(0^Oq^[(B/g
# Vertical line
s/|/^[(0^Ox^[(B/g
# Fill character
s/#/^[(0^Oa^[(B/g
# Circle
s/\*/^[(0^Of^[(B/g
@mjf
Copy link
Author

mjf commented Jul 22, 2011

Replace all ^O to Ctrl-V Ctrl-O and all ^[ to Control-V Escape. Then use as follows:

$ ascii2xterm < test.art

Example test.art:

  .--------------------------------.    .| |. '| |'
  |                                |
  |      .-----.-----.             |    * * * * * * * * *
  |      |     |     |------.      |
  |      |-----|-----|      |      |
  |      |     |     |      |      |
  |      '-----'-----'      |      |
  |                         '------'
  |                                           ###########
  '-----------------------------------------  ###########
                                              ###########
  #######################################################

AFAIK works in xterm(1) only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment