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 #360 from pterm/358-implement-interactive-printers
- Loading branch information
Showing
26 changed files
with
1,455 additions
and
21 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
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"atomicgo.dev/keyboard" | ||
) | ||
|
||
// ------ 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 * 2) | ||
keyboard.SimulateKeyPress('y') | ||
}() | ||
} | ||
} |
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,18 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/pterm/pterm" | ||
) | ||
|
||
func main() { | ||
result, _ := pterm.DefaultInteractiveConfirm.Show() | ||
pterm.Println() // Blank line | ||
pterm.Info.Printfln("You answered: %s", boolToText(result)) | ||
} | ||
|
||
func boolToText(b bool) string { | ||
if b { | ||
return pterm.Green("Yes") | ||
} | ||
return pterm.Red("No") | ||
} |
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) | ||
}() | ||
} | ||
} |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pterm/pterm" | ||
) | ||
|
||
func main() { | ||
var options []string | ||
|
||
for i := 0; i < 100; i++ { | ||
options = append(options, fmt.Sprintf("Option %d", i)) | ||
} | ||
|
||
for i := 0; i < 5; i++ { | ||
options = append(options, fmt.Sprintf("You can use fuzzy searching (%d)", i)) | ||
} | ||
|
||
selectedOptions, _ := pterm.DefaultInteractiveMultiselect.WithOptions(options).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,38 @@ | ||
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) | ||
time.Sleep(time.Millisecond * 250) | ||
} | ||
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) | ||
}() | ||
} | ||
} |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pterm/pterm" | ||
) | ||
|
||
func main() { | ||
var options []string | ||
|
||
for i := 0; i < 100; i++ { | ||
options = append(options, fmt.Sprintf("Option %d", i)) | ||
} | ||
|
||
for i := 0; i < 5; i++ { | ||
options = append(options, fmt.Sprintf("You can use fuzzy searching (%d)", i)) | ||
} | ||
|
||
selectedOption, _ := pterm.DefaultInteractiveSelect.WithOptions(options).Show() | ||
pterm.Info.Printfln("Selected option: %s", pterm.Green(selectedOption)) | ||
} |
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,35 @@ | ||
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 []rune(input) { | ||
keyboard.SimulateKeyPress(r) | ||
time.Sleep(time.Millisecond * 250) | ||
} | ||
|
||
for i := 0; i < 7; i++ { | ||
keyboard.SimulateKeyPress(keys.Left) | ||
time.Sleep(time.Millisecond * 150) | ||
} | ||
|
||
keyboard.SimulateKeyPress(keys.Backspace) | ||
time.Sleep(time.Millisecond * 500) | ||
keyboard.SimulateKeyPress(',') | ||
time.Sleep(time.Millisecond * 500) | ||
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,11 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/pterm/pterm" | ||
) | ||
|
||
func main() { | ||
result, _ := pterm.DefaultInteractiveTextInput.WithMultiLine(false).Show() | ||
pterm.Println() // Blank line | ||
pterm.Info.Printfln("You answered: %s", result) | ||
} |
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,49 @@ | ||
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 := "1111111\n2222222" | ||
for _, r := range input { | ||
if r == '\n' { | ||
keyboard.SimulateKeyPress(keys.Enter) | ||
} else { | ||
keyboard.SimulateKeyPress(r) | ||
} | ||
time.Sleep(time.Millisecond * 250) | ||
} | ||
|
||
for i := 0; i < 7; i++ { | ||
keyboard.SimulateKeyPress(keys.Left) | ||
time.Sleep(time.Millisecond * 150) | ||
} | ||
|
||
keyboard.SimulateKeyPress(keys.Backspace) | ||
time.Sleep(time.Millisecond * 500) | ||
keyboard.SimulateKeyPress(keys.Enter) | ||
time.Sleep(time.Millisecond * 500) | ||
input = "33333333\n4\n5555555" | ||
for _, r := range input { | ||
if r == '\n' { | ||
keyboard.SimulateKeyPress(keys.Enter) | ||
} else { | ||
keyboard.SimulateKeyPress(r) | ||
} | ||
time.Sleep(time.Millisecond * 250) | ||
} | ||
|
||
keyboard.SimulateKeyPress(keys.Tab) | ||
}() | ||
} | ||
} |
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,11 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/pterm/pterm" | ||
) | ||
|
||
func main() { | ||
result, _ := pterm.DefaultInteractiveTextInput.WithMultiLine().Show() // Text input with multi line enabled | ||
pterm.Println() // Blank line | ||
pterm.Info.Printfln("You answered: %s", result) | ||
} |
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,8 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
informational: true | ||
patch: | ||
default: | ||
informational: true |
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
Oops, something went wrong.