| | [Haskell-cafe] Trapping getChar before echo  | 
31-01-10, 08:48 AM
| | | [Haskell-cafe] Trapping getChar before echo Hi,
Is there any way of trapping keystrokes in Haskell, modifying them, and then echoing?
Basically I want to give the user a prompt like:
>
and then have whatever they type appear in UPPERCASE regardless of whether caps lock was on or not.
By default Haskell seems to echo characters in whatever case they were typed. I want to sneak in a toUpper in before the Chars get echoed.
Thanks
Mark Spezzano
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
| 
31-01-10, 10:05 AM
| | | Re: [Haskell-cafe] Trapping getChar before echo Hi Mark, Code: Content visible to registered users only.
Thanks, Neil
On Sun, Jan 31, 2010 at 8:47 AM, Mark Spezzano
< - > wrote:
> Hi,
>
> Is there any way of trapping keystrokes in Haskell, modifying them, and then echoing?
>
> Basically I want to give the user a prompt *like:
>>
>
> and then have whatever they type appear in UPPERCASE regardless of whether caps lock was on or not.
>
> By default Haskell seems to echo characters in whatever case they were typed. I want to sneak in a toUpper in before the Chars get echoed.
>
> Thanks
>
> Mark Spezzano
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Code: Content visible to registered users only.
> Code: Content visible to registered users only.
>
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
| 
31-01-10, 10:13 AM
| | | Re: [Haskell-cafe] Trapping getChar before echo import System.IO
import Data.Char
main = do
hSetEcho stdin False
hSetBuffering stdin NoBuffering
hSetBuffering stdout NoBuffering
scanLine
where scanLine = do
c <- hGetChar stdin
putChar . toUpper $ c
scanLine
Am Sonntag, den 31.01.2010, 19:17 +1030 schrieb Mark Spezzano:
> Hi,
>
> Is there any way of trapping keystrokes in Haskell, modifying them, and then echoing?
>
> Basically I want to give the user a prompt like:
> >
>
> and then have whatever they type appear in UPPERCASE regardless of whether caps lock was on or not.
>
> By default Haskell seems to echo characters in whatever case they were typed. I want to sneak in a toUpper in before the Chars get echoed.
>
> Thanks
>
> Mark Spezzano
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Code: Content visible to registered users only.
> Code: Content visible to registered users only.
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
| 
31-01-10, 12:58 PM
| | | Re: [Haskell-cafe] Trapping getChar before echo Michael Hartl wrote:
> import System.IO
> import Data.Char
>
> main = do
> hSetEcho stdin False
> hSetBuffering stdin NoBuffering
> hSetBuffering stdout NoBuffering
> scanLine
> where scanLine = do
> c <- hGetChar stdin
> putChar . toUpper $ c
> scanLine
>
Last time I tried something like this [on Windows], it didn't seem to
work. I wanted to trap arrow keys and so forth, but they seem to be
being used for input history. (I.e., pressing the up-arrow produces
previously-entered lines of text, and none of this appears to be
reaching the Haskell program itself.) Has this changed since I tried it
last year?
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
| 
01-02-10, 08:45 AM
| | | Re: [Haskell-cafe] Trapping getChar before echo I've tried this example and it just lets me type in anything in CAPITALS, which is nice, but Delete key doesn't delete and the arrow keys unfortunately let me manoeuvre the cursor all over the screen. Also the biggest problem is that Enter doesn't terminate the input session.
Isn't there a simple way to do something like this?
Surely Haskell must have a standard getLine function that support CAPITALS and backspacing and no arrow keys. Arrows keys with history would be nice.
Mark
On 31/01/2010, at 11:27 PM, Andrew Coppin wrote:
> Michael Hartl wrote:
>> import System.IO
>> import Data.Char
>>
>> main = do
>> hSetEcho stdin False
>> hSetBuffering stdin NoBuffering
>> hSetBuffering stdout NoBuffering
>> scanLine
>> where scanLine = do c <- hGetChar stdin
>> putChar . toUpper $ c
>> scanLine
>>
>
> Last time I tried something like this [on Windows], it didn't seem to work. I wanted to trap arrow keys and so forth, but they seem to be being used for input history. (I.e., pressing the up-arrow produces previously-entered lines of text, and none of this appears to be reaching the Haskell program itself.) Has this changed since I tried it last year?
>
> _______________________________________________
> Haskell-Cafe mailing list
> Code: Content visible to registered users only.
> Code: Content visible to registered users only.
>
>
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
| 
01-02-10, 09:14 AM
| | | Re: [Haskell-cafe] Trapping getChar before echo It might be worth looking at something like a curses library.
On Mon, Feb 1, 2010 at 4:45 PM, Mark Spezzano
< - > wrote:
> I've tried this example and it just lets me type in anything in CAPITALS, which is nice, but Delete key doesn't delete and the arrow keys unfortunately let me manoeuvre the cursor all over the screen. Also the biggest problem is that Enter doesn't terminate the input session.
>
> Isn't there a simple way to do something like this?
>
> Surely Haskell must have a standard getLine function that support CAPITALS and backspacing and no arrow keys. Arrows keys with history would be nice.
>
> Mark
>
>
> On 31/01/2010, at 11:27 PM, Andrew Coppin wrote:
>
>> Michael Hartl wrote:
>>> import System.IO
>>> import Data.Char
>>>
>>> main = do
>>> Â*hSetEcho stdin False
>>> Â*hSetBuffering stdin NoBuffering
>>> Â*hSetBuffering stdout NoBuffering
>>> Â*scanLine
>>> Â* Â* Â*where scanLine = do Â* Â* Â* Â* Â* Â* Â* c <- hGetChar stdin
>>> Â* Â* Â* Â* Â* Â* Â*putChar . toUpper $ c
>>> Â* Â* Â* Â* Â* Â* Â*scanLine
>>>
>>
>> Last time I tried something like this [on Windows], it didn't seem to work. I wanted to trap arrow keys and so forth, but they seem to be being used for input history. (I.e., pressing the up-arrow produces previously-entered lines of text, and none of this appears to be reaching the Haskell program itself.) Has this changed since I tried it last year?
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Code: Content visible to registered users only.
>> Code: Content visible to registered users only.
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Code: Content visible to registered users only.
> Code: Content visible to registered users only.
>
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
| 
02-02-10, 01:47 AM
| | | [Haskell-cafe] Re: Trapping getChar before echo > Last time I tried something like this [on Windows], it didn't seem to
> work. I wanted to trap arrow keys and so forth, but they seem to be being
> used for input history. (I.e., pressing the up-arrow produces
> previously-entered lines of text, and none of this appears to be reaching
> the Haskell program itself.) Has this changed since I tried it last year?
Doesn't work in windows, at least up till 6.10.1. There's a work-around
though.
{-# LANGUAGE ForeignFunctionInterface #-}
import Data.Char
import Control.Monad (liftM, forever)
import Foreign.C.Types
getHiddenChar = liftM (chr.fromEnum) c_getch
foreign import ccall unsafe "conio.h getch"
c_getch :: IO CInt
main = do
forever $ do
c <- getHiddenChar
putStrLn $ show (fromEnum c)
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
| 
05-02-10, 06:41 PM
| | | Re: [Haskell-cafe] Re: Trapping getChar before echo Tim Attwood wrote:
>> Last time I tried something like this [on Windows], it didn't seem to
>> work. I wanted to trap arrow keys and so forth, but they seem to be
>> being used for input history. (I.e., pressing the up-arrow produces
>> previously-entered lines of text, and none of this appears to be
>> reaching the Haskell program itself.) Has this changed since I tried
>> it last year?
>
> Doesn't work in windows, at least up till 6.10.1. There's a
> work-around though.
>
> {-# LANGUAGE ForeignFunctionInterface #-}
>
> import Data.Char
> import Control.Monad (liftM, forever)
> import Foreign.C.Types
>
> getHiddenChar = liftM (chr.fromEnum) c_getch
> foreign import ccall unsafe "conio.h getch"
> c_getch :: IO CInt
>
> main = do
> forever $ do
> c <- getHiddenChar
> putStrLn $ show (fromEnum c)
Thanks for the info.
Does anyone know how this is related to the "haskeline" package on Hackage?
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
| 
05-02-10, 11:39 PM
| | | Re: [Haskell-cafe] Re: Trapping getChar before echo On Fri, Feb 5, 2010 at 10:41 AM, Andrew Coppin
< - > wrote:
> Tim Attwood wrote:
>>>
>>> Last time I tried something like this [on Windows], it didn't seem to
>>> work. I wanted to trap arrow keys and so forth, but they seem to be being
>>> used for input history. (I.e., pressing the up-arrow produces
>>> previously-entered lines of text, and none of this appears to be reaching
>>> the Haskell program itself.) Has this changed since I tried it last year?
>>
>> Doesn't work in windows, at least up till 6.10.1. There's a work-around
>> though.
>>
>> {-# LANGUAGE ForeignFunctionInterface #-}
>>
>> import Data.Char
>> import Control.Monad (liftM, forever)
>> import Foreign.C.Types
>>
>> getHiddenChar = liftM (chr.fromEnum) c_getch
>> foreign import ccall unsafe "conio.h getch"
>> *c_getch :: IO CInt
>>
>> main = do
>> *forever $ do
>> * * c <- getHiddenChar
>> * * putStrLn $ show (fromEnum c)
>
> Thanks for the info.
>
> Does anyone know how this is related to the "haskeline" package on Hackage?
The haskeline package provides a readline-like library for reading in
a line of input with arrow keys, tab completion, etc. It works on
both Windows and unix platforms. Documentation and a full list of
features can be found at Code: Content visible to registered users only.
.
On Windows, haskeline gets all user input by calling Win32 API
functions such as ReadConsoleInputW: Code: Content visible to registered users only.
That function returns an INPUT_RECORD struct with information about
key press events (among others); those includes simple characters,
arrow keys, page up/down, etc. AFAIK that's the only way to get at
such events in the Windows console; there's no effective analogue to
the unix setting, where e.g. pressing the up key causes stdin to
receive the ANSI key sequence "\ESC[A".
The source code of haskeline has examples of how to import and use
those API functions: Code: Content visible to registered users only.
Best,
-Judah
_______________________________________________
Haskell-Cafe mailing list Code: Content visible to registered users only.
Code: Content visible to registered users only.
|  | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT +1. The time now is 11:59 PM.
Powered by vBulletin® Version 3.6.8 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 | |