Google Groupes n'accepte plus les nouveaux posts ni abonnements Usenet. Les contenus de l'historique resteront visibles.

[PS] Calendrier visuel PowerShell ...

48 vues
Accéder directement au premier message non lu

Jean

non lue,
17 juin 2006, 18:19:5617/06/2006
à
#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

#=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.
#
#======================================================#

param(
[string]$strdate=(get-date),
[ConsoleColor]$calendarbg='DarkGray',
[ConsoleColor]$monthyearfg='Cyan',
[ConsoleColor]$daynamefg='DarkBlue',
[ConsoleColor]$dayfg='White',
[ConsoleColor]$highlightdayfg='Red',
[ConsoleColor]$highlightdaybg='White',
[int32]$fullyear
)

#### Build an array of two first letters ####
#### localized days names ####

$firstdate=[datetime](0)
$daysnames=@(0..6)|%{
($_=$firstdate.ToString("dddd").SubString(0,2))
$firstdate=$firstdate.AddDays(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
## 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=@()

for($i=0;$i -lt $fd-1+$ld;$i++){
if($i+1 -lt $fd)
{$table+=' '*2}
else
{$table+=[string]($i-$fd+2)}
if($table[$table.Length-1].Length -eq 1)
{$table[$table.Length-1]+=' '}
if(($i+1) % 7 -eq 0)
{
$table[$table.Length-1]+=' '
if(!($table[$table.Length-1].Trim() -eq $ld))
{$table[$table.Length-1]+='`n'}
}
}
## Adds some extra space chars needed for formating output##
for($i=0;$i -lt $table.Length % 7)
{$table+=' '*2}
if($table[$table.Length-1] -eq ' '*2)
{$table[$table.Length-1]+=' '}
## get Month/Year localized string ##
$monthyear=$date.ToString("MMMM yyyy")
$monthyear=(' '*((21-$monthyear.Length)/2))+$monthyear
$monthyear+=(' '*(21-$monthyear.Length))+' '
return $table,$monthyear
}#end function build_date_table

#### Writes + colorizes calendar grid ####

$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

if($strdate -ne (get-date))
## Outputs calendar month grid ##
{(' '+([string]($daystable))).Split('`n')|%{$_}}
else
## Shows current month grid and highlight current day ##
{
($daystable)|
%{
write-host (' ') -NoNewLine
if($_.Trim() -eq (get-date $strdate).Day)
{
write-host ($_) `
-NoNewLine `
-ForegroundColor $highlightdayfg `
-BackgroundColor $highlightdaybg
}
else
{write-host ($_) -NoNewLine}
}
write-host '`r'
}
}else{
## Outputs full year grid ##
$yeartable=@(0..11)
$year=[string]$fullyear
$monthnames=@()
for($i=1;$i -lt 13;$i++){
$monthdays=
build_date_table(get-date([string]$i+'/'+$year))
$yeartable[$i-1]=
((' '+[string]($monthdays)[0]).Split('`n'))
$monthnames+=($monthdays[1])
}
for($i=0;$i -lt 12;$i+=3){
$rui.ForegroundColor=$monthyearfg
$monthnames[$i]+$monthnames[$i+1]+$monthnames[$i+2]
$rui.ForegroundColor=$daynamefg
((' '+[string]$daysnames+' ')*3)
$max=(
(
$yeartable[$i].length,`
$yeartable[$i+1].length,`
$yeartable[$i+2].length
)|sort
)[2]
for($j=0;$j -lt 3;$j++){
if($yeartable[$i+$j].Length -lt $max)
{$yeartable[$i+$j]+=' '*22}
}
$rui.ForegroundColor=$dayfg
for($j=0;$j -lt $max;$j++)
{
(
$yeartable[$i][$j]+
$yeartable[$i+1][$j]+
$yeartable[$i+2][$j]
)
}
''
}
}
## Restores console's background/foreground colors ##
$rui.ForegroundColor=$oldfg
$rui.BackgroundColor=$oldbg

#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

# Amicalement,

--
Jean - JMST
Belgium


Jacques Barathon [MS]

non lue,
18 juin 2006, 04:42:0418/06/2006
à
Superbe gadget, merci Jean! Je n'avais pas noté qu'il pleuvait si fort en
Belgique ces derniers jours :-)

"Jean" <repo...@groupe.svp> wrote in message
news:mn.90137d663f6edca7.49174@windows...
> #---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---
<snip>


> # 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.

As-tu ouvert un bug?

Jacques


Jacques Barathon [MS]

non lue,
18 juin 2006, 07:26:3818/06/2006
à
"Michel Claveau" <Enleverles XX....@XmXclaveauXX.XX.com> wrote in message
news:mn.92b07d66a...@XmXclaveauXX.XX.com...
> Pour info, voici une version PeJBshell :
>
> .pyt
> import calendar

Pff... Comparer un script avec une bibliothèque toute faite, quelle honte...
Il existe également une classe Calendar en .NET, mais il semble qu'elle soit
uniquement prévue pour un affichage dans une page web, même s'il doit être
possible de détourner la méthode RenderControl() pour récupérer l'affichage
en mode texte.

> print calendar.month(2006,6) #visualise un mois
> print calendar.prcal(2006) #visualise une année
>
>
> Un extrait du résultat en pièce jointe.

Tu peux afficher les noms de mois et de jours en français?
Et comment tu surlignes la date du jour?

Je sais, je pinaille. :-)

Jacques


Jean

non lue,
18 juin 2006, 12:20:1518/06/2006
à
> Superbe gadget, merci Jean! Je n'avais pas noté qu'il pleuvait si fort en
> Belgique ces derniers jours :-)
>

Maintenant c'est tropical.
Un micro-climat ici je vous dis :O)

> As-tu ouvert un bug?
>

Pas pour l'instant.
Il faudrait d'abord isoler le problème et proposer un code plus court
pour la reproduction.

De plus la période d'observation ne peut être que bénéfique.
Je constate que je n'ai apparemment pas le problème aujourd'hui.
Mais je constate aussi que ce jour est en fin de ligne, peut être y
a-t-il un rapport.

On y reviendra sûrement.
Mais ce qui pourrait déjà aider c'est de dire si vous rencontrez aussi
ce problème (quitte a essayer avec la date d'hier).

A noter qu'il y a parfois des problèmes de colorisation (le background
qui persiste un peu après l'exécution) avec -fullyear.
Dans un cas comme dans l'autre un clear-host préalable "résoud" le
problème.

Suite à la prochaine averse :O)

> Jacques

Jean

non lue,
18 juin 2006, 12:20:5718/06/2006
à
> Pour info, voici une version PeJBshell :

Je n'aurai qu'un mot : canaillou ! :O)

Jean

non lue,
18 juin 2006, 12:22:4718/06/2006
à
> Il existe également une classe Calendar en .NET, mais il semble qu'elle soit
> uniquement prévue pour un affichage dans une page web, même s'il doit être
> possible de détourner la méthode RenderControl() pour récupérer l'affichage
> en mode texte.

J'avais fait quelques essais infructueux de ce côté là mais il faudra
peut être insister un peu.

Jacques Barathon [MS]

non lue,
17 juin 2006, 14:54:2617/06/2006
à
"Jean" <repo...@groupe.svp> wrote in message
news:mn.944c7d6604c33d0b.49174@windows...
<snip>

> De plus la période d'observation ne peut être que bénéfique.
> Je constate que je n'ai apparemment pas le problème aujourd'hui.
> Mais je constate aussi que ce jour est en fin de ligne, peut être y a-t-il
> un rapport.
>
> On y reviendra sûrement.
> Mais ce qui pourrait déjà aider c'est de dire si vous rencontrez aussi ce
> problème (quitte a essayer avec la date d'hier).

Curieux: j'avais le problème avec la date d'aujourd'hui quand j'ai fait le
test ce matin, mais là ça marche, alors que j'ai redémarré mon poste et
qu'il s'agit de ma première session PowerShell. Curieux!

Et je viens de faire le test de mettre la date au 17 juin, j'ai ouvert une
nouvelle session PowerShell: ça marche aussi. Alors? Le bug est arrivé à
expiration? :-)

> A noter qu'il y a parfois des problèmes de colorisation (le background qui
> persiste un peu après l'exécution) avec -fullyear.

Oui, le problème apparaît également si on passe un paramètre incorrect: le
message d'erreur hérite des couleurs gris foncé et gris clair.

> Suite à la prochaine averse :O)

J'attends avec impatience la suite ... et la prochaine averse aussi,
d'ailleurs. Car le micro-climat tropical belge s'est étendu sur l'Essonne!

Jacques


Méta-MCI

non lue,
18 juin 2006, 16:32:1218/06/2006
à
Salut !

Faut dire que j'ai eu la chance que tu poses ton choix sur une
fonctionnalité pour laquelle Python possède une librairie standard qui a les
fonctions "texte" très similaires à ta démarche. Ce ne sera pas toujours
pareil.

@+

MCI

Jean

non lue,
18 juin 2006, 15:49:2818/06/2006
à
> "Jean" <repo...@groupe.svp> wrote in message
> news:mn.944c7d6604c33d0b.49174@windows...
> <snip>
>> De plus la période d'observation ne peut être que bénéfique.
>> Je constate que je n'ai apparemment pas le problème aujourd'hui.
>> Mais je constate aussi que ce jour est en fin de ligne, peut être y a-t-il
>> un rapport.
>>
>> On y reviendra sûrement.
>> Mais ce qui pourrait déjà aider c'est de dire si vous rencontrez aussi ce
>> problème (quitte a essayer avec la date d'hier).
>
> Curieux: j'avais le problème avec la date d'aujourd'hui quand j'ai fait le
> test ce matin, mais là ça marche, alors que j'ai redémarré mon poste et qu'il
> s'agit de ma première session PowerShell. Curieux!
>

C'est le moins que l'on puisse dire :-)

> Et je viens de faire le test de mettre la date au 17 juin, j'ai ouvert une
> nouvelle session PowerShell: ça marche aussi. Alors? Le bug est arrivé à
> expiration? :-)
>

Ca ne le fait peut être *que* les jours de pluie :O)

>> A noter qu'il y a parfois des problèmes de colorisation (le background qui
>> persiste un peu après l'exécution) avec -fullyear.
>
> Oui, le problème apparaît également si on passe un paramètre incorrect: le
> message d'erreur hérite des couleurs gris foncé et gris clair.
>

Ca j'arrive a le reproduire (pas la mise en évidence du jour, mais
c'est peut être lié).

Cf code de bug-color.ps1 en fin de message.

Ici pas besoin de fermer et réouvrir la console.
Quand le problème survient il suffit de faire un cls pour recommencer.

Si j'exécute 3 fois :

(0..99)|%{.\bug-color.ps1}

ou 1 fois :

cls
(0..299)|%{.\bug-color.ps1}

le problème apparait en fin de boucle : à la 298 ème ligne écrite pour
les 3 passes, à la 300 ème pour la passe unique.

Il semble donc que c'est à partir de la 300 ème ligne.
Dans le cas des 3 passes, je suppose qu'il faut ajouter les 2 lignes de
prompt (quand on réexécute la boucle).
J'ai constaté que la longueur de la ligne n'avait pas d'importance.

Ca voudrait donc dire qu'il "faut" faire un cls toute les 300 lignes
(mise en couleur ou non) écrites dans la console si on veut jouer avec
les couleurs.
C'est un peu comme si à la 300 ème, $host.UI.RawUI n'était plus
accessible.

J'ai fait un get-variable pour voir si il n'y avait une variable qui
mettrait une limite mais je n'ai rien vu.

C'est donc une partie du problème.

Si le résultat est le même chez vous et si vous estimez que c'est assez
pour soumettre un bug, ne vous gênez pas :-) (peut être soumettre sur
le groupe anglais avant).

Reste le problème de la mise en évidence du jour ... mais c'est plus
long a tester parcequ'il faut redémarrer la console à chaque fois.

#---8<---bug-color.ps1---8<---
param(
[ConsoleColor]$bgcolor1='DarkGray',
[ConsoleColor]$fgcolor1='White'
)

$rui=$host.UI.RawUI

$oldbg=$rui.BackgroundColor
$oldfg=$rui.ForegroundColor

$rui.BackgroundColor=$bgcolor1
$rui.ForegroundColor=$fgcolor1

write-host '0'

$rui.ForegroundColor=$oldfg
$rui.BackgroundColor=$oldbg
#---8<---bug-color.ps1---8<---

Jean

non lue,
19 juin 2006, 22:42:3619/06/2006
à
> Il semble donc que c'est à partir de la 300 ème ligne.

Et je constate que 300 est le nombre de lignes maximum affichable dans
ma console (avec l'ascenceur).
Il faut sans doute adapter le code ci dessous en fonction de ce
paramètre, par ex :

(1..300)|%{$_}

Voici le nouveau code de test plus simple a utiliser :

#---8<---color.ps1---8<---
$rui=$host.UI.RawUI

$oldbg=$rui.BackgroundColor
$oldfg=$rui.ForegroundColor

$rui.BackgroundColor='DarkGray'
$rui.ForegroundColor='White'

(1..300)|%{$_}

$rui.ForegroundColor=$oldfg
$rui.BackgroundColor=$oldbg
#---8<---color.ps1---8<---

Amicalement,

PS: discussion ouverte sur le groupe EN aussi

XX.mcXX@xmxclaveauxx.xx.com Michel Claveau

non lue,
20 juin 2006, 01:41:0420/06/2006
à
Bonjour !

300 lignes, c'est le paramètre par défaut. Cela se change, avec un
clic-droit + propriétés, onglet Options & "historique des commandes"
(sur l'icone qui a servi à lancer la console).

J'espère que cela t'aura consolé.

--
@-salutations

Michel Claveau


Jean

non lue,
20 juin 2006, 10:20:1220/06/2006
à
> J'espère que cela t'aura consolé.

On voit ici le résultat de vos excursions belges :O)

Amicalement,

Jean

non lue,
21 juin 2006, 19:53:2621/06/2006
à
> Reste le problème de la mise en évidence du jour ... mais c'est plus long a
> tester parcequ'il faut redémarrer la console à chaque fois.

Je ne suis pas encore parvenu a isoler le problème mais d'après mes
tests ce serait la ligne de test :

if($_.Trim() -eq (get-date $strdate).Day)

qui n'est pas (toujours?) traitée correctement au premier démarrage.

J'ai par contre trouvé un "fix" qui consite a remplacer :

if($_.Trim() -eq (get-date $strdate).Day)
{
write-host ($_) `

par

if($_.Trim() -eq (get-date $strdate).Day)
{
write-host (''+$_) `

Jean

non lue,
1 juil. 2006, 05:22:2401/07/2006
à
> J'ai par contre trouvé un "fix"

Non ... ce n'était pas un fix.
L'aventure continue :-)

Amicalement,

Jean

non lue,
1 juil. 2006, 07:25:3201/07/2006
à
> #---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

Voici une version 0.1 dans laquelle le bug de la mise en évidence du
jour courant a été fixé grâce à MOW sur le groupe
microsoft.public.windows.powershell dans le message d'id :
Ozb94fPn...@TK2MSFTNGP02.phx.gbl

Encore merci à lui :-)

#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

#=6/2006=====================================Version 0.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 -fullyear 2006|tee -file calendar.txt
# °outputs full year 2006 grid (3 x 4) and writes it
# to calendar.txt file
#

# Thanks to MOW to have fix a previous annoying bug "current
# day not always highlighted".
# see this message on microsoft.public.windows.powershell :
# Ozb94fPn...@TK2MSFTNGP02.phx.gbl
#======================================================#

param(
[string]$strdate=(get-date).Date,


[ConsoleColor]$calendarbg='DarkGray',
[ConsoleColor]$monthyearfg='Cyan',
[ConsoleColor]$daynamefg='DarkBlue',
[ConsoleColor]$dayfg='White',
[ConsoleColor]$highlightdayfg='Red',
[ConsoleColor]$highlightdaybg='White',
[int32]$fullyear
)

#### Build an array of two first letters ####
#### localized days names ####

$firstdate=[datetime](0)
$daysnames=(0..6)|%{
($_=$firstdate.ToString("dddd").SubString(0,2))
$firstdate=$firstdate.AddDays(1)
}

$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(!$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

if($strdate -ne (get-date).Date)


## Outputs calendar month grid ##
{(' '+([string]($daystable))).Split('`n')|%{$_}}
else
## Shows current month grid and highlight current day ##
{
($daystable)|`
%{
write-host (' ') -NoNewLine
if($_.Trim() -eq (get-date $strdate).Day)
{
write-host ($_) `
-NoNewLine `
-ForegroundColor $highlightdayfg `
-BackgroundColor $highlightdaybg
}
else
{write-host ($_) -NoNewLine}
}
write-host '`r'
}
}else{
## Outputs full year grid ##

$yeartable=(0..11)

#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

Amicalement,

Jean

non lue,
7 sept. 2006, 15:11:3807/09/2006
à
#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

#=9/2006=====================================Version 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
#

# Thanks to MOW to have fix a previous ennoying bug "current


# day not always highlighted".

# See this message on microsoft.public.windows.powershell :
# Ozb94fPn...@TK2MSFTNGP02.phx.gbl
#========================================================#

param(
$vardate=(get-date).Date,


[ConsoleColor]$calendarbg='DarkGray',
[ConsoleColor]$monthyearfg='Cyan',
[ConsoleColor]$daynamefg='DarkBlue',
[ConsoleColor]$dayfg='White',
[ConsoleColor]$highlightdayfg='Red',
[ConsoleColor]$highlightdaybg='White'

)

#### Build an array of two first letters ####
#### localized days names ####

$firstdate=[datetime](0)
$daysnames=(0..6)|%{
($_=$firstdate.ToString("dddd").SubString(0,2))
$firstdate=$firstdate.AddDays(1)
}

$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}

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

if($vardate -ne (get-date).Date)


## Outputs calendar month grid ##
{(' '+([string]($daystable))).Split('`n')|%{$_}}
else
## Shows current month grid and highlight current day ##
{
($daystable)|`
%{
write-host (' ') -NoNewLine

if($_.Trim() -eq (get-date $vardate).Day)
{
write-host ($_[0]+$_[1]) `


-NoNewLine `
-ForegroundColor $highlightdayfg `
-BackgroundColor $highlightdaybg

if($_[2] -eq ' '){write-host($_[2])}


}
else
{write-host ($_) -NoNewLine}
}
write-host '`r'
}
}else{
## Outputs full year grid ##

$yeartable=(0..11)

Jean

non lue,
7 sept. 2006, 15:13:0907/09/2006
à
> #---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---
>
> #=9/2006=====================================Version 1=#
> #=========== "human readable" grid calendar ============#

Voici donc la version 1 de gadget-calendar.ps1.

Ormis la résolution d'un petit bug d'affichage j'ai retiré
le paramètre -fullyear.
En lieu et place il suffit de passer un entier (représentant l'année)
en premier paramètre.

Par souci de cohésion le (premier) paramètre -strdate a été renommé
-vardate.

On peut donc taper :

.\gadget-calendar.ps1 2008

pour afficher le calendrier complet de l'année 2008


.\gadget-calendar.ps1 "1/2008"
ou
.\gadget-calendar.ps1 "january 2008"
ou
.\gadget-calendar.ps1 "janvier 2008"

pour afficher le mois de janvier 2008

Jacques Barathon [MS]

non lue,
7 sept. 2006, 18:18:4507/09/2006
à
Merci Jean.
 
J'ai un problème d'affichage quand j'essaie le script. Une ligne vierge s'intercale entre deux lignes du calendrier. Je n'ai pas le temps de débugger ce soir, j'ai juste constaté que le problème apparaît avec la ligne suivante:
 
Scripts[28/2]> ([string]$daystable).split('`n')
                  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
Scripts[28/2]>
 
L'affichage de $daystable ne montre pourtant pas de ligne supplémentaire, ni de caractère parasite pouvant provoquer un retour à la ligne intempestif. Je creuserai demain...
 
Jacques
 
"Jean" <repo...@groupe.svp> a écrit dans le message de news: mn.3cf97d697fc8243c.56820@windows...

Jean

non lue,
7 sept. 2006, 19:05:1207/09/2006
à
> J'ai un problème d'affichage quand j'essaie le script. Une ligne vierge
> s'intercale entre deux lignes du calendrier. Je n'ai pas le temps de débugger
> ce soir, j'ai juste constaté que le problème apparaît avec la ligne suivante

Merci du retour.
C'est assez gênant en effet.
Je ne reproduis pas le problème ici avec la RC1.
Je pense que c'est une question de version (vous utilisez déjà la RC 2
je crois).
Dans l'affirmative, reste à voir si il sagit d'un bug ou d'une
différence de traitement dans la RC2.

Jacques Barathon [MS]

non lue,
8 sept. 2006, 03:37:1208/09/2006
à
"Jean" <repo...@groupe.svp> a écrit dans le message de news:
mn.40417d69d9c730c4.56820@windows...

J'utilise une version post-RC1, mais ce n'est pas la RC2. J'essaierai de
creuser le sujet dans la journée.

Jacques

Jean

non lue,
8 sept. 2006, 05:30:1808/09/2006
à
> J'utilise une version post-RC1, mais ce n'est pas la RC2. J'essaierai de
> creuser le sujet dans la journée.

C'est sympa :-)

Juste une idée avant d'incriminer la version.

Voir si ça ne se résoudrait pas en mettant au tout début du script :

$oldOFS=$OFS
$OFS=" "

et à la toute fin du script

$OFS=$oldOFS

Jacques Barathon [MS]

non lue,
8 sept. 2006, 18:32:3708/09/2006
à
"Jean" <repo...@groupe.svp> a écrit dans le message de news:
mn.42b27d69f89748f3.56820@windows...

>> J'utilise une version post-RC1, mais ce n'est pas la RC2. J'essaierai de
>> creuser le sujet dans la journée.
>
> C'est sympa :-)

Bon, manque de temps aujourd'hui, je m'y mettrai ce week-end :-)

> Juste une idée avant d'incriminer la version.
>
> Voir si ça ne se résoudrait pas en mettant au tout début du script :
>
> $oldOFS=$OFS
> $OFS=" "
>
> et à la toute fin du script
>
> $OFS=$oldOFS

J'avais déjà essayé de modifier $OFS dans mon test rapide en mode debug,
sans effet positif.

Jacques

Jean

non lue,
9 sept. 2006, 02:09:4609/09/2006
à
> Bon, manque de temps aujourd'hui, je m'y mettrai ce week-end :-)

Pourvu qu'il pleuve :-)

Jean

non lue,
9 sept. 2006, 07:29:2909/09/2006
à
> Pourvu qu'il pleuve

En attendant je viens de fixer un problème avec le premier siècle.

Pour les années 1 à 99 quand le premier paramètre est une chaîne il
*faut* préfixer l'année de 0 à concurrence d'une longueur de 4.
Soit 0001 à 0099.

par ex :

.\gadget-calendar "3/0026"

pour afficher le mois de mars de l'année 26

Ce n'est pas nécessaire pour les années 100 à 999.

.\gadget-calendar "7/999"

Lorsqu'un entier est passé en paramètre (pour avoir une année complète)
ce n'est pas nécessaire non plus.

.\gadget-calendar 26

pour afficher l'année 26.

Je poste le script corrigé en réponse à ce message.

Jean

non lue,
9 sept. 2006, 07:32:3309/09/2006
à
> Je poste le script corrigé en réponse à ce message

#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

#=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 :
# Ozb94fPn...@TK2MSFTNGP02.phx.gbl
#========================================================#

param(
$vardate=(get-date).Date,
[ConsoleColor]$calendarbg='DarkGray',
[ConsoleColor]$monthyearfg='Cyan',
[ConsoleColor]$daynamefg='DarkBlue',
[ConsoleColor]$dayfg='White',
[ConsoleColor]$highlightdayfg='Red',
[ConsoleColor]$highlightdaybg='White'
)

## Stores actual $OFS and set it to a space char ##
$oldOFS=$OFS
$OFS=" "

#### Build an array of two first letters ####
#### localized days names ####

$firstdate=[datetime](0)
$daysnames=(0..6)|%{
($_=$firstdate.ToString("dddd").SubString(0,2))
$firstdate=$firstdate.AddDays(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")

"Int32"){$fullyear=$vardate.ToString("0000")}

$year=$fullyear


$monthnames=@()
for($i=1;$i -lt 13;$i++){
$monthdays=

build_date_table(get-date('1/'+[string]$i+'/'+$year))

## Restores OFS to its previous value
$OFS=$oldOFS
#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

#Amicalement,

Jean

non lue,
26 sept. 2006, 10:28:3926/09/2006
à
> 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.

Jean

non lue,
26 sept. 2006, 10:33:4326/09/2006
à
> Je poste le script corrigé en réponse à ce message.

#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---

#=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 :
# Ozb94fPn...@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...@microsoft.com
# To James Truher to have fix this RC2 compatibility problem.


# See this message on microsoft.public.windows.powershell :

# OZZcK3P4...@TK2MSFTNGP04.phx.gbl
#
#========Tested on PowerShell 1 RC1 (1.0.9567.1)=========#

param(
$vardate=(get-date).Date,
[ConsoleColor]$calendarbg="DarkGray",
[ConsoleColor]$monthyearfg="Cyan",
[ConsoleColor]$daynamefg="DarkBlue",
[ConsoleColor]$dayfg="White",
[ConsoleColor]$highlightdayfg="Red",
[ConsoleColor]$highlightdaybg="White"
)

## Stores actual $OFS and set it to a space char ##
$oldOFS=$OFS
$OFS=" "

#### Build an array of two first letters ####


#### localized days names ####

$firstdate=[datetime](0)
$daysnames=(0..6)|%{
($_=$firstdate.ToString("dddd").SubString(0,2))
$firstdate=$firstdate.AddDays(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")

{$fullyear=$vardate.ToString("0000")}

$year=$fullyear


$monthnames=@()
for($i=1;$i -lt 13;$i++){
$monthdays=

build_date_table(get-date("1/"+[string]$i+"/"+$year))

## Restores OFS to its previous value
$OFS=$oldOFS
#---8<---gadget-calendar.ps1---Jean-JMST-Belgium---8<---


#Amicalement,

--
Jean - JMST
Belgium


Jean

non lue,
26 sept. 2006, 13:11:5426/09/2006
à
> par des double guillemets

par des guillemets
(english spaghetti :-) )

Jacques Barathon [MS]

non lue,
26 sept. 2006, 19:24:3126/09/2006
à
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" <repo...@groupe.svp> a écrit dans le message de news:

mn.d3e17d699c60ab54.56820@windows...

Jean

non lue,
27 sept. 2006, 05:39:2627/09/2006
à
> L'exécution du script étale la couleur gris sur toutes les lignes où le
> calendrier s'affiche,

Je pense que c'est le bug dont j'avais parlé sur windows.powershell
(mn.a0c47d6619889097.49174@windows).

Je l'avais rapporté sur Connect :
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=146655&SiteID=99&wa=wsignin1.0

... résolu : By Design ...

C'est lié à la taille du tampon d'affichage de la console.
Avec l'installation par défaut de la RC2, pour reproduire le phénomène,
faire

cls

puis exécuter le script suivant :

#---8<---color.ps1---8<---
$rui=$host.UI.RawUI

$oldbg=$rui.BackgroundColor
$oldfg=$rui.ForegroundColor

$rui.BackgroundColor='DarkGray'
$rui.ForegroundColor='White'

(1..3000)|%{$_}

$rui.ForegroundColor=$oldfg
$rui.BackgroundColor=$oldbg
#---8<---color.ps1---8<---

... pour revenir à une situation normale il faut faire un "cls" dans la
console.

Jean

non lue,
27 sept. 2006, 06:18:2527/09/2006
à
> Je l'avais rapporté sur Connect :
>
> https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=146655&SiteID=99&wa=wsignin1.0
>
> ... résolu : By Design ...

oups ... c'est celui-ci :

https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=146656&SiteID=99&wa=wsignin1.0

... Résolu : Reporté (ouf :-) )

0 nouveau message