I got a new idea for using xmonad XMonad.Prompt.Input. I thought it would be very cool if you could make a simple calculator that calculates that the user enters and returns the result in the next invitation text, ending when the user clicks the button ... The problem is that I do not do it completely know how to handle types ...
So far I have this:
runAndGetOutput cmd = do
(_, pout, _, phandle) <- runInteractiveCommand cmd
waitForProcess phandle
a <- hGetContents pout
return a
calcPrompt :: XPConfig -> String -> X ()
calcPrompt c ans =
inputPrompt c ans ?+ \ next ->
calcPrompt c (runAndGetOutput ("calc" ++ next))
What does not work. I get:
Couldn't match expected type `[Char]' with actual type `IO String'
Expected type: String
Actual type: IO String
In the return type of a call of `runAndGetOutput'
In the second argument of `calcPrompt', namely
`(runAndGetOutput ("calc" ++ next))'
I understand that this is because runAndGetOutput returns an IO String, and I need a normal string for inputPrompt, included from the XMonad.Prompt.Input import. But I have no idea how to handle this ...
Many thanks for your help!
EDIT:
Now I have this:
runAndGetOutput :: String -> IO String
runAndGetOutput cmd = do
(_, pout, _, phandle) <- runInteractiveCommand cmd
a <- hGetContents pout
waitForProcess phandle
return a
calcPrompt :: XPConfig -> String -> X ()
calcPrompt c ans =
inputPrompt c ans ?+ \next ->
liftIO (runAndGetOutput ("echo -n " ++ next)) >>= calcPrompt c
, . , , , stdo , .
, echo : , . return, ( , , ). echo, echo bash script, echo.
EDIT:
. :) .