#=6/2006=====================================Version 0=#
#=========== "human readable" grid calendar ==========#
#
# To test :
#
# .\gadget-calendar
# °shows month calendar with current day
# highlighted (red on white by default)
# .\gadget-calendar "6/2006"|tee -file calendar.txt
# .\gadget-calendar "june 2006"|tee -file calendar.txt
# .\gadget-calendar "juin 2006"|tee -file calendar.txt
# °outputs june 2006 month grid and writes it
# to calendar.txt file
# .\gadget-calendar -fullyear 2006|tee -file calendar.txt
# °outputs full year 2006 grid (3 x 4) and writes it
# to calendar.txt file
#
# NOTE : gadget-calendar without parameters doesn't
# highlight current day if you call it directly
# after you've launched PowerShell (probably a
# console bug).
# If you recall gagdet-calendar, that works.
#
#======================================================#
function build_date_table($date){
#### Returns an array containing days numbers ####
#### and month name ####
## Sets variables containing month and year of the date ##
$m=$date.Month
$y=$date.Year
## Get month's first day position in the week ##
[datetime]$firstday=[string]$m+'/'+[string]$y
$fd=[int]$firstday.DayOfWeek
## As "dayofweek" is 0 indexed from Sunday to ##
## Saturday and we want from Monday to Sunday we ##
## use a "1 indexed" concept : ##
if($fd -eq 0){$fd=7}
## Sets a variable containing the number ##
## of days in the month ##
$ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m)
## Build an array containing days numbers relative ##
## to days names positions. ##
## If a position is not used, the value is set to ##
## a space char. ##
$table=@()
$rui=$host.UI.RawUI
## Stores current background/foreground console's colors ##
$oldfg=$rui.ForegroundColor
$oldbg=$rui.BackgroundColor
## Set console's colors for Month/Year line and grid ##
$rui.BackgroundColor=$calendarbg
if(!$fullyear){
$monthtable=build_date_table(get-date $strdate)
$monthyear=$monthtable[1]
$daystable=$monthtable[0]
$rui.ForegroundColor=$monthyearfg
## Ouputs month/year line ##
[string]$monthyear
## Set days names line foreground color ##
$rui.ForegroundColor=$daynamefg
## Outputs day names ##
' '+[string]$daysnames+' '
## Set days numbers foreground color ##
$rui.ForegroundColor=$dayfg
#=9/2006===================================Version 1.1===# #=========== "human readable" grid calendar ============# # # To test : # # .gadget-calendar # °shows month calendar with current day # highlighted (red on white by default) # .gadget-calendar "6/2006"|tee -file calendar.txt # .gadget-calendar "june 2006"|tee -file calendar.txt # .gadget-calendar "juin 2006"|tee -file calendar.txt # °outputs june 2006 month grid and writes it # to calendar.txt file # .gadget-calendar 2006|tee -file calendar.txt # °outputs full year 2006 grid (3 x 4) and writes it # to calendar.txt file # # NOTES # # About 1st century : # # When a string is passed for first argument, years between # 1 and 99 must be 0000 formated (so 0001 to 0099). # .gadget-calendar "5/0023" # # Values allowed for years : # # As in .Net specifications years can be in range 1..9999 # # THANKS : # # to MOW to have fix a previous ennoying bug "current # day not always highlighted". # See this message on microsoft.public.windows.powershell : # #========================================================#
function build_date_table($date){ #### Returns an array containing days numbers #### #### and month name ####
## Sets variables containing month and year of the date ## $m=$date.Month $y=($date.Year).ToString("0000") ## Get month's first day position in the week ## [datetime]$firstday=[string]$m+'/'+[string]$y $fd=[int]$firstday.DayOfWeek ## As "dayofweek" is 0 indexed from Sunday to ## ## Saturday and we want from Monday to Sunday we ## ## use a "1 indexed" concept : ## if($fd -eq 0){$fd=7} ## Sets a variable containing the number ## ## of days in the month ## $ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m) ## Build an array containing days numbers relative ## ## to days names positions. ## ## If a position is not used, the value is set to ## ## a space char. ## $table=@()
$rui=(get-host).UI.RawUI ## Stores current background/foreground console's colors ## $oldfg=$rui.ForegroundColor $oldbg=$rui.BackgroundColor ## Set console's colors for Month/Year line and grid ## $rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ## ## $fullyear to $vardate ## if($vardate.GetTypeCode() -eq "Int32"){$fullyear=$vardate.ToString("0000")}
if(!$fullyear){ $monthtable=build_date_table(get-date $vardate) $monthyear=$monthtable[1] $daystable=$monthtable[0] $rui.ForegroundColor=$monthyearfg ## Ouputs month/year line ## [string]$monthyear ## Set days names line foreground color ## $rui.ForegroundColor=$daynamefg ## Outputs day names ## ' '+[string]$daysnames+' ' ## Set days numbers foreground color ## $rui.ForegroundColor=$dayfg
#=9/2006===================================Version 1.1===#
#=========== "human readable" grid calendar ============#
#
# To test :
#
# .gadget-calendar
# °shows month calendar with current day
# highlighted (red on white by default)
# .gadget-calendar "6/2006"|tee -file calendar.txt
# .gadget-calendar "june 2006"|tee -file calendar.txt
# .gadget-calendar "juin 2006"|tee -file calendar.txt
# °outputs june 2006 month grid and writes it
# to calendar.txt file
# .gadget-calendar 2006|tee -file calendar.txt
# °outputs full year 2006 grid (3 x 4) and writes it
# to calendar.txt file
#
# NOTES
#
# About 1st century :
#
# When a string is passed for first argument, years between
# 1 and 99 must be 0000 formated (so 0001 to 0099).
# .gadget-calendar "5/0023"
#
# Values allowed for years :
#
# As in .Net specifications years can be in range 1..9999
#
# THANKS :
#
# to MOW to have fix a previous ennoying bug "current
# day not always highlighted".
# See this message on microsoft.public.windows.powershell :
# Ozb94fPnGHA.4240@TK2MSFTNGP02.phx.gbl
#========================================================#
function build_date_table($date){
#### Returns an array containing days numbers ####
#### and month name ####
## Sets variables containing month and year of the date ##
$m=$date.Month
$y=($date.Year).ToString("0000")
## Get month's first day position in the week ##
[datetime]$firstday=[string]$m+'/'+[string]$y
$fd=[int]$firstday.DayOfWeek
## As "dayofweek" is 0 indexed from Sunday to ##
## Saturday and we want from Monday to Sunday we ##
## use a "1 indexed" concept : ##
if($fd -eq 0){$fd=7}
## Sets a variable containing the number ##
## of days in the month ##
$ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m)
## Build an array containing days numbers relative ##
## to days names positions. ##
## If a position is not used, the value is set to ##
## a space char. ##
$table=@()
$rui=(get-host).UI.RawUI
## Stores current background/foreground console's colors ##
$oldfg=$rui.ForegroundColor
$oldbg=$rui.BackgroundColor
## Set console's colors for Month/Year line and grid ##
$rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ##
## $fullyear to $vardate ##
if($vardate.GetTypeCode() -eq
"Int32"){$fullyear=$vardate.ToString("0000")}
if(!$fullyear){
$monthtable=build_date_table(get-date $vardate)
$monthyear=$monthtable[1]
$daystable=$monthtable[0]
$rui.ForegroundColor=$monthyearfg
## Ouputs month/year line ##
[string]$monthyear
## Set days names line foreground color ##
$rui.ForegroundColor=$daynamefg
## Outputs day names ##
' '+[string]$daysnames+' '
## Set days numbers foreground color ##
$rui.ForegroundColor=$dayfg
#=9/2006===================================Version 1.1===# #=========== "human readable" grid calendar ============# # # To test : # # .gadget-calendar # °shows month calendar with current day # highlighted (red on white by default) # .gadget-calendar "6/2006"|tee -file calendar.txt # .gadget-calendar "june 2006"|tee -file calendar.txt # .gadget-calendar "juin 2006"|tee -file calendar.txt # °outputs june 2006 month grid and writes it # to calendar.txt file # .gadget-calendar 2006|tee -file calendar.txt # °outputs full year 2006 grid (3 x 4) and writes it # to calendar.txt file # # NOTES # # About 1st century : # # When a string is passed for first argument, years between # 1 and 99 must be 0000 formated (so 0001 to 0099). # .gadget-calendar "5/0023" # # Values allowed for years : # # As in .Net specifications years can be in range 1..9999 # # THANKS : # # to MOW to have fix a previous ennoying bug "current # day not always highlighted". # See this message on microsoft.public.windows.powershell : # #========================================================#
function build_date_table($date){ #### Returns an array containing days numbers #### #### and month name ####
## Sets variables containing month and year of the date ## $m=$date.Month $y=($date.Year).ToString("0000") ## Get month's first day position in the week ## [datetime]$firstday=[string]$m+'/'+[string]$y $fd=[int]$firstday.DayOfWeek ## As "dayofweek" is 0 indexed from Sunday to ## ## Saturday and we want from Monday to Sunday we ## ## use a "1 indexed" concept : ## if($fd -eq 0){$fd=7} ## Sets a variable containing the number ## ## of days in the month ## $ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m) ## Build an array containing days numbers relative ## ## to days names positions. ## ## If a position is not used, the value is set to ## ## a space char. ## $table=@()
$rui=(get-host).UI.RawUI ## Stores current background/foreground console's colors ## $oldfg=$rui.ForegroundColor $oldbg=$rui.BackgroundColor ## Set console's colors for Month/Year line and grid ## $rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ## ## $fullyear to $vardate ## if($vardate.GetTypeCode() -eq "Int32"){$fullyear=$vardate.ToString("0000")}
if(!$fullyear){ $monthtable=build_date_table(get-date $vardate) $monthyear=$monthtable[1] $daystable=$monthtable[0] $rui.ForegroundColor=$monthyearfg ## Ouputs month/year line ## [string]$monthyear ## Set days names line foreground color ## $rui.ForegroundColor=$daynamefg ## Outputs day names ## ' '+[string]$daysnames+' ' ## Set days numbers foreground color ## $rui.ForegroundColor=$dayfg
## Restores OFS to its previous value $OFS=$oldOFS #---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---
#Amicalement,
-- Jean - JMST Belgium
Jean
J'ai un problème d'affichage quand j'essaie le script. Une ligne vierge s'intercale entre deux lignes du calendrier.
Le problème a été fixé par James Truher sur microsoft.public.windows.powershell : http://groups.google.com/group/microsoft.public.windows.powershell/msg/7164c7d9364ad45a?dmode=source
Encore merci à lui.
Comme le script n'a pas besoin du comportement de l'apostrophe, plutôt que de modifier uniquement la ligne indiquée, j'ai remplacé toute les apostrophes par des double guillemets.
Je poste le script corrigé en réponse à ce message.
Amicalement,
-- Jean - JMST Belgium
J'ai un problème d'affichage quand j'essaie le script. Une ligne vierge
s'intercale entre deux lignes du calendrier.
Le problème a été fixé par James Truher sur
microsoft.public.windows.powershell :
http://groups.google.com/group/microsoft.public.windows.powershell/msg/7164c7d9364ad45a?dmode=source
Encore merci à lui.
Comme le script n'a pas besoin du comportement de l'apostrophe, plutôt
que de modifier uniquement la ligne indiquée, j'ai remplacé toute les
apostrophes par des double guillemets.
Je poste le script corrigé en réponse à ce message.
J'ai un problème d'affichage quand j'essaie le script. Une ligne vierge s'intercale entre deux lignes du calendrier.
Le problème a été fixé par James Truher sur microsoft.public.windows.powershell : http://groups.google.com/group/microsoft.public.windows.powershell/msg/7164c7d9364ad45a?dmode=source
Encore merci à lui.
Comme le script n'a pas besoin du comportement de l'apostrophe, plutôt que de modifier uniquement la ligne indiquée, j'ai remplacé toute les apostrophes par des double guillemets.
Je poste le script corrigé en réponse à ce message.
Amicalement,
-- Jean - JMST Belgium
Jean
Je poste le script corrigé en réponse à ce message.
#=9/2006===================================Version 1.2===# #=========== "human readable" grid calendar ============# # # To test : # # .gadget-calendar # °shows month calendar with current day # highlighted (red on white by default) # .gadget-calendar "6/2006"|tee -file calendar.txt # .gadget-calendar "june 2006"|tee -file calendar.txt # .gadget-calendar "juin 2006"|tee -file calendar.txt # °outputs june 2006 month grid and writes it # to calendar.txt file # .gadget-calendar 2006|tee -file calendar.txt # °outputs full year 2006 grid (3 x 4) and writes it # to calendar.txt file # # NOTES # # About 1st century : # # When a string is passed for first argument, years between # 1 and 99 must be 0000 formated (so 0001 to 0099). # .gadget-calendar "5/0023" # # Values allowed for years : # # As in .Net specifications years can be in range 1..9999 # # THANKS : # # To MOW to have fix a previous ennoying bug "current # day not always highlighted". # See this message on microsoft.public.windows.powershell : # # # To Jacques Barathon to have reported a problem with RC2 : # "blank lines added". # See this message on microsoft.public.fr.scripting : # # To James Truher to have fix this RC2 compatibility problem. # See this message on microsoft.public.windows.powershell : # # #========Tested on PowerShell 1 RC1 (1.0.9567.1)=========#
function build_date_table($date){ #### Returns an array containing days numbers #### #### and month name ####
## Sets variables containing month and year of the date ## $m=$date.Month $y=($date.Year).ToString("0000") ## Get month's first day position in the week ## [datetime]$firstday=[string]$m+"/"+[string]$y $fd=[int]$firstday.DayOfWeek ## As "dayofweek" is 0 indexed from Sunday to ## ## Saturday and we want from Monday to Sunday we ## ## use a "1 indexed" concept : ## if($fd -eq 0){$fd=7} ## Sets a variable containing the number ## ## of days in the month ## $ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m) ## Build an array containing days numbers relative ## ## to days names positions. ## ## If a position is not used, the value is set to ## ## a space char. ## $table=@()
$rui=(get-host).UI.RawUI ## Stores current background/foreground console's colors ## $oldfg=$rui.ForegroundColor $oldbg=$rui.BackgroundColor ## Set console's colors for Month/Year line and grid ## $rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ## ## $fullyear to $vardate ## if($vardate.GetTypeCode() -eq "Int32") {$fullyear=$vardate.ToString("0000")}
if(!$fullyear){ $monthtable=build_date_table(get-date $vardate) $monthyear=$monthtable[1] $daystable=$monthtable[0] $rui.ForegroundColor=$monthyearfg ## Ouputs month/year line ## [string]$monthyear ## Set days names line foreground color ## $rui.ForegroundColor=$daynamefg ## Outputs day names ## " "+[string]$daysnames+" " ## Set days numbers foreground color ## $rui.ForegroundColor=$dayfg
#=9/2006===================================Version 1.2===#
#=========== "human readable" grid calendar ============#
#
# To test :
#
# .gadget-calendar
# °shows month calendar with current day
# highlighted (red on white by default)
# .gadget-calendar "6/2006"|tee -file calendar.txt
# .gadget-calendar "june 2006"|tee -file calendar.txt
# .gadget-calendar "juin 2006"|tee -file calendar.txt
# °outputs june 2006 month grid and writes it
# to calendar.txt file
# .gadget-calendar 2006|tee -file calendar.txt
# °outputs full year 2006 grid (3 x 4) and writes it
# to calendar.txt file
#
# NOTES
#
# About 1st century :
#
# When a string is passed for first argument, years between
# 1 and 99 must be 0000 formated (so 0001 to 0099).
# .gadget-calendar "5/0023"
#
# Values allowed for years :
#
# As in .Net specifications years can be in range 1..9999
#
# THANKS :
#
# To MOW to have fix a previous ennoying bug "current
# day not always highlighted".
# See this message on microsoft.public.windows.powershell :
# Ozb94fPnGHA.4240@TK2MSFTNGP02.phx.gbl
#
# To Jacques Barathon to have reported a problem with RC2 :
# "blank lines added".
# See this message on microsoft.public.fr.scripting :
# 9704F9D3-A26E-4D19-B264-6D8E284583BA@microsoft.com
# To James Truher to have fix this RC2 compatibility problem.
# See this message on microsoft.public.windows.powershell :
# OZZcK3P4GHA.2208@TK2MSFTNGP04.phx.gbl
#
#========Tested on PowerShell 1 RC1 (1.0.9567.1)=========#
function build_date_table($date){
#### Returns an array containing days numbers ####
#### and month name ####
## Sets variables containing month and year of the date ##
$m=$date.Month
$y=($date.Year).ToString("0000")
## Get month's first day position in the week ##
[datetime]$firstday=[string]$m+"/"+[string]$y
$fd=[int]$firstday.DayOfWeek
## As "dayofweek" is 0 indexed from Sunday to ##
## Saturday and we want from Monday to Sunday we ##
## use a "1 indexed" concept : ##
if($fd -eq 0){$fd=7}
## Sets a variable containing the number ##
## of days in the month ##
$ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m)
## Build an array containing days numbers relative ##
## to days names positions. ##
## If a position is not used, the value is set to ##
## a space char. ##
$table=@()
$rui=(get-host).UI.RawUI
## Stores current background/foreground console's colors ##
$oldfg=$rui.ForegroundColor
$oldbg=$rui.BackgroundColor
## Set console's colors for Month/Year line and grid ##
$rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ##
## $fullyear to $vardate ##
if($vardate.GetTypeCode() -eq "Int32")
{$fullyear=$vardate.ToString("0000")}
if(!$fullyear){
$monthtable=build_date_table(get-date $vardate)
$monthyear=$monthtable[1]
$daystable=$monthtable[0]
$rui.ForegroundColor=$monthyearfg
## Ouputs month/year line ##
[string]$monthyear
## Set days names line foreground color ##
$rui.ForegroundColor=$daynamefg
## Outputs day names ##
" "+[string]$daysnames+" "
## Set days numbers foreground color ##
$rui.ForegroundColor=$dayfg
#=9/2006===================================Version 1.2===# #=========== "human readable" grid calendar ============# # # To test : # # .gadget-calendar # °shows month calendar with current day # highlighted (red on white by default) # .gadget-calendar "6/2006"|tee -file calendar.txt # .gadget-calendar "june 2006"|tee -file calendar.txt # .gadget-calendar "juin 2006"|tee -file calendar.txt # °outputs june 2006 month grid and writes it # to calendar.txt file # .gadget-calendar 2006|tee -file calendar.txt # °outputs full year 2006 grid (3 x 4) and writes it # to calendar.txt file # # NOTES # # About 1st century : # # When a string is passed for first argument, years between # 1 and 99 must be 0000 formated (so 0001 to 0099). # .gadget-calendar "5/0023" # # Values allowed for years : # # As in .Net specifications years can be in range 1..9999 # # THANKS : # # To MOW to have fix a previous ennoying bug "current # day not always highlighted". # See this message on microsoft.public.windows.powershell : # # # To Jacques Barathon to have reported a problem with RC2 : # "blank lines added". # See this message on microsoft.public.fr.scripting : # # To James Truher to have fix this RC2 compatibility problem. # See this message on microsoft.public.windows.powershell : # # #========Tested on PowerShell 1 RC1 (1.0.9567.1)=========#
function build_date_table($date){ #### Returns an array containing days numbers #### #### and month name ####
## Sets variables containing month and year of the date ## $m=$date.Month $y=($date.Year).ToString("0000") ## Get month's first day position in the week ## [datetime]$firstday=[string]$m+"/"+[string]$y $fd=[int]$firstday.DayOfWeek ## As "dayofweek" is 0 indexed from Sunday to ## ## Saturday and we want from Monday to Sunday we ## ## use a "1 indexed" concept : ## if($fd -eq 0){$fd=7} ## Sets a variable containing the number ## ## of days in the month ## $ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m) ## Build an array containing days numbers relative ## ## to days names positions. ## ## If a position is not used, the value is set to ## ## a space char. ## $table=@()
$rui=(get-host).UI.RawUI ## Stores current background/foreground console's colors ## $oldfg=$rui.ForegroundColor $oldbg=$rui.BackgroundColor ## Set console's colors for Month/Year line and grid ## $rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ## ## $fullyear to $vardate ## if($vardate.GetTypeCode() -eq "Int32") {$fullyear=$vardate.ToString("0000")}
if(!$fullyear){ $monthtable=build_date_table(get-date $vardate) $monthyear=$monthtable[1] $daystable=$monthtable[0] $rui.ForegroundColor=$monthyearfg ## Ouputs month/year line ## [string]$monthyear ## Set days names line foreground color ## $rui.ForegroundColor=$daynamefg ## Outputs day names ## " "+[string]$daysnames+" " ## Set days numbers foreground color ## $rui.ForegroundColor=$dayfg
Pour info, j'ai toujours un souci avec la version corrigée. Cette fois-ci c'est les couleurs qui "bavent". L'exécution du script étale la couleur gris sur toutes les lignes où le calendrier s'affiche, alors que le fond de base de ma session est noir. Cela donne des effets assez peu heureux.
Je n'ai pas bcp de temps en ce moment, mais j'essaierai de regarder plus tard...
Jacques
"Jean" a écrit dans le message de news:
Je poste le script corrigé en réponse à ce message.
#=9/2006===================================Version 1.2===# #=========== "human readable" grid calendar ============# # # To test : # # .gadget-calendar # °shows month calendar with current day # highlighted (red on white by default) # .gadget-calendar "6/2006"|tee -file calendar.txt # .gadget-calendar "june 2006"|tee -file calendar.txt # .gadget-calendar "juin 2006"|tee -file calendar.txt # °outputs june 2006 month grid and writes it # to calendar.txt file # .gadget-calendar 2006|tee -file calendar.txt # °outputs full year 2006 grid (3 x 4) and writes it # to calendar.txt file # # NOTES # # About 1st century : # # When a string is passed for first argument, years between # 1 and 99 must be 0000 formated (so 0001 to 0099). # .gadget-calendar "5/0023" # # Values allowed for years : # # As in .Net specifications years can be in range 1..9999 # # THANKS : # # To MOW to have fix a previous ennoying bug "current # day not always highlighted". # See this message on microsoft.public.windows.powershell : # # # To Jacques Barathon to have reported a problem with RC2 : # "blank lines added". # See this message on microsoft.public.fr.scripting : # # To James Truher to have fix this RC2 compatibility problem. # See this message on microsoft.public.windows.powershell : # # #========Tested on PowerShell 1 RC1 (1.0.9567.1)=========#
function build_date_table($date){ #### Returns an array containing days numbers #### #### and month name ####
## Sets variables containing month and year of the date ## $m=$date.Month $y=($date.Year).ToString("0000") ## Get month's first day position in the week ## [datetime]$firstday=[string]$m+"/"+[string]$y $fd=[int]$firstday.DayOfWeek ## As "dayofweek" is 0 indexed from Sunday to ## ## Saturday and we want from Monday to Sunday we ## ## use a "1 indexed" concept : ## if($fd -eq 0){$fd=7} ## Sets a variable containing the number ## ## of days in the month ## $ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m) ## Build an array containing days numbers relative ## ## to days names positions. ## ## If a position is not used, the value is set to ## ## a space char. ## $table=@()
$rui=(get-host).UI.RawUI ## Stores current background/foreground console's colors ## $oldfg=$rui.ForegroundColor $oldbg=$rui.BackgroundColor ## Set console's colors for Month/Year line and grid ## $rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ## ## $fullyear to $vardate ## if($vardate.GetTypeCode() -eq "Int32") {$fullyear=$vardate.ToString("0000")}
if(!$fullyear){ $monthtable=build_date_table(get-date $vardate) $monthyear=$monthtable[1] $daystable=$monthtable[0] $rui.ForegroundColor=$monthyearfg ## Ouputs month/year line ## [string]$monthyear ## Set days names line foreground color ## $rui.ForegroundColor=$daynamefg ## Outputs day names ## " "+[string]$daysnames+" " ## Set days numbers foreground color ## $rui.ForegroundColor=$dayfg
## Restores OFS to its previous value $OFS=$oldOFS #---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---
#Amicalement,
-- Jean - JMST Belgium
Merci Jean.
Pour info, j'ai toujours un souci avec la version corrigée. Cette fois-ci
c'est les couleurs qui "bavent". L'exécution du script étale la couleur gris
sur toutes les lignes où le calendrier s'affiche, alors que le fond de base
de ma session est noir. Cela donne des effets assez peu heureux.
Je n'ai pas bcp de temps en ce moment, mais j'essaierai de regarder plus
tard...
Jacques
"Jean" <repondre@groupe.svp> a écrit dans le message de news:
mn.d3e17d699c60ab54.56820@windows...
Je poste le script corrigé en réponse à ce message.
#=9/2006===================================Version 1.2===#
#=========== "human readable" grid calendar ============#
#
# To test :
#
# .gadget-calendar
# °shows month calendar with current day
# highlighted (red on white by default)
# .gadget-calendar "6/2006"|tee -file calendar.txt
# .gadget-calendar "june 2006"|tee -file calendar.txt
# .gadget-calendar "juin 2006"|tee -file calendar.txt
# °outputs june 2006 month grid and writes it
# to calendar.txt file
# .gadget-calendar 2006|tee -file calendar.txt
# °outputs full year 2006 grid (3 x 4) and writes it
# to calendar.txt file
#
# NOTES
#
# About 1st century :
#
# When a string is passed for first argument, years between
# 1 and 99 must be 0000 formated (so 0001 to 0099).
# .gadget-calendar "5/0023"
#
# Values allowed for years :
#
# As in .Net specifications years can be in range 1..9999
#
# THANKS :
#
# To MOW to have fix a previous ennoying bug "current
# day not always highlighted".
# See this message on microsoft.public.windows.powershell :
# Ozb94fPnGHA.4240@TK2MSFTNGP02.phx.gbl
#
# To Jacques Barathon to have reported a problem with RC2 :
# "blank lines added".
# See this message on microsoft.public.fr.scripting :
# 9704F9D3-A26E-4D19-B264-6D8E284583BA@microsoft.com
# To James Truher to have fix this RC2 compatibility problem.
# See this message on microsoft.public.windows.powershell :
# OZZcK3P4GHA.2208@TK2MSFTNGP04.phx.gbl
#
#========Tested on PowerShell 1 RC1 (1.0.9567.1)=========#
function build_date_table($date){
#### Returns an array containing days numbers ####
#### and month name ####
## Sets variables containing month and year of the date ##
$m=$date.Month
$y=($date.Year).ToString("0000")
## Get month's first day position in the week ##
[datetime]$firstday=[string]$m+"/"+[string]$y
$fd=[int]$firstday.DayOfWeek
## As "dayofweek" is 0 indexed from Sunday to ##
## Saturday and we want from Monday to Sunday we ##
## use a "1 indexed" concept : ##
if($fd -eq 0){$fd=7}
## Sets a variable containing the number ##
## of days in the month ##
$ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m)
## Build an array containing days numbers relative ##
## to days names positions. ##
## If a position is not used, the value is set to ##
## a space char. ##
$table=@()
$rui=(get-host).UI.RawUI
## Stores current background/foreground console's colors ##
$oldfg=$rui.ForegroundColor
$oldbg=$rui.BackgroundColor
## Set console's colors for Month/Year line and grid ##
$rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ##
## $fullyear to $vardate ##
if($vardate.GetTypeCode() -eq "Int32")
{$fullyear=$vardate.ToString("0000")}
if(!$fullyear){
$monthtable=build_date_table(get-date $vardate)
$monthyear=$monthtable[1]
$daystable=$monthtable[0]
$rui.ForegroundColor=$monthyearfg
## Ouputs month/year line ##
[string]$monthyear
## Set days names line foreground color ##
$rui.ForegroundColor=$daynamefg
## Outputs day names ##
" "+[string]$daysnames+" "
## Set days numbers foreground color ##
$rui.ForegroundColor=$dayfg
Pour info, j'ai toujours un souci avec la version corrigée. Cette fois-ci c'est les couleurs qui "bavent". L'exécution du script étale la couleur gris sur toutes les lignes où le calendrier s'affiche, alors que le fond de base de ma session est noir. Cela donne des effets assez peu heureux.
Je n'ai pas bcp de temps en ce moment, mais j'essaierai de regarder plus tard...
Jacques
"Jean" a écrit dans le message de news:
Je poste le script corrigé en réponse à ce message.
#=9/2006===================================Version 1.2===# #=========== "human readable" grid calendar ============# # # To test : # # .gadget-calendar # °shows month calendar with current day # highlighted (red on white by default) # .gadget-calendar "6/2006"|tee -file calendar.txt # .gadget-calendar "june 2006"|tee -file calendar.txt # .gadget-calendar "juin 2006"|tee -file calendar.txt # °outputs june 2006 month grid and writes it # to calendar.txt file # .gadget-calendar 2006|tee -file calendar.txt # °outputs full year 2006 grid (3 x 4) and writes it # to calendar.txt file # # NOTES # # About 1st century : # # When a string is passed for first argument, years between # 1 and 99 must be 0000 formated (so 0001 to 0099). # .gadget-calendar "5/0023" # # Values allowed for years : # # As in .Net specifications years can be in range 1..9999 # # THANKS : # # To MOW to have fix a previous ennoying bug "current # day not always highlighted". # See this message on microsoft.public.windows.powershell : # # # To Jacques Barathon to have reported a problem with RC2 : # "blank lines added". # See this message on microsoft.public.fr.scripting : # # To James Truher to have fix this RC2 compatibility problem. # See this message on microsoft.public.windows.powershell : # # #========Tested on PowerShell 1 RC1 (1.0.9567.1)=========#
function build_date_table($date){ #### Returns an array containing days numbers #### #### and month name ####
## Sets variables containing month and year of the date ## $m=$date.Month $y=($date.Year).ToString("0000") ## Get month's first day position in the week ## [datetime]$firstday=[string]$m+"/"+[string]$y $fd=[int]$firstday.DayOfWeek ## As "dayofweek" is 0 indexed from Sunday to ## ## Saturday and we want from Monday to Sunday we ## ## use a "1 indexed" concept : ## if($fd -eq 0){$fd=7} ## Sets a variable containing the number ## ## of days in the month ## $ld=(Get-Culture).Calendar.GetDaysInMonth($y,$m) ## Build an array containing days numbers relative ## ## to days names positions. ## ## If a position is not used, the value is set to ## ## a space char. ## $table=@()
$rui=(get-host).UI.RawUI ## Stores current background/foreground console's colors ## $oldfg=$rui.ForegroundColor $oldbg=$rui.BackgroundColor ## Set console's colors for Month/Year line and grid ## $rui.BackgroundColor=$calendarbg
## If an integer is passed for $vardate then defines ## ## $fullyear to $vardate ## if($vardate.GetTypeCode() -eq "Int32") {$fullyear=$vardate.ToString("0000")}
if(!$fullyear){ $monthtable=build_date_table(get-date $vardate) $monthyear=$monthtable[1] $daystable=$monthtable[0] $rui.ForegroundColor=$monthyearfg ## Ouputs month/year line ## [string]$monthyear ## Set days names line foreground color ## $rui.ForegroundColor=$daynamefg ## Outputs day names ## " "+[string]$daysnames+" " ## Set days numbers foreground color ## $rui.ForegroundColor=$dayfg