Skip to content

Commit

Permalink
rename app folder (#63)
Browse files Browse the repository at this point in the history
* rename app folder

* clean up package.yaml
  • Loading branch information
epoberezkin committed Jun 25, 2021
1 parent eb2404c commit 5a2ded7
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 118 deletions.
61 changes: 0 additions & 61 deletions apps/dog-food/Main.hs

This file was deleted.

File renamed without changes.
115 changes: 81 additions & 34 deletions apps/simplex-chat/Main.hs
Original file line number Diff line number Diff line change
@@ -1,45 +1,92 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}

module Main where

import Control.Concurrent (threadDelay)
import Control.Concurrent.STM (readTVarIO, retry)
import Control.Monad (forever, void)
import Simplex.Demo (chatLayoutDemo)
import ChatOptions
import Control.Concurrent.STM
import Control.Logger.Simple
import Control.Monad.IO.Unlift
import Control.Monad.Reader
import Simplex.Chat
import Simplex.Chat.Controller
import Simplex.Input
import Simplex.Messaging.Agent (getSMPAgentClient)
import Simplex.Messaging.Agent.Env.SQLite
import Simplex.Messaging.Client (smpDefaultConfig)
import Simplex.Store (createStore)
import System.IO (hFlush, stdout)
import System.Terminal (putStringLn, runTerminalT, withTerminal)
import qualified System.Terminal as C
import qualified System.Terminal.Internal as C

defaultSettings :: C.Size -> C.VirtualTerminalSettings
defaultSettings size =
C.VirtualTerminalSettings
{ C.virtualType = "xterm",
C.virtualWindowSize = pure size,
C.virtualEvent = retry,
C.virtualInterrupt = retry
import Simplex.Terminal
import System.Directory (getAppUserDataDirectory)
import UnliftIO.Async (race_)

cfg :: AgentConfig
cfg =
AgentConfig
{ tcpPort = undefined, -- agent does not listen to TCP
smpServers = undefined, -- filled in from options
rsaKeySize = 2048 `div` 8,
connIdBytes = 12,
tbqSize = 16,
dbFile = "smp-chat.db",
smpCfg = smpDefaultConfig
}

logCfg :: LogConfig
logCfg = LogConfig {lc_file = Nothing, lc_stderr = True}

main :: IO ()
main = do
ChatOpts {dbFile, smpServers} <- welcomeGetOpts
void $ createStore "simplex-chat.db" 4
ct <- newChatTerminal
a <- getSMPAgentClient cfg {dbFile, smpServers}
cc <- atomically $ newChatController a ct $ tbqSize cfg
-- setLogLevel LogInfo -- LogError
-- withGlobalLogging logCfg $ do
runReaderT simplexChat cc

welcomeGetOpts :: IO ChatOpts
welcomeGetOpts = do
appDir <- getAppUserDataDirectory "simplex"
opts@ChatOpts {dbFile} <- getChatOpts appDir
putStrLn "SimpleX chat prototype v0.3.1"
putStrLn $ "db: " <> dbFile
putStrLn "type \"/help\" or \"/h\" for usage info"
pure opts

simplexChat :: (MonadUnliftIO m, MonadReader ChatController m) => m ()
simplexChat = race_ runTerminalInput runChatController

-- defaultSettings :: C.Size -> C.VirtualTerminalSettings
-- defaultSettings size =
-- C.VirtualTerminalSettings
-- { C.virtualType = "xterm",
-- C.virtualWindowSize = pure size,
-- C.virtualEvent = retry,
-- C.virtualInterrupt = retry
-- }

-- main :: IO ()
-- main = do
-- void $ createStore "simplex-chat.db" 4

-- hFlush stdout
-- -- ChatTerminal {termSize} <- newChatTerminal
-- -- pos <- C.withVirtualTerminal (defaultSettings termSize) $
-- -- \t -> runTerminalT (C.setAlternateScreenBuffer True >> C.putString "a" >> C.flush >> C.getCursorPosition) t
-- -- print pos
-- -- race_ (printEvents t) (updateTerminal t)
-- void . withTerminal . runTerminalT $ chatLayoutDemo >> C.flush >> C.awaitEvent

-- printEvents :: C.VirtualTerminal -> IO ()
-- printEvents t = forever $ do
-- event <- withTerminal . runTerminalT $ C.flush >> C.awaitEvent
-- runTerminalT (putStringLn $ show event) t

hFlush stdout
-- ChatTerminal {termSize} <- newChatTerminal
-- pos <- C.withVirtualTerminal (defaultSettings termSize) $
-- \t -> runTerminalT (C.setAlternateScreenBuffer True >> C.putString "a" >> C.flush >> C.getCursorPosition) t
-- print pos
-- race_ (printEvents t) (updateTerminal t)
void . withTerminal . runTerminalT $ chatLayoutDemo >> C.flush >> C.awaitEvent

printEvents :: C.VirtualTerminal -> IO ()
printEvents t = forever $ do
event <- withTerminal . runTerminalT $ C.flush >> C.awaitEvent
runTerminalT (putStringLn $ show event) t

updateTerminal :: C.VirtualTerminal -> IO ()
updateTerminal t = forever $ do
threadDelay 10000
win <- readTVarIO $ C.virtualWindow t
withTerminal . runTerminalT $ mapM_ C.putStringLn win >> C.flush
-- updateTerminal :: C.VirtualTerminal -> IO ()
-- updateTerminal t = forever $ do
-- threadDelay 10000
-- win <- readTVarIO $ C.virtualWindow t
-- withTerminal . runTerminalT $ mapM_ C.putStringLn win >> C.flush
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 4 additions & 23 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@ library:
source-dirs: src

executables:
dog-food:
source-dirs: apps/dog-food
main: Main.hs
dependencies:
- simplex-chat
- async == 2.2.*
- bytestring == 0.10.*
- composition == 1.0.*
- directory == 1.3.*
- filepath == 1.4.*
- mtl == 2.2.*
- optparse-applicative == 0.15.*
- simple-logger == 0.1.*
- simplexmq == 0.3.*
- stm == 2.5.*
- terminal == 0.2.*
- time == 1.9.*
- unliftio == 0.2.*
- unliftio-core == 0.2.*
ghc-options:
- -threaded

simplex-chat:
source-dirs: apps/simplex-chat
main: Main.hs
Expand All @@ -54,14 +32,17 @@ executables:
- async == 2.2.*
- bytestring == 0.10.*
- composition == 1.0.*
- cryptonite == 0.27.*
- directory == 1.3.*
- file-embed == 0.0.14.*
- filepath == 1.4.*
- mtl == 2.2.*
- optparse-applicative == 0.15.*
- simple-logger == 0.1.*
- simplexmq == 0.3.*
- sqlite-simple == 0.4.*
- stm == 2.5.*
- terminal == 0.2.*
- time == 1.9.*
- unliftio == 0.2.*
- unliftio-core == 0.2.*
ghc-options:
Expand Down

0 comments on commit 5a2ded7

Please sign in to comment.