text2xpm in shell

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#16 Post by technosaurus »

01micko wrote:Ok, so I put this to actual use

Note the feature request.
that was exactly the kind of thing I had in mind when I wrote this. Things like partview, battview, tempview... Then I found out how to do the same thing in svg much easier, but it is still good for xcb/X11+xpm only apps I guess.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#17 Post by 01micko »

Another one,

cpuicon

There's a difference, no thread topic, this is just a link to the source code and support files including a build script.

You could say I'm going a bit mad on tray icons! But I find them more useful than widgets or conky as I actually use them! They don't look fantastic but they are functional.

techno, care to share the svg knowledge?
Puppy Linux Blog - contact me for access

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#18 Post by technosaurus »

Try playing with this:
(save as <something>.svg and open with viewnior)

Code: Select all

<svg>
  <rect width="100"
     height="50"
     x="0"
     y="0"
     style="font-size:12;fill:#0000ff;fill-opacity:0.75;fill-rule:evenodd;stroke-width:3pt;"
     id="rect1" />
  <rect
     width="50"
     height="50"
     x="0"
     y="0"
     style="font-size:12;fill:#ff00ff;fill-opacity:0.75;fill-rule:evenodd;stroke-width:3pt;"
     id="rect2" />
  <text
     x="0"
     y="50"
     style="font-size:12;font-weight:normal;fill-opacity:0.75;stroke-width:3pt;font-family:helvetica;"
     id="text1">
    <tspan
       id="tspan1">test</tspan>
  </text>
</svg>
you can add as many rectangles as you want, or you can save some svgS from inklite (uncompressed) for other shapes etc... (crap, now Iremember where I posted this before - it was in the project management / planner thread ... covered lines too)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#19 Post by jpeps »

01micko wrote:Another one,

cpuicon
You could also eliminate a folder with 100 xpms, etc, with a small tray icon that just toggles cpu-usage on and off in a small window when you need it.
Attachments
cpu.png
(47.85 KiB) Downloaded 539 times

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#20 Post by technosaurus »

this just requires echo and variables to generate svg

Code: Select all

echo '<svg>
	<rect width="100" height="50" x="0" y="0" id="rect1" style="font-size:12;fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke-width:3pt;"/>
	<rect width="50" height="50" x="0" y="0" id="rect2" style="font-size:12;fill:#ff00ff;fill-opacity:0.75;fill-rule:evenodd;stroke-width:3pt;"/>
	<ellipse cx="24" cy="24" rx="24" ry="24" style="font-size:12;fill:#ff0000;fill-opacity:0.75;fill-rule:evenodd;stroke-width:3pt;"/>
	<ellipse cx="74" cy="24" rx="24" ry="24" style="font-size:12;fill:#00ff00;fill-opacity:0.75;fill-rule:evenodd;stroke-width:3pt;"/>
	<text x="12" y="25" id="text1" style="font-size:12;font-weight:normal;fill-opacity:0.75;stroke-width:3pt;font-family:helvetica;">test</text>
	<path d="M 50 25 L 100.0 25.0 " style="font-size:12;fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;"/>
</svg>' >$FILE
simply edit the fixed parameters in place and then just replace the rest with single quoted variables. ex.

... width="50" .... becomes ... width="'${WIDTH}'" ...
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#21 Post by jpeps »

cpu-usage with Eterm

wrapper (toggle from tray):

Code: Select all

#/bin/sh

var="$(pidof cpu)"

if [ "$var" ]; then 
  kill -9  "$var"
else
Eterm --trans --no-cursor --buttonBar no --scrollBar no -x -f WHITE -g 10x2+890+682 -e cpu &
fi
Attachments
cpu.png
(29.7 KiB) Downloaded 510 times

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#22 Post by greengeek »

Interesting. Will have to find a use for this.
I tried putting a "!" in my string but it was rejected:

Code: Select all

# ./text2xpm "Very clever Techno !" >/tmp/tmp.xpm 
bash: !": event not found
#
Had to leave out the !

ps: Is there any way to get a line wrap so that I can have two or more lines displayed in the xpm?

cheers!
Attachments
Screenshot.png
(12 KiB) Downloaded 241 times

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#23 Post by technosaurus »

I'll have to check the quotes in all the subfunctions... I just reworked the glyphs for vertically oriented text ... still not implemented, but here are the strings for them ... our forum still hasn't figured out {overflow:scroll} so it won't be readable until cut/pasted.

As for extra lines, I'll probably convert it to functions, so that each arg is a separate line, then a wrapper can split the arguments by something like:
(oh yeah, this forum also adds spaces to each line, so delete the space that it adds to IFS)

Code: Select all

IFS="
"
wrapper $Text

Copy/paste to editor to read

Code: Select all

"                                                                                                                                                                                                                                                                                                                                                                                                       #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 " 
"                ######              #    ###     #   ##   ####           #     #   #####         ####    ##            ##   ###     #######       ########     #   ##      ##    ##      ######     #        #   #             ##  #####   ##########   #        #   #            #       ##            #   ##########   ##########    ########     ####         ########  #  ####   ##    ##   ###    #            #########    ####         #########    ##      ##   ###          ##       #       ######       #####        #   #    ##########       ### #     #              #      #      ######            #   ## ########           #            #       ######       ######       #####        #####       #########     ##           #   #            #       #######      ###          ######       ##   ##      ########     #     #   ##                         ####### #      #  #        ##  ###    ##     ##     #                ##  #  #           #                         #      #            #          #  #       #       #        #                                ##             ##                                                             #           #             #           #                        ##             "
"               #      #             #   #   ##   #   # # #    #   ##########   #  #     #   #   #    #   # ##         #  # #   #   #   #   #     #   #        # # #  #    #        #    #      #    #        #   #            #    #  #        #        #        #   #########     #     #              #    ##                ##     #        #   #    #       #       ###  #    # #     #    #   #   #                     #       ###               #     ##  ##        ##        # #      #      #  #  #      #     #      #     #       #   #       #  #  #   #   #            ###  # #    #                  #      #       #    #    #             #      #            #            #     #      #     #       #   #       #            #   # #      #     #           #          ##              #        # #            #   #    ##    #     #                       # #    # #   ##########    #   #   #     #   #  #   #             ###   ##    #         #     #####                #      #            #          #  #        #     #        # #                            #    ##          #  #                                      #    #   ####         #           #      #      #           ##############         ##               "
"              #        #   ##########   #     #  #   #  ##    #    #     #     #  #     #   #   #    #   #   ##       #   #    #   #    #   #   #    #       #   #    #   #        #   #        #   #   #    #   #   #        #    #   #       #        ##########   #        #     #   #               #      ##             #       #        #   #    #       #      # #   #    ##      #    #   #   ##########            #          ###         ###        ##            #####   #  ##    #      #  #  #      #     #      #     #      #     #      #  #  #   #   #           #   # # #    #         ## #######              #     #  #     ##########       #####       #            #     #      #     #      #     #      #            #  #  #      #     #            #           ##        ####          #              #  #    # #   #    #           ####### ##   # #    # #      #  #      ###########   #### #  #  #             #   # # #     ##     ##    ##     ##              #   #######         #          #  #         #   #        #   #             ###          ###     ###       #   ### ##      ##  ###  ####            ###  ###                ##### #####  ##### ##### #           ##           #       ##    #############"
"              #        #    #       #   #      # #   #   #    #     ##   #     #  #     #   #   #    #   #     ##     #   #    #   #    #   #   #    #       #   #    #   #        #   #        #   #   #    #   #   #        #        #       #        #        #            #      # #                #      ##            #        #        #   #    #       #     #  #   #    #       #   #    #   #                     #          ###            #       ##          ##        #    #   #      #  #  #      #     #      #     #      #     #      #  #  #    #########      #   # # #    #            #     #              #      ##      #        #      #            #            #     #      #     #      #     #      #            #  #  #   #########             #         ##              #         #              #  #    #  ## #   #                         #  ####  #   ##########    #   #   #   #  # ####   #             #   ##   #      #####     #         #             #      #            #          #  #          # #        #     #            #  #          #         ##     #               ##  #  #                  #    #   ####               #      #           ###############           #    ###                   "
"               #      #      #      #   #       ##   #        #       ## #     #  #     #    #   #   #   #       ##   #  # #   #   #    #   #    #   #       #   #    #   #        #   #        #   #   #    #   #   #        #        #       #        #        #            #       #                 #    ##            ##         #        #   #    #       #     #  #   #    #       #   #    #   #                     #       ###      #########      ##  ##     ###          #     ## #      #  #  #       #   #       #     #      #     #      #  #  #       #           #   ##  #     #                 #            ##        #               #      #######       #           #     #       #   #       #     #       #           # #   #      #                  #      ###          ######         # #             #  #    #    ##  #                           #      #       #  #       #  #    #   #  #   #     #             ### #   #               #           #            #      #            #          #  #           #        #       #                                     ##   #                                                                            #           #             #           #  ##                      "
"                ######                   ##      #   #      ##          ##     #####  ##      #######    #             ##   ###     ####  ##      ########   ##########    ########    ##########   ##########   ##########    ########    ##########                       ##    ##########   ##########   ##########   ##########    ########    ##########    ########    ##########    ###   ##    #            #########    ####                      ##      ##                #       ##       #  ##    ##########       #####        #####        #####        #            ###  ##  ##########                             ##########                                #######       #####       #########     #####       #######       #   #       #            ######                                 ##   ##      #####  #     #     #   ##                          ######                    ##   ##     ##     ##    #                 ###                                         #                              #  #                                                                    ##  ##                                                                                                                 ##                        "
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

very good post.

#24 Post by mister_electronico »

I had no knowledge of this post, The script that converts the text string on points with so few lines of code is so clever. and conversion to xpm image not just to understand it at all is great.


Technosaurus can you let me copy you code, to I try to improve my make_dots script?

Very good post..... thanks.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#25 Post by greengeek »

technosaurus wrote: I just reworked the glyphs for vertically oriented text ... still not implemented, but here are the strings for them
I tried grafting them in (hoping for a miracle despite the fact you said it's not implemented yet :-) ) and notice that the dots are missing (replaced by spaces instead?). Is that as expected?

Ash tells me:

Code: Select all

# ./text2xpm "your text here" >/tmp/tmp.xpm
ash: bad number
#
Attachments
txt2xpm_vert.jpg
(113.88 KiB) Downloaded 198 times

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#26 Post by technosaurus »

greengeek wrote:
technosaurus wrote: I just reworked the glyphs for vertically oriented text ... still not implemented, but here are the strings for them
I tried grafting them in (hoping for a miracle despite the fact you said it's not implemented yet :-) ) and notice that the dots are missing (replaced by spaces instead?). Is that as expected?
It was supposed to be dots, I just converted it to 1s and 0s and screwed up when I switched it back... though the spaces are more readable.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
solo
Posts: 389
Joined: Thu 14 Nov 2013, 20:33

#27 Post by solo »

So..

If you would have an extra set of 10 characters that would mimic graph states, like for instance a zero readout would only be dots, and a 1 value would be a row of 6 fills on row 11 (or K) only, and a 2 value would be a row of 6 fills on row 11 plus a row of 6 fills on row 10 (J), and so on and so on, would you then also have a tool for displaying graphs, be it very elementary?!

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#28 Post by technosaurus »

At one point I combined this with my xpm percentbar generator... I can only seem to find the standalone percent bar function though (in bashbox), so I will just post it here for now.
I also reworked partview to use it here.

Code: Select all

percentbar() { #usage: "$0" XX% name=filename fgcolor=XXX bgcolor=XXX height=XXX width=XXX [vertical]
FILENAME=barimage
FGCOLOR=\#000
BGCOLOR=None
PERCENT=50
WIDTH=100
HEIGHT=24
BARSTRING=""
q=0 #should have used for loops
y=0 #not while loops - oops
#get values from input
for x in $@; do
case $x in
   width*)WIDTH=`echo $x |cut -d = -f 2`;;
   height*)HEIGHT=`echo $x |cut -d = -f 2`;;
   fg*)FGCOLOR=`echo $x |cut -d = -f 2`
      [ "$FGCOLOR" != "None" ] && FGCOLOR=\#$FGCOLOR;;
   bg*)BGCOLOR=`echo $x |cut -d = -f 2`
      [ "$BGCOLOR" != "None" ] && BGCOLOR=\#$BGCOLOR;;
   name*)FILENAME=`echo $x |cut -d = -f 2`;;
   *%)PERCENT=`echo $x |cut -d % -f 1`;;
   vert*)VERTICAL="true";;
   *)   echo "usage "$0" XX% name=filename fgcolor=XXX bgcolor=XXX height=XXX width=XXX [vertical]
      colors can be 3 or 6 digit hexadecimal or None ... default is horizontal bars" && exit
      ;;
esac
done


#write header to file
echo '/* XPM */' >${FILENAME}.xpm
echo 'static char *'$FILENAME'_xpm[] = {' >>${FILENAME}.xpm
echo '"'$WIDTH $HEIGHT '2 1",' >>${FILENAME}.xpm
echo '"0 c '$BGCOLOR'",' >>${FILENAME}.xpm
echo '"1 c '$FGCOLOR'",' >>${FILENAME}.xpm

if [ "$VERTICAL" == "true" ];then #vertical bars
BARTOP=$(($HEIGHT*$PERCENT/100))
#generate each line of the image
   while [ "$q" -lt $HEIGHT ]; do
   q=$(($q + 1))
      if [ "$q" -lt $BARTOP ];then
         while [ "$z" -lt $WIDTH ]; do
            BARSTRING=${BARSTRING}0
            z=$(($z + 1))
         done
      else
         while [ "$z" -lt $WIDTH ]; do
            BARSTRING=${BARSTRING}1
            z=$(($z + 1))
         done
      fi
   echo '"'$BARSTRING'"' >>${FILENAME}.xpm
   BARSTRING=""
   z=0
   done
else #horizontal bars
#generate one line of the image
   BARMAX=$(($WIDTH*$PERCENT/100))
   while [ "$q" -lt $BARMAX ]; do
      q=$(($q + 1))
      BARSTRING=${BARSTRING}1
   done
   while [ "$q" -le $WIDTH ]; do
      BARSTRING=${BARSTRING}0
      q=$(($q + 1))
   done
#write a line for each pixel of height
   while [ "$y" -le $HEIGHT ]; do
   echo '"'$BARSTRING'"' >>${FILENAME}.xpm
      y=$(($y + 1))
   done
fi

echo '};' >>${FILENAME}.xpm
}
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

Re: very good post.

#29 Post by technosaurus »

mister_electronico wrote:Technosaurus can you let me copy you code, to I try to improve my make_dots script?

Very good post..... thanks.
All of my code is under the Technosaurus Public License which basically says you can do whatever you want with it, but don't expect me to contribute back to it if you put it under a viral license like those of the FSF (GPL, LGPL, AGPL,...)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#30 Post by 01micko »

Just for fun I converted text2xpm to C. No other reason. It's basically useless, just an exercise.

Also attached is statically compiled version that should run on most x86 and x86_64 linux OS.

EDIT: updated source, removed crap from a previous attempt
Attachments
texttoxpm.gz
binary -renamed so it doesn't conflict
(11.13 KiB) Downloaded 146 times
text2xpm.c.gz
source
(1.71 KiB) Downloaded 152 times
Puppy Linux Blog - contact me for access

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#31 Post by technosaurus »

01micko wrote:Just for fun I converted text2xpm to C. No other reason. It's basically useless, just an exercise.

Also attached is statically compiled version that should run on most x86 and x86_64 linux OS.

EDIT: updated source, removed crap from a previous attempt
that's pretty ironic... I initially wrote it in c and ported it to shell as an exercise.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Use the same License.

#32 Post by mister_electronico »

Technosaurus wrote

Code: Select all

All of my code is under the Technosaurus Public License which basically says 
you can do whatever you want with it, but don't expect me to contribute back 
to it if you put it under a viral license like those of the FSF (GPL, LGPL, AGPL,...)
I use the same license, never earn a penny with my code and never will win, it's just for fun.

Thanks Technosaurus.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#33 Post by greengeek »

01micko wrote:EDIT: updated source, removed crap from a previous attempt
Hi mick, excuse my ignorance - I tried to run the .c file you uploaded first and got variety of errors. Then I realised it was "source" so I must be using it wrong. I previously thought I should be able to run a C file much the same as a bash file - but that's obviously incorrect (even though I'm sure I have sometimes clicked on a C file and it has run perfectly...).

What should I have done with the .c source file please?
cheers!
(ps I did use the texttoxpm.gz file successfully)

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#34 Post by 01micko »

greengeek wrote:Hi mick, excuse my ignorance - I tried to run the .c file you uploaded first and got variety of errors. Then I realised it was "source" so I must be using it wrong. I previously thought I should be able to run a C file much the same as a bash file - but that's obviously incorrect (even though I'm sure I have sometimes clicked on a C file and it has run perfectly...).

No, you can't 'run' a C source file. It contains code that needs to be 'compiled'. Our stock C compiler is gcc (in the devx). Maybe you were thinking of python or perl (.py or .pl)? Some of those might work by clicking them.
greengeek wrote:What should I have done with the .c source file please?
cheers!
(ps I did use the texttoxpm.gz file successfully)
To compile it (and this is the most simple form - do some homework if you want to get the exec with the name of your choice) simply run this:

Code: Select all

gcc text2xpm.c
This will give you a compiled binary file named 'a.out'. You can run that binary from a terminal. You can rename that binary to whatever you wish.

--

Sorry for OT techno.. should have gone to my 'Fun with C' thread.
Puppy Linux Blog - contact me for access

Post Reply