Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
More flexible way to add hierarchies
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Nov 28, 2020
1 parent 189460b commit 0d106bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
29 changes: 17 additions & 12 deletions internal/page/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,28 @@ func add(session *Session, cmd command.Command) (result string, err error) {

// "Add" commands to process
batch := make([]*AddCommandBatchItem, 0)
if len(cmd.Lines) == 0 {

// top command
indent := 0
if len(cmd.Values) > 0 {
// single command
batch = append(batch, &AddCommandBatchItem{
Command: &cmd,
})
} else {
// batch
for _, line := range cmd.Lines {
childCmd, err := command.Parse(line, false)
if err != nil {
return "", err
}
childCmd.Name = "add"
batch = append(batch, &AddCommandBatchItem{
Command: childCmd,
})
indent = 2
}

// sub-commands
for _, line := range cmd.Lines {
childCmd, err := command.Parse(line, false)
if err != nil {
return "", err
}
childCmd.Name = "add"
childCmd.Indent += indent
batch = append(batch, &AddCommandBatchItem{
Command: childCmd,
})
}

// list of control IDs
Expand Down
5 changes: 3 additions & 2 deletions tests/test-add-command.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ try {
pglet_send "add to=page at=0
stack width=600px horizontalAlign=stretch
textbox id=fullName value='someone' label=Name placeholder='Your name, please' description='That\'s your name'
textbox id=bio label='Bio' description='A few words about yourself' value='Line1\nLine2' multiline=true
stack id=buttons horizontal=true
textbox id=bio label='Bio' description='A few words about yourself' value='Line1\nLine2' multiline=true"

pglet_send "add stack id=buttons horizontal=true
button id=submit text=Submit primary=yes event=btn_event
button id=cancel event=btn_event2"

Expand Down

0 comments on commit 0d106bf

Please sign in to comment.