mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-01 13:56:11 +00:00
* terminal: refactor chat core used in terminal app and in bot examples * fix tests * refactor
34 lines
1.1 KiB
Haskell
34 lines
1.1 KiB
Haskell
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
module Main where
|
|
|
|
import Control.Concurrent (threadDelay)
|
|
import Simplex.Chat
|
|
import Simplex.Chat.Controller (versionNumber)
|
|
import Simplex.Chat.Core
|
|
import Simplex.Chat.Options
|
|
import Simplex.Chat.Terminal
|
|
import Simplex.Chat.View (serializeChatResponse)
|
|
import System.Directory (getAppUserDataDirectory)
|
|
import System.Terminal (withTerminal)
|
|
|
|
main :: IO ()
|
|
main = do
|
|
appDir <- getAppUserDataDirectory "simplex"
|
|
opts@ChatOpts {chatCmd} <- getChatOpts appDir "simplex_v1"
|
|
if null chatCmd
|
|
then do
|
|
welcome opts
|
|
t <- withTerminal pure
|
|
simplexChatTerminal defaultChatConfig opts t
|
|
else simplexChatCore defaultChatConfig opts Nothing $ \_ cc -> do
|
|
r <- sendChatCmd cc chatCmd
|
|
putStrLn $ serializeChatResponse r
|
|
threadDelay $ chatCmdDelay opts * 1000000
|
|
|
|
welcome :: ChatOpts -> IO ()
|
|
welcome ChatOpts {dbFilePrefix} = do
|
|
putStrLn $ "SimpleX Chat v" ++ versionNumber
|
|
putStrLn $ "db: " <> dbFilePrefix <> "_chat.db, " <> dbFilePrefix <> "_agent.db"
|
|
putStrLn "type \"/help\" or \"/h\" for usage info"
|