mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-09-03 16:24:57 +00:00
Add Prompt and PrintBanner
Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
@@ -10,6 +12,8 @@ import (
|
||||
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/qeesung/image2ascii/convert"
|
||||
)
|
||||
|
||||
func SH(c string) (string, error) {
|
||||
@@ -133,3 +137,27 @@ func Shell() *exec.Cmd {
|
||||
cmd.Stdin = os.Stdin
|
||||
return cmd
|
||||
}
|
||||
|
||||
func Prompt(t string) (string, error) {
|
||||
if t != "" {
|
||||
pterm.Info.Println(t)
|
||||
}
|
||||
answer, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimSpace(answer), nil
|
||||
}
|
||||
|
||||
func PrintBanner(d []byte) {
|
||||
img, _, _ := image.Decode(bytes.NewReader(d))
|
||||
|
||||
convertOptions := convert.DefaultOptions
|
||||
convertOptions.FixedWidth = 100
|
||||
convertOptions.FixedHeight = 40
|
||||
|
||||
// Create the image converter
|
||||
converter := convert.NewImageConverter()
|
||||
fmt.Print(converter.Image2ASCIIString(img, &convertOptions))
|
||||
}
|
||||
|
Reference in New Issue
Block a user