readline-cleanup-after-signal added by mario-goulart on Sat Mar 14 16:53:42 2020

(import breadline)
(import (chicken foreign)
        (chicken process signal))

(foreign-declare "#include <readline/readline.h>")

(define readline-cleanup-after-signal
  (foreign-lambda void "rl_cleanup_after_signal"))

(set-signal-handler! signal/int
  (lambda (_)
    (readline-cleanup-after-signal)
    (exit)))

(let loop ()
  (let ((input (readline "> ")))
    (if input
        (begin
          ;; processing code goes here
          (print input)
          (loop))
        (newline))))