💾 Archived View for bbs.geminispace.org › u › oldernow › 13076 captured on 2023-12-28 at 15:54:52. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Thin and to the point

                ----------------------
                |  my wife awoke me  |
                |    in wee hours    |
                |     to fix my      |
                |        limp        |
                |                    |
                | slept 'til 8:46am  |
                |    not a record    |
                |    but up there    |
                |                    |
                |    not a ton of    |
                |   usenet action    |
                |    but it'll do    |
                |                    |
                | tonight we're out  |
                |  celebrating with  |
                |  a birthday girl   |
                |                    |
                |  whipped out the   |
                |    small guitar    |
                |     yesterday      |
                |                    |
                |  my wife doesn't   |
                |      like it       |
                |   and I'll admit   |
                |   it's sound is    |
                |      smaller       |
                |                    |
                |    but i can eq    |
                |    around that     |
                |   and it's just    |
                |     such a joy     |
                |   of simplicity    |
                |      to play       |
                |                    |
                |  i'm feeling the   |
                |     slight tug     |
                |  of the 3x5 cards  |
                |       again        |
                |                    |
                |  a way they were   |
                |  my earliest days  |
                |     of posting     |
                |                    |
                |   jot, scribble    |
                |   insert shapes    |
                |       shade        |
                |                    |
                |       text++       |
                |                    |
                |        and         |
                |     of course      |
                |   not by way of    |
                | commands or clicks |
                |  conducting code   |
                |    and hardware    |
                |     to perform     |
                |     equivalent     |
                |      lifting       |
                ----------------------

☯️ oldernow

23 hours ago · 👍 stack

7 Comments ↓

🚀 stack · 23 hours ago:

OK, I have to ask if you manually formatted that!

☯️ oldernow · 22 hours ago:

@stack The process:

1) type text manually in vim

2) :<first-line-number>,<last-line-number>!center

3) :<first-line-number>,<last-line-number>!box

4) :<first-line-number>,<last-line-number>s/^/ /

where 'center' is a script to center text, and 'box' is a script to create the box around text. (4) is to pad the text on the left so it doesn't look quite so "up against the left".

(And of course one surrounds the text in the good 'ole triple backticks....)

🚀 Minko_Ikana · 22 hours ago:

Where is the outrage about this pornography being published in the library? Tone it back down to a limp will ya? lol

~ Sacasm :)

🚀 stack · 21 hours ago:

Cool. Would you consider sharing your scripts? They seem pretty useful.

☯️ oldernow · 20 hours ago:

@stack Here be the Lua scripts. You'll see they're not well documented, but read from stdin and write to stdout, making the perfect to run against lines in a vim session a la:

NOTE: The source code below contains tab characters.

center

Looks like "center" takes a couple optional arguments related to some kind of additional padding.

Let's say you start with this on lines 1 through 4 in a vim session:

this
is a test
to see
what happens

running ":1,4!center" leads to:

    this
 is a test
   to see
what happens

running ":1,4!center @" leads to:

@@@@this@@@@
@is a test@@
@@@to see@@@
what happens

(see how it used argument one as a padding character?)

running ":1,4!center @ x" leads to:

@@@@this
@is a test
@@@to see
what happens

So apparently the second argument (which can be anything) leads to the padding occurring only at the front of lines.

"center" source

#! /usr/bin/env lua
local pad = ' '
if arg[1] then
	pad = arg[1]
end
t = {}
max = 0
for line in io.stdin:lines() do
	line = string.gsub(line, '^%s*', '')
	line = string.gsub(line, '%s*


, '')
	table.insert(t, line)
	if #line > max then max = #line end
end
for i,line in ipairs(t) do
	if #line > 0 then
		for j=1, (max-#line)/2, 1 do
			io.stdout:write(pad)
		end
		if arg[1] then
			io.stdout:write(line)
			if not arg[2] then
				for j=1, (max-#line)/2, 1 do
					io.stdout:write(pad)
				end
				if (max-#line)%2 > 0 then
					io.stdout:write(pad)
				end
			end
			print()
		else
			print(line)
		end
	else
		print(line)
	end
end

box

Starting with this in lines 1 through 4 of a vim session:

    this
 is a test
   to see
what happens

running ":1,4!box" leads to:

================
|     this     |
|  is a test   |
|    to see    |
| what happens |
================

running ":1,4!box x" (i.e. with optional argument that means 'use - instead of = for the top/bottom lines') leads to:

----------------
|     this     |
|  is a test   |
|    to see    |
| what happens |
----------------

Looks like it also uses an optional TAB environment variable for some reason (sorry...), but will also recognize the presence of a "-c" flag, directing it to center text within the box... which I *think* obviates the "center script".

So starting with this in lines 1 through 4 of a vim session:

this
is a test
to see
what happens

running ":1,4!box" leads to:

================
| this         |
| is a test    |
| to see       |
| what happens |
================

running ":1,4!box -c" leads to:

================
|     this     |
|  is a test   |
|    to see    |
| what happens |
================

Yeah, I know... flakey... not documented for sh*t, etc. But I tend to forget what I've written before, generally don't have patience to refactor for reuse, etc.

In other words, I'm no @skyjake. :-)

Good luck!

box source

#! /usr/bin/env lua
local tab = os.getenv('TAB')
if tab then
	if tonumber(tab) then
		tab = string.rep(' ', tonumber(tab))
	end
end
local center = false
for i,v in ipairs(arg) do
	if v == '-c' then
		center = true
		table.remove(arg, i)
	end
end
local lines = {}
local max = 0
for line in io.stdin:lines() do
	if tab then
		line = string.gsub(line, '\t', tab)
	end
	local len = string.len(line)
	if len > max then
		max = len
	end
	table.insert(lines, line)
end
local c = '='
if arg[1] then
	c = '-'
end
print(string.rep(c, max+4))
if center then
	for i,line in ipairs(lines) do
		local front = math.floor((max - string.len(line)) / 2)
		local back = max - string.len(line) - front
		print('| ' .. string.rep(' ', front) .. line .. string.rep(' ', back) .. ' |')
	end
else
	for i,line in ipairs(lines) do
		print('| ' .. line .. string.rep(' ', max - string.len(line)) .. ' |')
	end
end
print(string.rep(c, max+4))

🚀 stack · 19 hours ago:

@oldernow: many thanks. I can't believe there are no simple linux utils to do that! FreeBSD has fmt -c, but it does not work in linux to center...

vim does have a %center command...

There is a linux utility called 'boxes', should be in most repos. It comes with simple ones, and a bunch of ridiculous ASCII-art boxes too...

☯️ oldernow · 17 hours ago:

@stack Oh wow, didn't know about vim's "center", although needing to specify a width or go with an ugly default seems a bit more work than my script, which bases the centering on length of the longest line in a set. But I could easily be not completely understanding vim's "center"