diff --git a/PSWorkItem.psd1 b/PSWorkItem.psd1 index 6973c23..3876cba 100644 --- a/PSWorkItem.psd1 +++ b/PSWorkItem.psd1 @@ -4,7 +4,7 @@ @{ RootModule = 'PSWorkItem.psm1' - ModuleVersion = '0.4.0' + ModuleVersion = '0.5.0' CompatiblePSEditions = 'Core' GUID = '4d3ff215-69ea-4fe6-8ad6-97ffc3a15bfb' Author = 'Jeff Hicks' @@ -33,7 +33,7 @@ # ReleaseNotes = '' # Prerelease = '' # RequireLicenseAcceptance = $false - ExternalModuleDependencies = @(@{ModuleName="mySQLite";ModuleVersion="0.9.2"}) + ExternalModuleDependencies = "MySQLite" } # End of PSData hashtable } # End of PrivateData hashtable diff --git a/PSWorkItem.psm1 b/PSWorkItem.psm1 index 58c91a3..7e9af52 100644 --- a/PSWorkItem.psm1 +++ b/PSWorkItem.psm1 @@ -1,7 +1,7 @@ -Get-Childitem $psscriptroot\functions\*.ps1 -recurse | -Foreach-Object { -. $_.FullName +Get-ChildItem $psscriptroot\functions\*.ps1 -Recurse | +ForEach-Object { + . $_.FullName } #region class definitions @@ -20,7 +20,7 @@ class PSWorkItem { #this will be last resort GUID to ensure uniqueness hidden[guid]$TaskID = (New-Guid).Guid - PSWorkItem ([string]$Name,[string]$Category) { + PSWorkItem ([string]$Name, [string]$Category) { $this.Name = $Name $this.Category = $Category } @@ -51,28 +51,36 @@ class PSWorkItemDatabase { } #Add a dynamic type extension to the PSWorkItem class -Update-TypeData -TypeName PSWorkitem -MemberType ScriptProperty -MemberName OverDue -Value {$this.DueDate -le (Get-Date)} -Force -Update-TypeData -TypeName PSWorkItem -MemberType ScriptProperty -MemberName "TimeRemaining" -Value {New-Timespan -end $this.DueDate -start (Get-Date)} -force -Update-TypeData -TypeName PSWorkItemArchive -MemberType AliasProperty -MemberName "CompletedDate" -Value 'TaskModified' -force +Update-TypeData -TypeName PSWorkitem -MemberType ScriptProperty -MemberName OverDue -Value { $this.DueDate -le (Get-Date) } -Force +Update-TypeData -TypeName PSWorkItem -MemberType ScriptProperty -MemberName "TimeRemaining" -Value { New-TimeSpan -End $this.DueDate -Start (Get-Date) } -Force +Update-TypeData -TypeName PSWorkItemArchive -MemberType AliasProperty -MemberName "CompletedDate" -Value 'TaskModified' -Force #endregion #make this variable global instead of exporting so that I don't have to use Export-ModuleMember 7/28/2022 JDH -$global:PSWorkItemPath = Join-Path -path $HOME -childpath "PSWorkItem.db" +$global:PSWorkItemPath = Join-Path -Path $HOME -ChildPath "PSWorkItem.db" + <# - Default categories when creating a new database file. - This will be a module-scoped variable +Default categories when creating a new database file. +This will be a module-scoped variable #> -$PSWorkItemDefaultCategories = "Work","Personal","Project","Other" +$PSWorkItemDefaultCategories = "Work", "Personal", "Project", "Other" + +#a global hashtable used for formatting PSWorkItems +$global:PSWorkItemCategory = @{ + "Work" = $PSStyle.Foreground.Cyan + "Personal" = $PSStyle.Foreground.Green +} -Register-ArgumentCompleter -CommandName New-PSWorkItem,Get-PSWorkItem,Set-PSWorkItem,Get-PSWorkItemArchive -ParameterName Category -ScriptBlock { +Register-ArgumentCompleter -CommandName New-PSWorkItem, Get-PSWorkItem, Set-PSWorkItem, Get-PSWorkItemArchive -ParameterName Category -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) #PowerShell code to populate $wordtoComplete - Get-PSWorkItemCategory | Where-Object {$_.category -Like "$wordToComplete*"} | - Select-Object -Property Category,@{Name="Description";Expression={ - $_.description -match "\w+" ? $_.description : "no description"}} | + Get-PSWorkItemCategory | Where-Object { $_.category -Like "$wordToComplete*" } | + Select-Object -Property Category, @{Name = "Description"; Expression = { + $_.description -match "\w+" ? $_.description : "no description" } + } | ForEach-Object { # completion text,listitem text,result type,Tooltip [System.Management.Automation.CompletionResult]::new($_.category, $_.category, 'ParameterValue', $_.description) diff --git a/README.md b/README.md index ad5d9a9..ea8de6c 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,31 @@ If you are running the command in the PowerShell console or VSCode, overdue task Read the examples for [Get-PSWorkItem](docs/Get-PSWorkItem.md) for other ways to use this command including custom format views. +### PSWorkItemCategory + +In addition to formatting overdue and imminent due dates, the module also provides a mechanism to add highlighting of specific categores. Importing the module will create a global variable called `PSWorkItemCategory`. The key will be a category name. The value will be a $PSStyle or ANSI escape sequence. These are the module defaults. + +```powershell +$global:PSWorkItemCategory = @{ + "Work" = $PSStyle.Foreground.Cyan + "Personal" = $PSStyle.Foreground.Green +} +``` + +You can modify this hashtable as you would any other hashtable. + +```powershell +$PSWorkItemCategory.Add("Event","`e[38;5;153m") +``` + +The entry will have no effect unless the category is definied in the database. + +> Note that when you view the hashtable, you won't see any values because they escape sequences are non-printable., + +![colorized categories](images/psworkitemcategory.png) + +Category highlighting is only available in the default view. + ## Updating Tasks Use [Set-PSWorkItem](docs/Set-PSWorkItem.md) or its alias `swi` to update a task based on its ID. diff --git a/changelog.md b/changelog.md index ca10ab0..a254ee0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog for PSWorkItem +## 0.5.0 + ++ Fixed module manifest. [Issue #1](https://github.com/jdhitsolutions/PSWorkItem/issues/1) ++ Added a feature to highlight tasks based on category. The module defines a global variable, `$PSWorkItemCategory`, which is a hashtable. The key is the category and the value is the `$PSStyle` or ANSI sequence. The default format view is configured to use these settings. ++ Updated `README.md`. + ## 0.4.0 + Updated `README`. diff --git a/formats/psworkitem.format.ps1xml b/formats/psworkitem.format.ps1xml index 6b878d8..c42f3a8 100644 --- a/formats/psworkitem.format.ps1xml +++ b/formats/psworkitem.format.ps1xml @@ -70,7 +70,8 @@ https://github.com/jdhitsolutions/PSScriptTools "{0}{1}{2}" -f $psstyle.Foreground.brightyellow, $_.name, $psstyle.reset } else { - $_.name + + "$($PSWorkItemCategory["$($_.category)"])$($_.name)$($PSStyle.Reset)" } } else { @@ -89,7 +90,7 @@ https://github.com/jdhitsolutions/PSScriptTools "{0}{1}{2}" -f $psstyle.Foreground.brightyellow, $_.Description, $psstyle.reset } else { - $_.Description + "$($PSWorkItemCategory["$($_.category)"])$($_.Description)$($PSStyle.Reset)" } } else { @@ -108,7 +109,7 @@ https://github.com/jdhitsolutions/PSScriptTools "{0}{1}{2}" -f $psstyle.Foreground.brightyellow, $_.DueDate, $psstyle.reset } else { - $_.DueDate + "$($PSWorkItemCategory["$($_.category)"])$($_.duedate)$($PSStyle.Reset)" } } else { @@ -117,10 +118,24 @@ https://github.com/jdhitsolutions/PSScriptTools - Category + + if ($host.name -match "console|code") { + "$($PSWorkItemCategory["$($_.category)"])$($_.category)$($PSStyle.Reset)" + } + else { + $_.category + } + - Progress + + if ($host.name -match "console|code") { + "$($PSWorkItemCategory["$($_.category)"])$($_.progress)$($PSStyle.Reset)" + } + else { + $_.progress + } + diff --git a/formats/psworkitemdatabase.format.ps1xml b/formats/psworkitemdatabase.format.ps1xml index 6d089ec..885a226 100644 --- a/formats/psworkitemdatabase.format.ps1xml +++ b/formats/psworkitemdatabase.format.ps1xml @@ -9,7 +9,6 @@ https://github.com/jdhitsolutions/PSScriptTools - default PSWorkItemDatabase diff --git a/images/psworkitemcategory.png b/images/psworkitemcategory.png new file mode 100644 index 0000000..ad822e2 Binary files /dev/null and b/images/psworkitemcategory.png differ