Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
module Interactive where
--
-- Interaktiivsed programmid on funktsioonid
-- (standard)sisendist väljundisse.
--
type Interact = String -> String
type Pos = (Int,Int)
--
--Baaskombinaatorid
--
end :: Interact
readChar, peekChar :: (Char -> Interact) -> Interact
pressAnyKey :: Interact -> Interact
unreadChar :: Char -> Interact -> Interact
writeChar :: Char -> Interact -> Interact
writeStr :: String -> Interact -> Interact
ringBell :: Interact -> Interact
readLine :: String -> (String -> Interact) -> Interact
end cs = ""
readChar prog (c:cs) = prog c cs
peekChar prog cs@(c:_) = prog c cs
pressAnyKey prog = readChar (\c -> prog)
unreadChar c prog cs = prog (c:cs)
writeChar c prog cs = c : prog cs
writeStr s prog cs = s ++ prog cs
ringBell = writeChar '\BEL'
readLine prompt g cs = prompt ++ g line input'
where line = before '\n' cs
input' = after '\n' cs
before x = takeWhile (/= x)
after x = tail . dropWhile (/= x)
--
-- ANSI koodid ekraaniga töötamiseks
--
cls :: String
cls = "\ESC[2J"
highlight :: String -> String
highlight s = "\ESC[7m"++s++"\ESC[0m"
goto :: Int -> Int -> String
goto x y = "\ESC[" ++ show y ++ ";"
++ show x ++ "H"
home :: String
home = goto 1 1
at :: Pos -> String -> String
at (x,y) s = goto x y ++ s
--
-- Interaktiivsed kombinaatorid ANSI ekraaniga töötamiseks
--
clearScreen :: Interact -> Interact
clearScreen = writeStr cls
moveTo :: Pos -> Interact -> Interact
moveTo (x,y) = writeStr (goto x y)
writeAt :: Pos -> String -> Interact -> Interact
writeAt pos s = writeStr (at pos s)
readAt :: Pos -> String ->
(String->Interact) -> Interact
readAt pos prompt g
= moveTo pos $ readLine prompt g