Skip to content

Commit c62d602

Browse files
Merge pull request #175 from PowerShellWeb/turtles-on-a-text-path
Turtle 0.1.9
2 parents 50c909d + b256277 commit c62d602

18 files changed

+415
-20
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## Turtle 0.1.9:
2+
3+
* Turtle Text Path Support
4+
* `Turtle.get/set_Text` controls the text (#167)
5+
* `Turtle.get/set_TextAttribute` sets text attributes (#168)
6+
* `Turtle.get/set_TextAnimation` animates text attributes (#171)
7+
* `Get-Turtle` parameter improvements (#169, #170)
8+
* `Get-Turtle` tracks invocation info (#157)
9+
10+
---
11+
112
## Turtle 0.1.8:
213

314
* Turtle Performance

Commands/Get-Turtle.ps1

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function Get-Turtle {
3030
Each argument can be the name of a move of the turtle object.
3131
3232
After a member name is encountered, subsequent arguments will be passed to the member as parameters.
33+
34+
Any parameter that begins with whitespace will be split into multiple words.
3335
.EXAMPLE
3436
# We can write shapes as a series of steps
3537
turtle "
@@ -370,6 +372,10 @@ function Get-Turtle {
370372
$memberNames = $memberNames | Sort-Object @{Expression={ $_.Length };Descending=$true}, name
371373
# Create a new turtle object in case we have no turtle input.
372374
$currentTurtle = [PSCustomObject]@{PSTypeName='Turtle'}
375+
376+
$invocationInfo = $MyInvocation
377+
$invocationInfo |
378+
Add-Member ScriptProperty History {Get-History -Id $this.HistoryId} -Force
373379
}
374380

375381
process {
@@ -381,21 +387,31 @@ function Get-Turtle {
381387
return $PSBoundParameters.InputObject
382388
}
383389

390+
if (-not $currentTurtle.Invocations) {
391+
$currentTurtle | Add-Member NoteProperty Invocations -Force @(,$invocationInfo)
392+
} elseif ($currentTurtle.Invocations -is [object[]]) {
393+
$currentTurtle.Invocations += $invocationInfo
394+
}
395+
384396

385397
# First we want to split each argument into words.
386398
# This way, it is roughly the same if you say:
387399
# * `turtle 'forward 10'`
388400
# * `turtle forward 10`
389401
# * `turtle 'forward', 10`
390402
$wordsAndArguments = @(foreach ($arg in $ArgumentList) {
391-
# If the argument is a string, split it by whitespace.
403+
# If the argument is a string, and it starts with whitespace
392404
if ($arg -is [string]) {
393-
$arg -split '\s{1,}'
405+
if ($arg -match '^[\r\n\s]+') {
406+
$arg -split '\s{1,}'
407+
} else {
408+
$arg
409+
}
394410
} else {
395411
# otherwise, leave the argument alone.
396412
$arg
397413
}
398-
})
414+
})
399415

400416
# Now that we have a series of words, we can process them.
401417
# We want to keep track of the current member,
@@ -406,7 +422,7 @@ function Get-Turtle {
406422

407423
# To do this in one pass, we will iterate through the words and arguments.
408424
# We use an indexed loop so we can skip past claimed arguments.
409-
for ($argIndex =0; $argIndex -lt $wordsAndArguments.Length; $argIndex++) {
425+
for ($argIndex =0; $argIndex -lt $wordsAndArguments.Length; $argIndex++) {
410426
$arg = $wordsAndArguments[$argIndex]
411427
# If the argument is not in the member names list, we can complain about it.
412428
if ($arg -notin $memberNames) {
@@ -415,7 +431,6 @@ function Get-Turtle {
415431
}
416432
continue
417433
}
418-
419434

420435
# If we have a current member, we can invoke it or get it.
421436
$currentMember = $arg
@@ -478,7 +493,16 @@ function Get-Turtle {
478493

479494
# If we have any arguments,
480495
if ($argList) {
481-
# lets try to set it.
496+
# Check to see if they are strongly typed
497+
if ($memberInfo -is [Management.Automation.Runspaces.ScriptPropertyData]) {
498+
$desiredType = $memberInfo.SetScriptBlock.Ast.ParamBlock.Parameters.StaticType
499+
if ($desiredType -is [Type] -and
500+
$argList.Length -eq 1 -and
501+
$argList[0] -as $desiredType) {
502+
$argList = $argList[0] -as $desiredType
503+
}
504+
}
505+
# lets try to set it.
482506
$currentTurtle.$currentMember = $argList
483507
} else {
484508
# otherwise, lets get the property
@@ -492,9 +516,9 @@ function Get-Turtle {
492516
# Properties being returned will largely be strings or numbers, and these will always output directly.
493517
if ($null -ne $stepOutput -and -not ($stepOutput.pstypenames -eq 'Turtle')) {
494518
# Output the step
495-
$stepOutput
519+
$stepOutput
496520
# and set the output turtle to false.
497-
$outputTurtle = $false
521+
$outputTurtle = $false
498522
} elseif ($null -ne $stepOutput) {
499523
# Set the current turtle to the step output.
500524
$currentTurtle = $stepOutput
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Loading

Examples/TurtlesOnATextPath.svg

Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
if ($PSScriptRoot) { Push-Location $PSScriptRoot}
2+
3+
$turtlesOnATextPath = turtle rotate 90 jump 50 rotate -90 ArcRight 50 60 text 'turtles on a text path' textattribute @{'font-size'=36}
4+
$turtlesOnATextPath | Save-Turtle ./TurtlesOnATextPath.svg
5+
6+
7+
$textPath2 = turtle rotate 90 jump 50 rotate -90 ArcRight 50 -60
8+
9+
$turtlesOnATextPath =
10+
turtle rotate 90 jump 50 rotate -90 rotate -30 forward 200 text 'turtles on a text path' morph @(
11+
turtle rotate 90 jump 50 rotate -90 rotate -10 forward 200
12+
turtle rotate 90 jump 50 rotate -90 rotate -5 forward 200
13+
turtle rotate 90 jump 50 rotate -90 rotate -10 forward 200
14+
) textAnimation ([Ordered]@{
15+
attributeName = 'fill' ; values = "#4488ff;#224488;#4488ff" ; repeatCount = 'indefinite'; dur = "4.2s"
16+
},[Ordered]@{
17+
attributeName = 'font-size' ; values = "1em;1.3em;1em" ; repeatCount = 'indefinite'; dur = "4.2s"
18+
},[Ordered]@{
19+
attributeName = 'textLength' ; values = "100%;1%;100%" ; repeatCount = 'indefinite'; dur = "4.2s"
20+
},[Ordered]@{
21+
attributeName = 'x' ; values = "-100%; 100%; -50%" ; repeatCount = 'indefinite'; dur = "4.2s"
22+
})
23+
$turtlesOnATextPath | Save-Turtle ./TurtlesOnATextPath-Morph.svg
24+
25+
26+
turtle rotate -90 circle 42 text "a turtle circle" textattribute ([Ordered]@{
27+
'x'='5%'
28+
'dominant-baseline'='text-before-edge'
29+
'letter-spacing'='.16em'
30+
}) save ./TurtlesOnATextPath-ATurtleCircle.svg
31+
32+
if ($PSScriptRoot) { Pop-Location }

Turtle.psd1

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
# Version number of this module.
3-
ModuleVersion = '0.1.8'
3+
ModuleVersion = '0.1.9'
44
# Description of the module
55
Description = "Turtles in a PowerShell"
66
# Script module or binary module file associated with this manifest.
@@ -37,15 +37,14 @@
3737
# A URL to the license for this module.
3838
LicenseURI = 'https://github.com/PowerShellWeb/Turtle/blob/main/LICENSE'
3939
ReleaseNotes = @'
40-
## Turtle 0.1.8:
41-
42-
* Turtle Performance
43-
* Improving `.Steps` performance (#159)
44-
* Reducing Turtle Verbosity (#160)
45-
* New Moves:
46-
* Step (#161)
47-
* Forward,Teleport, and GoTo now use Step (#161)
48-
* New Reflection Examples (#162)
40+
## Turtle 0.1.9:
41+
42+
* Turtle Text Path Support
43+
* `Turtle.get/set_Text` controls the text (#167)
44+
* `Turtle.get/set_TextAttribute` sets text attributes (#168)
45+
* `Turtle.get/set_TextAnimation` animates text attributes (#171)
46+
* `Get-Turtle` parameter improvements (#169, #170)
47+
* `Get-Turtle` tracks invocation info (#157)
4948
5049
---
5150

0 commit comments

Comments
 (0)