sithquote

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

sithquote

Unread post by DebianJoe » Mon Nov 11, 2013 12:59 pm

I got tired of seeing the infamous "Color Boxes" while playing with all these recent terminal color tools, so I made up a fun little tool for cycling through escape sequences.

Image

You can get it with git, wget, curl, or just copy and paste (just one little file).
https://raw.github.com/DebianJoe/sithqu ... ithquote.c

Usage is easy. Build it (no links, just "make sithquote" or "gcc sithquote.c -o sithquote", and put the binary wherever you want (in /usr/bin for global use, or a conveniently located directory somewhere in your PATH if you're Rho) to run it.

If you run it without arguments, it returns a quote from a Sith Lord from Star Wars.
If you want to feed it specific info, just run it with what you want in quotations afterwards:

Code: Select all

$ sithquote "Whatever artistic BS I feel like seeing quoted"
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: sithquote

Unread post by machinebacon » Mon Nov 11, 2013 1:27 pm

Pure fun! Thanks Sire!

Now people want to have a custom.quotes file that can be fed via -a option ;)
..gnutella..

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: sithquote

Unread post by dkeg » Mon Nov 11, 2013 1:33 pm

haha, that's cool man!
sith.png

Work hard; Complain less

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: sithquote

Unread post by DebianJoe » Mon Nov 11, 2013 1:39 pm

Sure, we can do a custom file reading. It's something I hacked out at breaks while I was at work. I'll put some more options in there just for fun when I get some time.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: sithquote

Unread post by rhowaldt » Mon Nov 11, 2013 3:40 pm

sure, now i wanna pipe the Tao and Apprentice Poetry through this thing ;)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: sithquote

Unread post by machinebacon » Mon Nov 11, 2013 3:49 pm

^ flashback moment ;)
..gnutella..

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: sithquote

Unread post by DebianJoe » Mon Nov 11, 2013 4:13 pm

Give me a day or so, I'll have it able to accept either pipes or have a file to be opened and read a random line from.

I guess I'll set pipes to be the default behavior and use quotes only if specified...but I'm keeping the Sith quotes in there. ;)
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: sithquote

Unread post by machinebacon » Mon Nov 11, 2013 4:29 pm

Somewhat related:

1) add quotes to /usr/local/share/quotes without a newline at the end

2) /usr/local/bin/sithquoter

Code: Select all

#!/bin/bash
FILE=/usr/local/share/quotes
head -$((${RANDOM} % `wc -l < $FILE` + 1)) $FILE | tail -1 | sed 's/.*/\"&\"/g' | xargs sithquote
..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: sithquote

Unread post by rhowaldt » Mon Nov 11, 2013 4:30 pm

^^ default quotes are important to have. plus, if you remove the Sith quotes, then you lose your app's title! can't be done.
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: sithquote

Unread post by DebianJoe » Mon Nov 11, 2013 5:12 pm

Since MB wrote such an elegant way to use whatever file you want to insert quotes....here's an easy way to make the same system take pipes. Make this your piped quote program.

Code: Select all

#include <stdio.h>
int main()
{
    int c, i = 0;
    c = getchar();
    while (c != EOF) {
        putchar(c);
	printf("\033[1;3%dm", i++);
        c = getchar();
	if(i == 8){i = 0;}
    }
    printf("\033[1;m\n");
    return 0;
}
Image

I don't see the point in rewriting everything to handle a different flow when this is such a short answer. (If you put it somewhere in yo' PATH, you don't need the ~/path/to/binary in the pipe...but I'm being lazy.)

Enjoy.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: sithquote

Unread post by rhowaldt » Tue Nov 12, 2013 8:59 am

hahaha, very nice! great little tool, i love this stuff :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: sithquote

Unread post by DebianJoe » Tue Nov 12, 2013 9:23 am

Okay, just because I can't just NOT do something, here's how the more recent version works.

Code: Select all

sithquote
^^Sets up a "free-flow" mode that will accept being piped into. If you run the program without a pipe, it goes into a passive typing mode, where every time you type something and hit "enter" it will colorize it. Ctrl^d will break the loop.

Code: Select all

sithquote -q
Generates pseudo-random sith quote

Code: Select all

sithquote -c "Whatever I feel like writing"
Allows user to specify a custom string to be processed.

Code: Select all

sithquote -a
Reads from a user-specified file and picks a pseudo-random LINE from the file to be processed. In the code, before you build it, there's a line with a bunch of comments all around it...almost at the very top. Change this line to give the full path to your customized file.

Edit: This was a hell of a lot of fun to program, because of all of the different directions that input could come from, and twin-iterating loops, and trying to handle some fake-randomness. I tried to make it reasonably fast by only allocating memory for whatever was being done.

# On my laptop #
time dmesg | sithquote
dmesg 0.01s user 0.00s system 70% cpu 0.011 total
./sithquote/sithquote 0.01s user 0.01s system 52% cpu 0.031 total
#

0.01 seconds to process dmesg...hell yes!
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: sithquote

Unread post by dkeg » Tue Nov 12, 2013 2:01 pm

love it joe! I was thinking if there is a way to pass different fonts to the output so has larger fonts for clearer distinction.

Work hard; Complain less

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: sithquote

Unread post by DebianJoe » Tue Nov 12, 2013 2:55 pm

Sure dkeg

Code: Select all

sithquote -q | figlet
....but seriously, I'm not preprocessing stdin at all for the pipes, which would mean setting the font for each character to make it work as you've asked. It would be possible with some major additions, but not really reasonable for how it is currently written. You could always change the bold to non-bold escapes under the processing function to be "\033[0;31m", "\033[0;3%dm", and "\033[0;m" respectively. This would probably make the font more readable....but I probably need to change the loop to avoid c0, because black on black tends to not show up in many themes.

Give me a few minutes, I can write you a patch to try it to see if you like it.

Edit: Try this out...looks a bit cleaner:

Code: Select all

22c22,23
<       int c, i = 0;                                                                       
---
>       int c;                                                                              
>       int i = 0;                                                                          
26c27
<           printf("\033[1;3%dm", i++);                                                     
---
>           printf("\033[0;3%dm", i++);                                                     
28c29
<           if(i == 8){i = 0;}                                                              
---
>           if(i == 8){i = 1;}                                                              
30c31
<     printf("\033[1;m\n");                                                                 
---
>     printf("\033[0;m\n");                                                                 
171c172
<       printf("\033[1;3%dm", i++);                                                         
---
>       printf("\033[0;3%dm", i++);                                                         
173c174
<           i = 0;                                                                          
---
>           i = 2;                                                                          
176c177
<     printf("\033[1;m\n");                                                                 
---
>     printf("\033[0;m\n");                                                                 

Copy the above to a file, call it "dkeg.patch" and use

Code: Select all

patch sithquote.c < dkeg.patch
Which will let you try it out if you want. If you don't like it, you could then just use a hard reset to the git repo.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: sithquote

Unread post by dkeg » Tue Nov 12, 2013 3:23 pm

No worries Joe, I was really just thinking aloud. I definitely don't want to push more work on you. I'm in a class today, but I'll check it out tonight. Again, no worries man, its good as it is, not meaning to seem like a douche : D

Work hard; Complain less

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: sithquote

Unread post by DebianJoe » Tue Nov 12, 2013 3:28 pm

No problem at all, I'm just having fun with this. The patch does seem to make the text more readable, so I may push it as an option with instructions for applying it. It's really dependent on how the original theme looks as to what is best, though. Let me know what you think when you get time.

Edit: pushed it, so you can get it via a git pull. Use whichever works better.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: sithquote

Unread post by dkeg » Sat Nov 16, 2013 3:16 pm

Hey Joe, morning, I cloned the latest and applied the patch. It all worked fine, I'm not seeing much of a difference though. My process was
first clean house, removed the original from /usr/bin
clone
apply patch
builid
copy to /usr/bin/

did I miss / mess something. It works great, just wasn't sure what diff I should see.

Work hard; Complain less

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: sithquote

Unread post by DebianJoe » Sat Nov 16, 2013 3:22 pm

It should have un-bolded the text, which on my system did make it more readable due to the font I use. That's really the only thing that the patch does.

I'll put some more thought into it later, and perhaps there's a better way to make it significantly more readable that won't force me into converting things into true strings. I'm up to my ears in projects right now, though, so it may be a bit.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: sithquote

Unread post by dkeg » Sat Nov 16, 2013 3:36 pm

okay, okay then yes it is much more readable. But now you say that I definitely can see the difference. Sorry, being an idiot this morning ....
It's my fault too, I have my terminal font set at mono 7 :D

Yeah, no worries Joe, like I said it is awesome the way it is.

Work hard; Complain less

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: sithquote

Unread post by DebianJoe » Sat Nov 16, 2013 3:43 pm

No worries at all. Thanks for playing with my toys. :D

I've got a few irons in the fire right now, and hopefully some of them will actually be useful. (Speaking of, if anyone who wants to try their hand at some hardcore C or Python...message me, I'll put you to work.) ;)
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

Post Reply