-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from KarolosLykos/issue-418-proposal_option_t…
…o_change_checkmarks_in_interactice_multiselect Fixes #418
- Loading branch information
Showing
8 changed files
with
265 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
_examples/interactive_multiselect/custom-checkmarks/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# interactive_multiselect/custom-checkmark | ||
|
||
![Animation](animation.svg) | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"atomicgo.dev/keyboard/keys" | ||
|
||
"github.com/pterm/pterm" | ||
) | ||
|
||
func main() { | ||
var options []string | ||
|
||
for i := 0; i < 5; i++ { | ||
options = append(options, fmt.Sprintf("Option %d", i)) | ||
} | ||
|
||
printer := pterm.DefaultInteractiveMultiselect.WithOptions(options) | ||
printer.Filter = false | ||
printer.KeyConfirm = keys.Enter | ||
printer.KeySelect = keys.Space | ||
printer.Checkmark = pterm.Checkmark{Checked: "+", Unchecked: "-"} | ||
selectedOptions, _ := printer.Show() | ||
pterm.Info.Printfln("Selected options: %s", pterm.Green(selectedOptions)) | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"atomicgo.dev/keyboard" | ||
"atomicgo.dev/keyboard/keys" | ||
) | ||
|
||
// ------ Automation for CI ------ | ||
// You can ignore this function, it is used to automatically run the demo and generate the example animation in our CI system. | ||
func init() { | ||
if os.Getenv("CI") == "true" { | ||
go func() { | ||
time.Sleep(time.Second) | ||
for i := 0; i < 10; i++ { | ||
keyboard.SimulateKeyPress(keys.Down) | ||
if i%2 == 0 { | ||
time.Sleep(time.Millisecond * 100) | ||
keyboard.SimulateKeyPress(keys.Enter) | ||
} | ||
time.Sleep(time.Millisecond * 500) | ||
} | ||
time.Sleep(time.Second) | ||
|
||
for _, s := range "fuzzy" { | ||
keyboard.SimulateKeyPress(s) | ||
time.Sleep(time.Millisecond * 150) | ||
} | ||
|
||
time.Sleep(time.Second) | ||
|
||
for i := 0; i < 2; i++ { | ||
keyboard.SimulateKeyPress(keys.Down) | ||
time.Sleep(time.Millisecond * 300) | ||
} | ||
|
||
keyboard.SimulateKeyPress(keys.Enter) | ||
time.Sleep(time.Millisecond * 350) | ||
keyboard.SimulateKeyPress(keys.Tab) | ||
}() | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
_examples/interactive_multiselect/custom-checkmarks/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"atomicgo.dev/keyboard/keys" | ||
|
||
"github.com/pterm/pterm" | ||
) | ||
|
||
func main() { | ||
var options []string | ||
|
||
for i := 0; i < 5; i++ { | ||
options = append(options, fmt.Sprintf("Option %d", i)) | ||
} | ||
|
||
printer := pterm.DefaultInteractiveMultiselect.WithOptions(options) | ||
printer.Filter = false | ||
printer.KeyConfirm = keys.Enter | ||
printer.KeySelect = keys.Space | ||
printer.Checkmark = pterm.Checkmark{Checked: "+", Unchecked: "-"} | ||
selectedOptions, _ := printer.Show() | ||
pterm.Info.Printfln("Selected options: %s", pterm.Green(selectedOptions)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package pterm_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"atomicgo.dev/keyboard" | ||
"atomicgo.dev/keyboard/keys" | ||
"github.com/MarvinJWendt/testza" | ||
|
||
"github.com/pterm/pterm" | ||
) | ||
|
||
func TestInteractiveMultiselectPrinter_Show(t *testing.T) { | ||
go func() { | ||
keyboard.SimulateKeyPress(keys.Down) | ||
keyboard.SimulateKeyPress(keys.Down) | ||
keyboard.SimulateKeyPress(keys.Enter) | ||
keyboard.SimulateKeyPress(keys.Tab) | ||
}() | ||
result, _ := pterm.DefaultInteractiveMultiselect.WithOptions([]string{"a", "b", "c", "d", "e"}).WithDefaultOptions([]string{"b"}).Show() | ||
testza.AssertEqual(t, []string{"b", "c"}, result) | ||
} | ||
|
||
func TestInteractiveMultiselectPrinter_Show_MaxHeightSlidingWindow(t *testing.T) { | ||
go func() { | ||
keyboard.SimulateKeyPress(keys.Up) | ||
keyboard.SimulateKeyPress(keys.Up) | ||
keyboard.SimulateKeyPress(keys.Enter) | ||
keyboard.SimulateKeyPress(keys.Tab) | ||
}() | ||
result, _ := pterm.DefaultInteractiveMultiselect.WithOptions([]string{"a", "b", "c", "d", "e", "f"}).WithDefaultOptions([]string{"b"}).Show() | ||
testza.AssertEqual(t, []string{"b", "e"}, result) | ||
} | ||
|
||
func TestInteractiveMultiselectPrinter_WithDefaultText(t *testing.T) { | ||
p := pterm.DefaultInteractiveMultiselect.WithDefaultText("default") | ||
testza.AssertEqual(t, p.DefaultText, "default") | ||
} | ||
|
||
func TestInteractiveMultiselectPrinter_WithDefaultOption(t *testing.T) { | ||
p := pterm.DefaultInteractiveMultiselect.WithDefaultOptions([]string{"default"}) | ||
testza.AssertEqual(t, p.DefaultOptions, []string{"default"}) | ||
} | ||
|
||
func TestInteractiveMultiselectPrinter_WithOptions(t *testing.T) { | ||
p := pterm.DefaultInteractiveMultiselect.WithOptions([]string{"a", "b", "c"}) | ||
testza.AssertEqual(t, p.Options, []string{"a", "b", "c"}) | ||
} | ||
|
||
func TestInteractiveMultiselectPrinter_WithMaxHeight(t *testing.T) { | ||
p := pterm.DefaultInteractiveMultiselect.WithMaxHeight(1337) | ||
testza.AssertEqual(t, p.MaxHeight, 1337) | ||
} | ||
|
||
func TestInteractiveMultiselectPrinter_WithKeySelect(t *testing.T) { | ||
p := pterm.DefaultInteractiveMultiselect.WithKeySelect(keys.Left).WithOptions([]string{"a", "b", "c"}) | ||
testza.AssertEqual(t, p.KeySelect, keys.Left) | ||
} | ||
|
||
func TestInteractiveMultiselectPrinter_WithKeyConfirm(t *testing.T) { | ||
p := pterm.DefaultInteractiveMultiselect.WithKeyConfirm(keys.Left).WithOptions([]string{"a", "b", "c"}) | ||
testza.AssertEqual(t, p.KeyConfirm, keys.Left) | ||
} | ||
|
||
func TestInteractiveMultiselectPrinter_WithCheckmark(t *testing.T) { | ||
p := pterm.DefaultInteractiveMultiselect.WithCheckmark(pterm.Checkmark{Checked: "+", Unchecked: "-"}).WithOptions([]string{"a", "b", "c"}) | ||
testza.AssertEqual(t, p.Checkmark, pterm.Checkmark{Checked: "+", Unchecked: "-"}) | ||
} |