diff --git a/bannercli/banner.go b/bannercli/banner.go new file mode 100644 index 0000000..767b784 --- /dev/null +++ b/bannercli/banner.go @@ -0,0 +1,58 @@ +// Package bannercli provides functionality to print different styles of banners +// to the terminal. These styles include binary representation and simple +// animation effects to enhance the visual presentation of CLI applications. +// # bannercli/banner.go +// Example usage: +// +// bannercli.PrintTypingBanner("ChatGPT Session Exporter", 100*time.Millisecond) +// +// Copyright (c) 2023 H0llyW00dzZ +package bannercli + +import ( + "fmt" + "strings" + "time" +) + +// PrintBinaryBanner prints a binary representation of a banner. +// Each character of the message is converted into its binary form. +// Spaces between words are widened to enhance readability. +// +// Copyright (c) 2023 H0llyW00dzZ +func PrintBinaryBanner(message string) { + banner := strings.ReplaceAll(message, " ", " ") + for _, char := range banner { + fmt.Printf(" %08b", char) + } + fmt.Println() +} + +// PrintAnimatedBanner prints a simple animated banner by scrolling the message +// horizontally across the terminal. The animation repeats the number of times +// specified by the `repeat` parameter with a delay between each frame as +// specified by the `delay` parameter. +// +// Copyright (c) 2023 H0llyW00dzZ +func PrintAnimatedBanner(message string, repeat int, delay time.Duration) { + for r := 0; r < repeat; r++ { + for i := 0; i < len(message); i++ { + fmt.Print("\r" + strings.Repeat(" ", i) + message) + time.Sleep(delay) + } + } + fmt.Println() +} + +// PrintTypingBanner prints the message with a typing animation effect. +// +// Each character appears sequentially with a delay, simulating a typing effect. +// +// Copyright (c) 2023 H0llyW00dzZ +func PrintTypingBanner(message string, delay time.Duration) { + for _, char := range message { + fmt.Printf("%c", char) + time.Sleep(delay) + } + fmt.Println() +} diff --git a/main.go b/main.go index cc1b494..6e83789 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,9 @@ import ( "strconv" "strings" "syscall" + "time" + "github.com/H0llyW00dzZ/ChatGPT-Next-Web-Session-Exporter/bannercli" "github.com/H0llyW00dzZ/ChatGPT-Next-Web-Session-Exporter/exporter" "github.com/H0llyW00dzZ/ChatGPT-Next-Web-Session-Exporter/filesystem" "github.com/H0llyW00dzZ/ChatGPT-Next-Web-Session-Exporter/interactivity" @@ -47,6 +49,7 @@ const ( // main initializes the application, setting up context for cancellation and // starting the user interaction flow for data processing and exporting. func main() { + bannercli.PrintTypingBanner("ChatGPT Session Exporter", 100*time.Millisecond) // Prepare a cancellable context for handling graceful shutdown. // This context will be passed down to functions that support cancellation. ctx, cancel := context.WithCancel(context.Background()) @@ -110,10 +113,12 @@ func main() { func handleInputError(err error) { if err == context.Canceled || err == io.EOF { // Handle a context cancellation or EOF, if applicable - fmt.Println("\n[GopherHelper] Exiting gracefully...\nReason: Operation canceled or end of input. Exiting program.") + bannercli.PrintTypingBanner("\nReason: Operation canceled or end of input. Exiting program.", 100*time.Millisecond) os.Exit(0) } else { - fmt.Printf("\n[GopherHelper] Error reading input: %s\n", err) + // Format the error message before passing it to PrintTypingBanner + errorMessage := fmt.Sprintf("\n[GopherHelper] Error reading input: %s\n", err) + bannercli.PrintTypingBanner(errorMessage, 100*time.Millisecond) os.Exit(1) } }