Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 17 Oct 2019, 09:39
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
cal command alternatives
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 3 [45 Posts]   Goto page: 1, 2, 3 Next
Author Message
torm


Joined: 07 Mar 2015
Posts: 181

PostPosted: Mon 10 Oct 2016, 06:31    Post subject:  cal command alternatives  

Edited topic.

Defaults.
____
Currently most Puppys are shipped with BusyBox version of "cal" command,
that unfortunately fails to detect the correct week-start-day for most european
users. There is also no commandline switch to fix that.
Note that BusyBox is a multi-call binary, and "cal" command is just a symlink
to it by default.


Alternatives.
____
Standard util-linux cal command is provided in util-linux package and
makes around 42k size binary ( stripped ) .
Note that cal as a stand-alone program is not listed in PPM, and util-linux package
may appear already installed.
util-linux has somewhat unusual compile method.
Official source for util-linux package: https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.33/
____
ccal_4.0 is stated as "any OS" alternative to cal ( MSDOS/FreeBSD/Unix/OS2/.. ).
It has some extras like colored terminal output and appointments.
On the other hand, it is no longer developed ( since 2002? ) and may have some
errors for european locales ( broken year view, etc. )
It may be listed in PPM ( Puppy Package Manager )
____
libcalendar-simple-perl_1.21-1
is configurable and small perl script, that unfortunately
depends on another perl module provided ( mostly ) inside devx.sfs
____
There are some bash scripts that try to mimic the cal command, for example:
http://unix.stackexchange.com/questions/29434/displaying-weeks-number-in-certain-format-using-ncal-or-cal
..while those may or not work as expected.



GUI alternatives.
____
gtk2 calendar-widget is a bit heavy, while limited in design
and has little use for external apps as input source.
For example see here: http://murga-linux.com/puppy/viewtopic.php?t=112293
____
gtk1.2 calendar-widget may have problems with locale support ( depending on system )
and needs extra dependencies ( like: gtk1.2 ? ) to compile.
For example of static precompiled bin see here: http://murga-linux.com/puppy/viewtopic.php?t=59079&start=60
____
xcalendar-4.0 is built on the old X Toolkit and the Athena or Motif
widgets. It may have problems with X11 fonts ( locale specific ) and poor visual
appearance. Also there is no automated locale support by default.


Other alternatives.
____
Programs with large size or multiple external dependencies are not listed here.


Practical use for cal command.
____
Output can be piped to different GUI apps like Conky, GKrellm2, and alike.
Or used in gtkdialog apps as direct or edited input for calendar.
Or just.. a fix for broken command?


Summary.
____
The "usual" util-linux cal command is the most correct and complete.
Then again, for some users tricky to install or compile.
It can be the best solution for those who expect full features of cal command
for personal use, while one may need all different variations of precompiled
executable file at hand ( 32/64 deb/slack/whatnot.. ) if it is shared as dependency or
direct input for some other program that is shared as pet package.
NB!
If You know how to compile util-linux cal as stand-alone program ( with: make, make install.. )
outside util-linux package, then please
share it here and include a stand-alone source.
Note..
One may download util-linux without installing it - from PPM, then extract cal from it.
-
ccal_4.0 is licensed as Public Domain package in readme.cal file, and there is MIT-style license in
cal.c file top, hmm... ?
Fuzzy license, help me if you can. For now I'll keep it as it is.
Not perfect, not lightweight, while it should compile on most puppy versions without problems.
I think I managed to trim it down to very basic one-month-view calendar with less than 10kb in size.
Fixed some issues, added automated locale support, etc.
It used to be posted here under name of "kale" before, as source code tar.gz.
That was a little bit funny name in some languages, so I think "pmonth" may fit better.

Last edited by torm on Fri 23 Nov 2018, 20:45; edited 1 time in total
Back to top
View user's profile Send private message 
torm


Joined: 07 Mar 2015
Posts: 181

PostPosted: Mon 20 Aug 2018, 03:35    Post subject:  

pmonth, pmonth_clear.

pmonth is very simple terminal application that displays current month
calendar with current date marked.
Current date is marked with < >
Output can be piped to different GUI apps like Conky, GKrellm2, and alike.

pmonth_clear works the same, however without markings around the current date.
So it may be more suitable for scripts that use sed, etc.

pmonth and pmonth_clear are based on ccal_4.0 program, while take no commandline options
or settings or any other external data.
Week-start-day and locale detection are automated.

To compile, strip and install, open terminal in source directories, and type:

make
make install


Notes.
Default install path is /root/my-applications/bin, to change that - edit Makefile.

License.
pmonth and pmonth_clear are placed into the Public Domain.
pmonth.c and pmonth_clear.c files have the initial MIT-style disclaimers at the top,
from the original cal.c file.
pmonth.tar.gz
Description  pmonth c source
gz

 Download 
Filename  pmonth.tar.gz 
Filesize  3.41 KB 
Downloaded  67 Time(s) 
pmonth_clear.tar.gz
Description  pmonth_clear c source
gz

 Download 
Filename  pmonth_clear.tar.gz 
Filesize  3.31 KB 
Downloaded  81 Time(s) 
pmonth-and-pmonth_clear.jpg
 Description   screenshot from terminal window, note the difference in marks around the current date..
 Filesize   75.61 KB
 Viewed   533 Time(s)

pmonth-and-pmonth_clear.jpg

Back to top
View user's profile Send private message 
torm


Joined: 07 Mar 2015
Posts: 181

PostPosted: Fri 23 Nov 2018, 20:53    Post subject:  

pmonth_gtk2

pmonth_gtk2 is a simple GTK-2 frontend for cal, BusyBox cal or pmonth_clear commands.
It can be updated, started and closed from run_pmonth_gtk2 script.
By default, the script will toggle pmonth_gtk2 on and off, depending on the current state.

Details.
To change the displayed text details or input commands - edit the run_pmonth_gtk2.sh script.

Look.
Transparent and semi-transparent backgrounds for calbg.png file are supported.
Font and color of month name and year number are set in run_pmonth_gtk2.sh script,
also the color of current date.
pmonth_gtk2.rc file in /root/my-applications/pmonth-gtk2/data folder is a
custom theme file for pmonth_gtk2 program only, and can set other look details.
The part in pmonth_gtk2.rc file beginning:
engine "murrine"
{
textstyle = 1
text_shade = 0.01
}
should apply a subtle shadow below dates,
while it can be commented out, if you don't have "Murrine" theme engine for GTK-2 installed.

Defaults.
pmonth_gtk2 is positioned at lower-right corner of display.
Size is 252x402 pixels.
Automatic timeout is 30 seconds, there is a "close" button at the top edge,
and the program will close if window has lost the focus.
Default install path is /root/my-applications/pmonth-gtk2 folder.

Font.
"Droid Sans Mono" TTF font used on screenshot is included in source package but
will not be installed by default, as it my be already installed in some puppy versions.
Default font folders are in /usr/share/fonts/.. - please drop it there, if it isn't already.
"Droid Sans Mono" font is licensed under Apache License v2.0

Notes.
Note the difference for executable file and the folder name: pmonth_gtk2 and pmonth-gtk2.
pmonth_gtk2 uses some code from "navig8or" menu program by Oliver Schweisfurth.


License.
GPLv2 or, at Your option, any later version of that license.

To compile, strip and install, open terminal in source directory, and type:
make
make install

You can run the program with:
run_pmonth_gtk2
pmonth_gtk2.tar.gz
Description  pmonth_gtk2 c source and data
gz

 Download 
Filename  pmonth_gtk2.tar.gz 
Filesize  83.24 KB 
Downloaded  91 Time(s) 
pmonth_gtk2-screenshot.jpg
 Description   screenshot
 Filesize   55.55 KB
 Viewed   530 Time(s)

pmonth_gtk2-screenshot.jpg

Back to top
View user's profile Send private message 
torm


Joined: 07 Mar 2015
Posts: 181

PostPosted: Sun 25 Nov 2018, 13:27    Post subject:  

Side-notes about pmonth_gtk2.

As far as the input for pmonth_gtk2 is prior edited with run_pmonth_gtk2 script,
You could - for example, make the this input more interesting.

In no particular order:
- make header ( month name and year number ) use some other font, size, angle and/or color
- add more space between header and calendar grid
- use different calbg.png backgrounds, depending on month number,
by replacing initial file with link to one of 12 different files - then replace the link as/if needed
- use more interesting design for calbg.png file ( no compositing manager is used )
- insert more/other information from external files/commands
- ...

At the end of the day, use whatever You can pull out of a bash script. Smile
If it does not drag in heavy external dependencies and works as good for other locales
-then please share it here.

It needs some testing first, while I hope that
in the long run, pmonth/pmonth_clear/pmonth_gtk2 could be
shared as 32/64 bit pet files for wider public in correct forum sections.
As stand-alone, or as part of another program.

There is pmonth_plus somewhere on todo list, with some extra/optional features,
once some theoretical uses are figured out to start with.
Don't get me wrong here, I'm not a developer - just a regular but offline user,
so it is sometimes faster to edit some script or source than to
go ( well, walk.. ) online and start searching for something
__

To tell the truth, these days I tend to forget what and where I have uploaded
and that is - even if I have the time to get there. So if anyone would volunteer
to maintain, update, etc the packages - I'd be glad to hand it over.
No rush, whenever it makes to somewhat stable and more tested state, then just
start new topic in desktop/utilities/.. section, simple as that.
Just be prepared to answer any user-side questions and comments in
reasonable time .

For now, have a nice day Wink
Back to top
View user's profile Send private message 
torm


Joined: 07 Mar 2015
Posts: 181

PostPosted: Wed 28 Nov 2018, 15:33    Post subject:  

pmonth_p, pmonth_clear_p

pmonth_p and pmonth_clear_p look and work more or less the same as pmonth and pmonth_clear
( please see the posts above )
The only difference is that you can select the displayed month,
and year ( if month is selected first ) .
Without any options the current month is displayed.

Month number must be padded with leading zero if it is a single digit.
For example to select February of this year, type:
pmonth_p 02

Year number can be within 1800 to 9999 and can only be selected as extra option to month number.
For example to select November of year 2024, type:
pmonth_p 11 2024

pmonth_p uses marks around current date only if current month of current year is selected.
pmonth_clear_p does not use marks.

That would be all for now.
pmonth_p-source.tar.gz
Description  pmonth_p C source
gz

 Download 
Filename  pmonth_p-source.tar.gz 
Filesize  3.87 KB 
Downloaded  83 Time(s) 
pmonth_clear_p-source.tar.gz
Description  pmonth_clear_p C source
gz

 Download 
Filename  pmonth_clear_p-source.tar.gz 
Filesize  3.72 KB 
Downloaded  77 Time(s) 
Back to top
View user's profile Send private message 
rufwoof


Joined: 24 Feb 2014
Posts: 3546

PostPosted: Wed 28 Nov 2018, 16:26    Post subject:  

A bash script to take the busybox cal and print that out with the first column shifted to the end (with the dates shifted up one line, except if Sunday was the 1st) would suffice.
_________________
( ͡° ͜ʖ ͡°) :wq
Fatdog multi-session usb

echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1921
Location: Japan

PostPosted: Fri 30 Nov 2018, 07:59    Post subject:  

@rufwoof: Sunday 1st makes no difference. All last values have to be shifted up. Please post sample code if you know how to do it.
Code:
# cal 7 2018 | sed -r 's/(...)(.*)/\2 \1/'
  July 2018   
Mo Tu We Th Fr Sa Su
 2  3  4  5  6  7  1
 9 10 11 12 13 14  8
16 17 18 19 20 21 15
23 24 25 26 27 28 22
30 31 29
Back to top
View user's profile Send private message 
torm


Joined: 07 Mar 2015
Posts: 181

PostPosted: Fri 30 Nov 2018, 12:16    Post subject:  

Oh..
There used to be a script for that use in pWidgets package, that worked - sometimes
.. and failed, every now and then..

Below is a screenshot from both BusyBox and util-linux cal command output,
where util-linux bin is renamed to "util-linux_cal".
The actual output will be different on systems with different locale
than mine, including week-start-day and abbr. weekday names.
util-linux cal command output on the screenshot is correct for my locale, while
the BusyBox output is "somewhat strange", if you look at the details..

So .. Confused
busybox_vs_util-linux.jpg
 Description   output from BusyBox cal and util-linux cal commands
 Filesize   70.18 KB
 Viewed   402 Time(s)

busybox_vs_util-linux.jpg

Back to top
View user's profile Send private message 
puppy_apprentice


Joined: 07 Feb 2012
Posts: 300

PostPosted: Fri 30 Nov 2018, 16:18    Post subject:  

MochiMoppel wrote:
Please post sample code if you know how to do it.


Ugly code. But you find an idea and could try to make better one:

Code:
n=($(cal | head -2 | tail -1 | tr ' ' '\n'));
echo " "${n[1]}" "${n[2]}" "${n[3]}" "${n[4]}" "${n[5]}" "${n[6]}" "${n[0]}
c=$(cal | tail -n +3)
a=$(echo ${c//   / . })
i=0
j=0
for l in $a
do
  if [ "$l" == "." ]
  then
    j=$((j+1))
  fi
  if [ "$l" == "1" ]
  then
    week="                  $week"
  fi
  if [ $((i-j)) -lt 9 ]
  then
    week="$week  $l"
  else
    week="$week $l"
  fi
  if [ $((i%7)) -eq 0 ]
  then
    week=$week"\n"
  fi
  i=$((i+1))
done
echo -e "$week" | tr '.' ' ' | grep -w -B7 -A7 --color=always "$(date +%e)"
suncal.jpg
 Description   
 Filesize   30.9 KB
 Viewed   382 Time(s)

suncal.jpg

Back to top
View user's profile Send private message 
rufwoof


Joined: 24 Feb 2014
Posts: 3546

PostPosted: Fri 30 Nov 2018, 16:45    Post subject:  

MochiMoppel wrote:
All last values have to be shifted up. Please post sample code if you know how to do it.

Laborious example of how to open/use two file descriptors

Code:
#!/bin/bash

# pass me a month and year i.e. 7 2018

IFS=

# create the two temp files
t1=`mktemp`
t2=`mktemp`

# Load the files
cal $1 $2 | sed -r 's/(...)(.*)/\1/' >$t1  # Sunday list
cal $1 $2 | sed -r 's/(...)(.*)/\2/' >$t2  # Rest

# open the two files
exec 7<$t1
exec 8<$t2

read month <&8
read empty <&7
echo "    $month"

read weekdays1 <&8
read weekdays2 <&7
echo "$weekdays1" "$weekdays2"

read dates2 <&7
tst=`echo ${dates2} | sed 's/ //g'`
if [ ! -z $tst ]; then
   echo "                 " "$dates2"
fi

for i in 1 2 3 4 5 6
do
   read dates1 <&8
   read dates2 <&7
   tst="$dates1 $dates2"
   tst=`echo ${tst} | sed 's/ //g'`
   if [ ! -z $tst ]; then
         echo "$dates1" "$dates2"
   fi
done

# close the files
exec 7</dev/null
exec 8</dev/null

# clean up
rm $t1
rm $t2

Last edited by rufwoof on Sat 01 Dec 2018, 09:10; edited 6 times in total
Back to top
View user's profile Send private message 
Burunduk

Joined: 21 Aug 2011
Posts: 76

PostPosted: Fri 30 Nov 2018, 16:49    Post subject:  

Quote:
The actual output will be different on systems with different locale


My busybox cal always outputs English names no matter what.

---

As the busybox utilities are all I have on my phone, I wrote a script that adds support for -s and -m options to busybox cal. It only shifts the names of days though, numbers are taken from a different year where all the Mondays are Sundays. It works with the years of the current and previous century for simplicity.

Code:
#!/bin/busybox sh
# Wrapper for busybox cal command. Adds support for -s and -m options.

# This is intended to be a function
#local sunday opt o m y

# The default is Monday if $sunday is empty
sunday=default

opt=

while getopts :SMsmyj o; do

        case $o in
            S|s)  sunday=set
                  continue
                  ;;
            M|m)  sunday=${sunday#default}    # only change the default setting
                  continue
                  ;;
            j)    sunday=set
                  ;;
            \?)   cal --help
                  exit 1
                  ;;
        esac

        opt=${opt:--}$o  # save options from shifting
done

shift $(( $OPTIND - 1 ))

case $# in
    0)  y=`date +%Y`
        m=`date +%m`
        ;;
    1)  y="$1"
        m=
        ;;
    2)  y="$2"
        m="$1"
        ;;
    *)  cal --help
        exit 1
        ;;
esac

y="${y%%[^0-9]*}"    # not necessary but this will become a part of a sed script

[[ "$y" -le 1912 || "$y" -gt 2099 ]] && sunday=set


if [[ ! $sunday ]]; then

    cal $opt $m $((y - 12)) | sed -r '
        1 s/[0-9]{4}/'$y'/
        /^[[:alpha:]]./ s/([[:alpha:]].) (.{17})/\2 \1/g
    '
else
    cal $opt "$@"
fi
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1921
Location: Japan

PostPosted: Fri 30 Nov 2018, 21:19    Post subject:  

torm wrote:
util-linux cal command output on the screenshot is correct for my locale, while
the BusyBox output is "somewhat strange", if you look at the details..
And what is your locale?
If busybox cal fails to display weekday abbreviations then I would consider this to be a serious bug. Would make no sense to start any reformatting acrobatic before this issue is solved.

On the other hand I have found no other reports regarding this issue. Strange indeed.
Back to top
View user's profile Send private message 
tallboy


Joined: 21 Sep 2010
Posts: 1501
Location: Drøbak, Norway

PostPosted: Fri 30 Nov 2018, 22:00    Post subject:  

Ancient Puppy:
/root/.packages/builtin_files/minixcal
In /root/.jwm-tray:
Code:
<Clock format="%H:%M:%S">minixcal</Clock>

Activate by click on clock.

_________________
True freedom is a live Puppy on a multisession CD/DVD.
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14404
Location: Gatineau (Qc), Canada

PostPosted: Fri 30 Nov 2018, 22:39    Post subject:  

torm wrote:
(...)
Summary.
____
The "usual" util-linux cal command is the most correct and complete.
Then again, for some users tricky to install or compile.
It can be the best solution for those who expect full features of cal command
for personal use, while one may need all different variations of precompiled
executable file at hand ( 32/64 deb/slack/whatnot.. ) if it is shared as dependency or
direct input for some other program that is shared as pet package.
NB!
If You know how to compile util-linux cal as stand-alone program ( with: make, make install.. )
outside util-linux package, then please
share it here and include a stand-alone source.
Note..
One may download util-linux without installing it - from PPM, then extract cal from it.(...)

Hello torm and all.

Concerning the full cal, please see here. I've attached my
compilation of it for xenialPup-706 (32-bit).

Concerning locales, it probably has no bearing on this discussion, but I
thought I would mention it. There is a new kid in town, called dateutils,
to ease doing date sorts, backward and forward projections, and a
couple of other things. It has an independent locale file located at
/usr/share/dateutils/locale to which one can add his/her own locale if
need be.

Both work fine on my Pup. YMVV.

Finally, perhaps I'm way off, but shouldn't there be a mention of calcurse
on this thread?


BFN.
full-cal.zip
Description  Unzip in /usr/bin and make file cal-2.33 executable. Contains a "cal"
symlink for convenience. (Please note this executable is 32-bit only.)
zip

 Download 
Filename  full-cal.zip 
Filesize  56.49 KB 
Downloaded  40 Time(s) 

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1921
Location: Japan

PostPosted: Fri 30 Nov 2018, 23:34    Post subject:  

@ puppy_apprentice: Simply works Laughing
@ rufwoof: cal chokes on $1 $2. Works when I place IFS='|' after the cal commands
@ Burunduk: Looks like a winner. "Stealing" and relabelling a suitable calendar is a clever idea. The only one in the pack that supports yearly display
Many thanks to all for the interesting suggestions.
Code:
# burunduk_test -m 7 2018
     July 2018
Mo Tu We Th Fr Sa Su
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

# burunduk_test -m 2018
                              2018                             

      January               February               March       
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7            1  2  3  4            1  2  3  4
 8  9 10 11 12 13 14   5  6  7  8  9 10 11   5  6  7  8  9 10 11
15 16 17 18 19 20 21  12 13 14 15 16 17 18  12 13 14 15 16 17 18
22 23 24 25 26 27 28  19 20 21 22 23 24 25  19 20 21 22 23 24 25
29 30 31              26 27 28              26 27 28 29 30 31
                                                                               
       April                  May                   June       
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
                   1      1  2  3  4  5  6               1  2  3
 2  3  4  5  6  7  8   7  8  9 10 11 12 13   4  5  6  7  8  9 10
 9 10 11 12 13 14 15  14 15 16 17 18 19 20  11 12 13 14 15 16 17
16 17 18 19 20 21 22  21 22 23 24 25 26 27  18 19 20 21 22 23 24
23 24 25 26 27 28 29  28 29 30 31           25 26 27 28 29 30
30
        July                 August              September     
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
                   1         1  2  3  4  5                  1  2
 2  3  4  5  6  7  8   6  7  8  9 10 11 12   3  4  5  6  7  8  9
 9 10 11 12 13 14 15  13 14 15 16 17 18 19  10 11 12 13 14 15 16
16 17 18 19 20 21 22  20 21 22 23 24 25 26  17 18 19 20 21 22 23
23 24 25 26 27 28 29  27 28 29 30 31        24 25 26 27 28 29 30
30 31
      October               November              December     
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7            1  2  3  4                  1  2
 8  9 10 11 12 13 14   5  6  7  8  9 10 11   3  4  5  6  7  8  9
15 16 17 18 19 20 21  12 13 14 15 16 17 18  10 11 12 13 14 15 16
22 23 24 25 26 27 28  19 20 21 22 23 24 25  17 18 19 20 21 22 23
29 30 31              26 27 28 29 30        24 25 26 27 28 29 30
                                            31
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 3 [45 Posts]   Goto page: 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1350s ][ Queries: 13 (0.0087s) ][ GZIP on ]