Tag Archives: edit

shpaint: For the Toulouse-Lautrec of the terminal

Part of the fun in spending two and a half years sifting through random text-based software has been the occasional joy in finding something amazingly cool. On occasion I’ve stumbled over stuff I didn’t even think was possible, and yet there it is, in plain view.

2015-04-18-6m47421-shpaint

That’s Martin Bruchanov’s shpaint, which is a simple, mouse-driven ANSI art editor for terminal emulators. You can probably figure out how to use shpaint just by looking at that screenshot; click on a foreground color, a background color and a glyph, and click away until your artwork is complete.

It’s all the more impressive when you realize it’s written in bash. And to really blow your mind, Martin points out that it’s done in only 180 lines of bash. 😯

If I have 180 lines to work with, I’m lucky if I get “Hello, world” to appear on the screen. :\

shpaint isn’t perfect, but that doesn’t detract from its coolness. For one thing, it doesn’t work in a virtual console; I tried to fire up gpm and draw my rendition of the Mona Lisa (imagine a stick figure in garish colors), but apparently shpaint doesn’t work that way.

shpaint also can’t really do more than plot a glyph at a time. No line functions or paint-fill buckets. You have to do this old-school, like we used to do things back in the 80s.

Martin admits that occasionally something goes haywire between shpaint, bash and the terminal emulator, and clicking a cell will cause weird and random painting effects. That happened to me once or twice, but the fix is easy — just exit shpaint with CTRL+C, which saves your file automatically, then restart it and all is well.

shpaint sends your rendition of Whistler’s Mother to a flat file that will spill out the same image just with the cat command, meaning you can probably work this into other, more advanced editors to handle more intricate touchup. Don’t feel guilty doing that; our artist at work regularly sketches with a pencil, then scans her work into a computer and does everything else in Photoshop.

In fact, I’m no Picasso, but I daresay there are probably some parts of text-based artistry that would be well-served by relying on shpaint as an option to aewan, cavewall or duhdraw, even if it’s just for the speed of plotting points with the mouse, as opposed to cursor controls.

shpaint wins points from me just for being amazing and cool, but also for doing its job cleanly, obviously and without unnecessary bloat. I know this technically falls down on some of the points I like to see in text-based programs, but I think it deserves a star anyway: ⭐ Give it a try. πŸ˜‰

wiggle: A little room for wiggle

I have wiggle on my list for this morning, but I don’t know if I can show a very useful case for it.

2015-01-25-j3dmt61-wiggle

I understand from the program description that wiggle is designed to patch code where patch itself can’t, because of conflicting changes or some other error.

Personally I couldn’t come up with something so intricate to show what patch couldn’t do, but wiggle could. It’s another one of those situations where I’m trying to find a broken case for a program, so I can demonstrate another program. :\

Which isn’t very easy if you’re not one of the people who immediately sees the use of wiggle anyway. I’m guessing if you read through the description of wiggle and say to yourself, “Hmm, that could be useful to me. …” then you’re already way ahead of me.

So I’ll leave it at that. I should mention that wiggle is in Debian and AUR; both wiggle and wiggle-git stopped on warnings for me, so you might want to disable warnings that are treated as errors when you build it.

Of course, the Debian version runs fine. There’s the convenience of a precompiled distro. Then again, the Debian package page links to a dead home page, so there’s the convenience of AUR, too. … πŸ˜‰

duhdraw: For the Van Gogh of the vc

duhdraw, as I understand from the home page, has been around for almost 20 years in one form or another, and has its beginnings as an offshoot of a DOS program called TheDRAW. And so if you’re familiar with accents among native English speakers, you may better understand that name. πŸ˜‰

Having a near 20-year history may make it look weak when compared to tools like aewan or cavewall, or even cadubi, but duhdraw might still have a few tricks up its sleeve.

2014-11-07-2sjx281-duhdraw

That is not the world’s strongest screenshot, and for that I apologize. That was my passive-aggressive way of pointing out that duhdraw, regardless of your terminal dimensions, is going to confine itself to that small window.

Your canvas will actually stretch down to about 1000 lines, if the README file is to be believed, but width-wise, 80 appears to be its limit.

And the unreadable characters there in the screenshot are supposed to be “high ASCII” characters — pipe symbols and others, I believe — but were not properly rendered by my framebuffer …. or by rxvt-unicode, which was more disappointing. It may be a sign of its age, but apparently duhdraw had trouble reaching that high.

Most of duhdraw’s features are accessible through ALT keys, so the help screen, for example, is ALT+H. Erasing the canvas and starting over is ALT+E. Saving is ALT+S and loading is … well, you get the picture.

I found a copy-and-paste feature, such as was in cavewall or aewan, but it seemed quite primitive (or perhaps was incomplete) to me and hard to control. No transparent stamp effects or editable polygons, sorry.

duhdraw is not without its own interesting gimmicks though. ALT+D enters a line drawing mode, where just moving the cursor begins a continuous line you can control.

And I like the pickup commands of ALT+P and ALT+U, where you can instantly adopt the character and the color scheme of any character on the screen, and use it elsewhere. It’s quicker than running back and forth to the ALT+F keys for the color palette. And attribute mode is even easier, turning your cursor into a sopping wet paint roller, wherever you go on the screen.

And to be honest, trapping commands against the ALT keys is a good way to do business, since it frees up virtually every other key as a stamp, without losing out to shifted characters or special sequences. I like the way duhdraw does that.

It’s unfortunate that I couldn’t see all the characters duhdraw offered, because I have a feeling that duhdraw had more interesting approaches to ASCII art than just what the bigshots like aewan or cavewall could offer.

But duhdraw is not the do-all, be-all end of the line for ASCII art tools. In fact, if anything, it may be just the beginning, or as close as Linux users could get in 1996. 😎

aewan: For the Klimt of the console

I’ve seen about three or four ASCII art editors for the console now, and it’s becoming clear that each one has unique features that are very appealing, but misses out on something another one offers.

After I found cavewall, I figured any other ASCII art editor was going to fall flat. After all, cavewall had a slew of features that I hadn’t thought possible in text-art program, and didn’t expect to see again.

And along came aewan.

2014-11-06-2sjx281-aewan

The ASCII Editor Without A Name actually includes layer management, much like you’d see in GIMP or That Other Graphics Program which shall go unnamed and unlinked. The one that starts with “foto” and ends with “shoppe.”

If you’re skeptical, so was I, but aewan pulls it off quite gracefully. And those layers are the key to copy and pasting, moving blocks of images, creating stamp pad effects and even transparent stamping. It’s amazing.

You can add dozens of layers to text drawings, set their visibility, name them and rearrange them. Set their dimensions and move them around until you complete your masterpiece.

aewan has hotkeys for the color palette, a menu-driven interface with key commands for some of the most important features, and can save all your work into a file that (supposedly; I didn’t try it) can be used in a pager to display animation effects.

Wow. 😯 That’s impressive for a program that saw its last update in 2005. My hat is off. Again. For that alone, an incredibly rare and immeasurably valuable K.Mandla gold star is warranted: ⭐ Well done.

But … I can see where some features from cavewall don’t appear in aewan. cavewall has adjustable stepping features for example, making line drawing and the like more convenient. aewan doesn’t have that, or if it does, I don’t recall seeing it.

aewan does have a specific line-drawing mode though, and that’s quite handy. Pressing the hyphen or pipe symbol actually draws the appropriate extended line, so you can draw in continuous bars, instead of just the text character. But vertical lines aren’t as easy with aewan as they are with cavewall.

And neither aewan nor cavewall has the polygon drawing and editing features that were in textdraw. But that’s only black-and-white, and so loses an edge to cadubi, which behaved more like a colorized stamping program that could import images rendered by caca, and edit them.

So I’m at the point now where each of these has a particular feature that makes it shine, but misses out on something mastered by its brethren. Perhaps at some point a Grand Unifying Text-Based Art Tool will appear. And it shall be known as GUTBAT, and the people shall rejoice. … πŸ™„

cavewall: For the Kahlo of the console

I had to scrounge around the Internet for a while, before I could find the home page for cavewall. It was worth it:

2014-10-15-6m47421-cavewall

cavewall is another ASCII “image editor” allowing you to draw and create pictures using text symbols and so forth. We’ve seen a few of these in the past, to include classics like cadubi, or hidden gems like textdraw.

A lot of the files that are in the latest cavewall tarball date back to 2006 or even earlier. I didn’t expect it to compile, but as you can see, it worked more or less flawlessly.

For as hard as it was to find cavewall, it’s a huge step forward in ASCII drawing programs. It has, for example …

  • Block selection and range functions, which is a huge addition, because it adds things like …
    • Copy and paste functions
    • Fill functions
    • Paste from clipboard options
    • Custom box and frame creation, and more
  • Stepping modes, so pressing a character moves you in a specific direction — not just to the right
  • Menus for most program functions, plus hotkeys for the most common ones
  • Export to plain text or HTML
  • Import back from those formats

And a lot more. cavewall manages to take a lot of cadubi’s high points, and some of textdraw’s best functions, then add a few bonuses of its own, and combine them all in a very usable way.

It’s clear not everything is finished (I would have loved to see the “inject figlet-ized text” feature work), and it needs a little polishing on some points (the menus are sometimes obtrusive, or overwrite themselves, and cavewall intercepts some command sequences as text … small points). But the majority of it seems to be working.

Like I said, cavewall doesn’t appear to have seen attention in almost a decade. Very rarely do I wish for someone to adopt a program and bring it up to date (well, okay, sometimes I do), but cavewall is so very nearly perfect, that it’s sad to see it languish unnoticed in a corner of the Internet. 😦

I’m going to give cavewall a great big shiny gold K.Mandla star though, in the hopes that someone will see its potential and give it the boost it deserves: ⭐ πŸ˜‰ Enjoy!

csstidy: Tidy and neat

I like tidy tools. I like tools that take my mess of HTML and turn it into the stuff of legend. No doubt if I was a programmer I’d think a similar tool for perl was as cool as sliced bread. csstidy presses that same button, and makes me wish I had a reason to use it.

2014-10-08-6m47421-csstidy

As you can see there, csstidy lopped off the start of my ugly-as-sin HTML file, and sent me back a corrected, clean and spaced version, ready for editing or to be injected back into the file. It even went so far as to make some small improvements.

csstidy has a few options, which will reveal themselves to you if you invoke csstidy without a target. (Don’t try -h or --help.) Most of them are more than I would ever need to dress up my lowly web pages, but there might be something there that enthuses you.

Short of that, there’s not a lot for me to say about csstidy. I was scolded a long time ago for not coding like a girl, and I know I shouldn’t rely on tools like this if I ever want to be a rock-and-roll-web-page-designer, but hey … it works clean and neat for me. πŸ˜€

ngp: Find it and edit it, in one deft motion

These days I seem to be finding less and less tools that really grab me, and more and more that seem to fall short of the mark somehow. ngp is one of the former, and this one I think I shall keep around.

ngp is like a recursive, colorized, interactive grep. If you take the output of ack, make it navigable with a selection bar, then add the ability to jump straight into a selected file with your $EDITOR, you’ll have an idea of what ngp does.

So for example, this

 ngp -r ion

Takes me straight to this:

2014-10-03-6m47421-ngp

And from there, if I highlight a line and press enter, I jump into $EDITOR and can adjust as necessary. Leave the editor and ngp reclaims the terminal, showing the same results but with red text, so I know I already traveled there. Very smooth. 😎

ngp strikes me as a tool someone would invent where they see themselves repeating the same task over and over, and relying on two or three terminal windows to track their progress. And if you work in text files a lot, or through trees of code, I imagine ngp would save you some time finding certain problems, and fixing them.

ngp can be a little finicky, so watch your flags carefully. And I might have compared it to grep but it’s not feature-compatible, so don’t start throwing wild strings of flags at it and expecting it to munch them down the same way grep does.

But for a find-and-replace or find-and-edit or search-and-destroy at the console tool, ngp has everything tied up in one, nice, neat package. A well-earned, albeit completely valueless, K.Mandla gold star: ⭐ Enjoy! πŸ˜‰

rename: The built-in filename sifting tool

Sorry for the one-day break; Thursdays are always a little bit hectic for me, and this being the last in the month was especially busy.

The bulk of util-linux is splashed across the previous post, but I have a few left over that I want to point out. rename is one of those, and at its best, rename is a quick and speedy tool for bulk renaming files. Here’s what it does, on a good day:

2014-09-26-6m47421-rename-01

That’s a classy solution for bulk renaming where the same string needs to be substituted out in each file. rename makes it (more or less) a cinch to swap date strings, replace extensions or even make mass insertions and deletions to file names … with a little added command-line kung fu.

rename‘s shortcomings — and you knew I was going to point some out — occasionally crop up, though:

2014-09-26-6m47421-rename-02

If you look closely, you’ll see that the last file name had its prefix changed, but not the extension. rename caught the first instance of “text,” but quit before it found the other.

rename also has very little in the way of error-checking. Once you send the command, the deed is done … and short of reversing your previous command, there is no preview-and-commit. And you must be cautious that your substitution doesn’t allow for files to be moved onto one another.

And it should probably go without saying that, unless you are a regex grand master, some of the more complex or subtle renaming that is possible with something like renameutils is lost on rename. Which isn’t to say it can’t be done, only to say that your success will depend on your proficiency. πŸ˜•

rename works though, and in minor substitutions it’s a breeze. And given its simplicity and straightforward arrangement, I can’t say too many bad things about it. Keep it in mind the next time you dump a couple hundred pictures off your digital camera, and need a system to order them. … 😯

mkfifo: Pipe panjandrum

I’m going to guess that you probably know what a pipe symbol does on most Linux systems — passes the output of one program to a second. It’s what allows you to do things like this

dmesg | grep ATA

and find local hard drives. Or gives me my topics for the day, with

ls vimwiki/ | shuf -n1

mkfifo is part of coreutils, and allows you to name a pipe, and reuse it over and over. It might sound odd, but it works in much the same way as the symbol.

mkfifo pipe

Now I have a file entry called “pipe” in my directory, marked with a “p” in the leftmost column.

kmandla@6m47421: ~$ ls -lha
prw-r--r--  1 kmandla users    0 Sep 21 07:42 pipe

Now I can jam something in that pipe, if I like.

kmandla@6m47421: ~$ ls vimwiki/ > pipe

And … apparently, nothing happens. My terminal is paused, somehow waiting for an action. The suspense is killing me. πŸ™„

Actually, until something collects the material in that pipe, it will pause there more or less indefinitely. So if I …

kmandla@6m47421: ~$ grep ch < pipe

The whole flood comes out, and we can all relax again. Crisis averted. 😐

2014-09-21-6m47421-mkfifo

It might seem rather pointless or irrelevant to name a pipe or even to make note of mkfifo for it. But you’ve already seen the subtlety in action, and maybe just didn’t think about it.

That first terminal emulator was paused, waiting for someone to unblock the pipe. A second terminal received the data and did something with it.

So what? So … not only can you jam a program’s output into a holding area, waiting for a recipient, but that also means you can pass data between terminals with a named pipe. So if you’re waiting for one program to end, you can send the output of another into stasis, until it’s ready.

And you can pass information between different programs running in different terminals, at virtual consoles, in and out of a multiplexer … possibly even between users or across distant machines if you’re clever. It’s not the best way to do those things, but it might work in a pinch. Experiment and see.

I know named pipes are not anything new, but little things like this are the reason I wanted to sift through coreutils again. If you need a better explanation of named pipes, and you don’t mind reaching back almost 20 years, Andy Vaught’s explanation from issue #44 of Linux Journal is a great starting point. Nice to see that things haven’t changed that much since ’97. … πŸ˜‰

basename: What I had in mind

A while back, when I said I dumped coreutils back into The List because I thought there were still a few useful programs in there, I was thinking mostly of basename. So I’m kind of glad that shuf spat it out today.

I use basename a lot, although I can’t pin down any regular case that you might identify with. Here’s one that comes to mind though: Making sure the index page in my local wiki has all the programs included in the directory.

Occasionally I get sloppy and lose a title, or worse, have a file in the directory that doesn’t have a corresponding link in the index. That’s a problem because I can go months without knowing there’s an additional program in there.

I solve that by periodically dumping all the names of the files into an empty wiki page, and check links manually. vimwiki makes that fairly easy, since one press of the enter key will create a link, and the next will follow it. If the page is blank, it was a missing file, but if the file is there I can check that against my old list.

All this is terribly uninteresting. Let’s get to the good part. I use find to pluck out all the files from within /home/kmandla/vimwiki/ :

find . -type f

find naturally shows a preceding ./ for each file. I could fix that by adding -printf "%f\n" at the end, but vimwiki tacks .wiki on the end of each file, so I’d end up using basename anyway to get rid of that.

Ergo,

find . -type f -exec basename "{}" .wiki \;

In that case, basename trims off the leading path, and then the suffix .wiki from whatever it is given. The next step, which I won’t bother showing, is to dump all that into a separate file.

basename can cut off whatever you like from the end of a file, provided you predict it correctly. It’s a good way to trim file extensions, if you know what they are (if you don’t, you should be thinking about cut).

I have other uses for basename, and I can’t think of them right now. Perhaps in the future I’ll come back and add them on here, just for future reference. πŸ™‚