Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom select/confirm key for interactive printer
- Loading branch information
Showing
5 changed files
with
123 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# interactive_multiselect/demo_custom | ||
|
||
![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.NoFilter = true | ||
printer.KeyConfirm = keys.Enter | ||
printer.KeySelect = keys.Space | ||
selectedOptions, _ := printer.Show() | ||
pterm.Info.Printfln("Selected options: %s", pterm.Green(selectedOptions)) | ||
} | ||
``` |
10 changes: 10 additions & 0 deletions
10
_examples/interactive_multiselect/demo_custom/animation.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,31 @@ | ||
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) | ||
keyboard.SimulateKeyPress(keys.Down) | ||
time.Sleep(time.Millisecond * 100) | ||
keyboard.SimulateKeyPress(keys.Space) | ||
|
||
time.Sleep(time.Millisecond * 300) | ||
|
||
keyboard.SimulateKeyPress(keys.Down) | ||
time.Sleep(time.Millisecond * 100) | ||
keyboard.SimulateKeyPress(keys.Space) | ||
|
||
time.Sleep(time.Millisecond * 300) | ||
keyboard.SimulateKeyPress(keys.Enter) | ||
}() | ||
} | ||
} |
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,23 @@ | ||
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.NoFilter = true | ||
printer.KeyConfirm = keys.Enter | ||
printer.KeySelect = keys.Space | ||
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