schemencurseschicken-scheme

`getstr` in ncurses egg (Chicken Scheme)


I'm trying to figure how to use the function getstr of this egg (and consequently of mvgetstr, mvwgetstr, etc...). For example:

(require-extension ncurses)

(let ((stdscr (initscr)) (str (make-string 10)))
  (getstr str)
  (addstr str)
  (getch))

csi tells me

Error: bad argument type - not a pointer: " "

So i tried with this:

(require-extension ncurses)

(let ((stdscr (initscr)) (str (make-string 10)))
  (begin      
  (getstr (object->pointer str))
   (addstr str)
   (getch)))) 

This time csi give me another error:

Error: bad argument type - not a string: [panic] Detected corrupted data in stack - execution terminated

I think the problem is about the encoding of the string (a function thinks is ascii and another utf-8). I've no experience with pointer in scheme, I simply would know the best idiot-proof way to get a string with this egg.


Solution

  • In the end I think this is a bug of the ncurses egg. Here they say this was a bug and it has been correct but I have the same problem with the last version.

    However these functions were not really scheme-like and it's simple to redefine these functions using getch (which works correctly). For example:

    (define (mvgetstr x y)
      (move y x)
      (let loop ((str ""))
        (let ((ch (getch)))
          (if (eq? (char->integer ch ) 10) ;10 is the ENTER KEY code
          str
          (loop (string-append str (string ch)))))))
    

    Edit: another user suggested a way to use this function and similar:

    (use ncurses lolevel data-structures)
    
    (define (get-string max)
      (let ((buffer (make-string max #\null)))
        (getnstr (make-locative buffer) max)
        (string-translate buffer #\null)))
    
    (let ((stdscr (initscr))
          (str (get-string 10)))
      (addstr str)
      (getch)
      (write str))