• Boxed Output

    From porkchop@porkchop@invalid.foo (Mike Sanders) to comp.lang.awk on Mon Nov 6 22:09:28 2023
    From Newsgroup: comp.lang.awk

    Nifty little script...

    #!/bin/sh
    #
    # tags: box, sh, shell, awk, code
    #
    # box - awk shell script encases
    # output within a formatted box
    # Michael Sanders 2023
    # https://busybox.neocities.org/notes/box.txt
    #
    # example...
    #
    # +---------------+
    # | 3 menu items |
    # | |
    # | . coffee |
    # | . tea |
    # | . iced water |
    # +---------------+

    awk '

    {
    lines[NR] = $0
    current = length($0)
    if (current > max) max = current
    }

    END { box(lines, NR, max) }

    function box(ary, num, width, count) {
    horizontal(width)
    while(++count <= num) vertical(width, ary[count])
    horizontal(width)
    }

    function vertical(width, line) { printf "| %-" width "s |\n", line }

    function horizontal(width, x, line) {
    line = "+"
    for (x = 0; x < width + 2; x++) line = line "-"
    print line "+"
    }

    ' <<'DATA'
    _
    / \ _-'
    _/| \-''- _ /
    __-' { | \
    / \
    / "o. |o }
    | \ ;
    ',
    \_ __\
    ''-_ \.//
    / '-____'
    /
    _'
    _-'
    DATA

    # eof
    --
    :wq
    Mike Sanders

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.awk on Tue Nov 7 14:21:18 2023
    From Newsgroup: comp.lang.awk

    On 06.11.2023 23:09, Mike Sanders wrote:
    Nifty little script...
    [...]
    ' <<'DATA'
    _
    / \ _-'
    _/| \-''- _ /
    __-' { | \
    / \
    / "o. |o }
    | \ ;
    ',
    \_ __\
    ''-_ \.//
    / '-____'
    /
    _'
    _-'
    DATA

    Nice sample data. :-)

    Janis

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From porkchop@porkchop@invalid.foo (Mike Sanders) to comp.lang.awk on Tue Nov 7 18:44:02 2023
    From Newsgroup: comp.lang.awk

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    Nice sample data. :-)

    A friend created that ASCII Art, I'll pass along
    the compliment. =)
    --
    :wq
    Mike Sanders

    --- Synchronet 3.20a-Linux NewsLink 1.114