Skip to content

Commit

Permalink
example(textinput): added example
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Apr 15, 2023
1 parent fe5a80d commit 9d14585
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
30 changes: 30 additions & 0 deletions _examples/interactive_textinput/password/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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)
input := "Hello, World!"
for _, r := range input {
if r == '\n' {
keyboard.SimulateKeyPress(keys.Enter)
} else {
keyboard.SimulateKeyPress(r)
}
time.Sleep(time.Millisecond * 250)
}

keyboard.SimulateKeyPress(keys.Enter)
}()
}
}
10 changes: 10 additions & 0 deletions _examples/interactive_textinput/password/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import "github.com/pterm/pterm"

func main() {
result, _ := pterm.DefaultInteractiveTextInput.WithMask("*").Show("Enter your password")

logger := pterm.DefaultLogger
logger.Info("Password received", logger.Args("password", result))
}

0 comments on commit 9d14585

Please sign in to comment.