Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Send messages from the client.

  • Loading branch information...
commit bb30c075fa86317e4f5879e0db6d1275b5bb1209 1 parent 2645781
@napthats authored
Showing with 11 additions and 9 deletions.
  1. +5 −4 PhiVty/UI.hs
  2. +6 −5 main.hs
View
9 PhiVty/UI.hs
@@ -9,7 +9,6 @@ module PhiVty.UI
import Graphics.Vty.Widgets.All
import qualified Data.Text as T
-import Control.Concurrent
data UIData = UIData {
ui_collection :: Collection,
@@ -17,11 +16,13 @@ data UIData = UIData {
ui_message :: Widget FormattedText
}
-initialPhiUI :: IO UIData
-initialPhiUI = do
+initialPhiUI :: (String -> IO ()) -> IO UIData
+initialPhiUI inputHandler = do
e <- editWidget
-- tentative
- e `onActivate` error "exit"
+ e `onActivate` \this -> do
+ txt <- getEditText this
+ inputHandler $ T.unpack txt
fg <- newFocusGroup
_ <- addToFocusGroup fg e
mes_plain <- plainText (T.pack "hi")
View
11 main.hs
@@ -14,13 +14,14 @@ import Codec.Binary.UTF8.String
main :: IO ()
main = do
- uidata <- initialPhiUI
+ tchan <- atomically newTChan
+ let recv_handler mes =
+ atomically $ writeTChan tchan (decodeString . unpack . convert "SJIS" "UTF-8" . pack $ mes)
+ soc <- connect "49.212.144.158" 20017 recv_handler
+ uidata <- initialPhiUI $ \mes ->
+ if mes == ":exit" then error "exit" else send mes soc
_ <- forkIO $ do
let new_db = initialDB 0
- tchan <- atomically newTChan
- let recv_handler mes =
- atomically $ writeTChan tchan (decodeString . unpack . convert "SJIS" "UTF-8" . pack $ mes)
- soc <- connect "49.212.144.158" 20017 recv_handler
send "#open guest3" soc
send "#map-iv 1" soc
send "#status-iv 1" soc

0 comments on commit bb30c07

Please sign in to comment.
Something went wrong with that request. Please try again.