Пример #1
0
func ExampleCleanup() {
	sigint := make(chan os.Signal, 1)
	signal.Notify(sigint, syscall.SIGINT)

	readline.CatchSigint = false

	var line string
	var err error

	done := make(chan struct{})

	go func() {
		line, err = readline.String("> ")
		close(done)
	}()

	select {
	case <-sigint:
		fmt.Println("\nInterrupted")

		// Restore terminal attributes
		readline.Cleanup()
		// Note that we still have a goroutine reading from Stdin that
		// will terminate when we exit.
		os.Exit(1)
	case <-done:
		fmt.Printf("Read line %s, error %v\n", line, err)
	}
}
Пример #2
0
func cleanupAndExit() {
	// Restore terminal attributes..
	gnureadline.Cleanup()

	// Reset the terminal color.
	fmt.Print(colorReset)

	fmt.Println(`Good Bye

  ___/')
 /= =\/
/= = =\
^--|--^
`)

	// Just wait for a moment before exiting to be
	// sure, all defers get called and the program
	// performs a clean exit.
	time.Sleep(150 * time.Millisecond)

	// Exit the application with exit code 1.
	os.Exit(1)
}