getting constant input

Discussion of Scheme and Racket

getting constant input

Postby Jonsul » Sun Sep 12, 2010 10:10 pm

As a learning project, I'm trying to create a cli text editor like vi. I've been trying to figure out how to get a constant input coming in from the user in the terminal, but the only example I've found to get input is from a prompt function like "in-lines". I'm pretty sure I need to start a loop and open a port for input, but I've been scouring documentation for opening a port and haven't found out how to yet. By the way I've been using Racket.
Anyone got a good example for me to look at, or a link to documentation?

Thanks alot
Jonsul
 
Posts: 18
Joined: Mon Apr 19, 2010 7:56 am

Re: getting constant input

Postby Paul Donnelly » Wed Sep 15, 2010 8:12 am

Ncurses wrapper? If your Scheme doesn't already have one, it would be a good chance to learn to work the FFI. Doing console drawing yourself doesn't sound pleasant.
Paul Donnelly
 
Posts: 148
Joined: Wed Jul 30, 2008 11:26 pm

Re: getting constant input

Postby Warren Wilkinson » Thu Nov 11, 2010 3:35 pm

I/O has been sucked into operating systems for some time now, so you have to go through it. For example, on Linux ASM programs can use READ and WRITE (interrupts 3 & 4) to perform some basic IO. To do char by character input I think they must use the IOCTL system call to set the IO mode.

Because the system calls differ among OS', and because C seems to be every OS's favorite language, the non-portable syscalls are eschewed for slighly more portable C libraries.

http://cboard.cprogramming.com/c-programming/63166-kbhit-linux.html has an implementation of kbhit in C for Linux. The routine is to be continually polled, and it returns 0 if no key pressed, otherwise a keycode. In that thread they ask the poster why he didn't use a curses library, so I guess that is common practice.

Does Racket have a REPL? Changing how characters are read might negatively affect the lifespan of your Scheme or Lisp. The last time I tried to do something like this in Forth (GForth, which has a repl), I concluded the best way to coexist a repl and key-by-key input together harmoneously was to rewrite the language. This way I could control when the repl took input and when my program took input. Emacs may be emacs instead of a lisp package because its authors come to the same conclusion.
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.
User avatar
Warren Wilkinson
 
Posts: 116
Joined: Tue Aug 10, 2010 11:24 pm
Location: Calgary, Alberta


Return to Scheme

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron