From 578e06cd750e4cb13a6707482bf519a2e664730f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 3 Apr 2021 21:53:16 +0100 Subject: [PATCH] remove terminal mode "simple" (#78) --- ChatOptions.hs | 3 +-- ChatTerminal.hs | 59 +++++-------------------------------------------- Types.hs | 3 +-- 3 files changed, 8 insertions(+), 57 deletions(-) diff --git a/ChatOptions.hs b/ChatOptions.hs index 72bc6f9854..0a7ff89f09 100644 --- a/ChatOptions.hs +++ b/ChatOptions.hs @@ -48,7 +48,7 @@ chatOpts appDir = ( long "term" <> short 't' <> metavar "TERM" - <> help ("terminal mode: editor, simple or basic (" <> termModeName deafultTermMode <> ")") + <> help ("terminal mode: editor or basic (" <> termModeName deafultTermMode <> ")") <> value deafultTermMode ) where @@ -63,7 +63,6 @@ parseSMPServer = eitherReader $ A.parseOnly (smpServerP <* A.endOfInput) . B.pac parseTermMode :: ReadM TermMode parseTermMode = maybeReader $ \case "basic" -> Just TermModeBasic - "simple" -> Just TermModeSimple "editor" -> Just TermModeEditor _ -> Nothing diff --git a/ChatTerminal.hs b/ChatTerminal.hs index 641daf55bf..ccc5a87616 100644 --- a/ChatTerminal.hs +++ b/ChatTerminal.hs @@ -3,10 +3,6 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} --- #ifdef mingw32_HOST_OS --- {-# LANGUAGE ForeignFunctionInterface #-} --- #endif - module ChatTerminal ( ChatTerminal (..), newChatTerminal, @@ -33,11 +29,6 @@ import qualified System.Console.ANSI as C import System.IO import Types --- #ifdef mingw32_HOST_OS --- import Data.Char --- import Foreign.C.Types --- #endif - data ChatTerminal = ChatTerminal { inputQ :: TBQueue ByteString, outputQ :: TBQueue ByteString, @@ -102,10 +93,8 @@ newTermState user = chatTerminal :: ChatTerminal -> IO () chatTerminal ct - | termMode ct == TermModeBasic = - run (receiveFromTTY $ getLn stdin) sendToTTY - | termSize ct == (0, 0) || termMode ct == TermModeSimple = - run (receiveFromTTY $ getChatLn ct) sendToTTY + | termSize ct == (0, 0) || termMode ct == TermModeBasic = + run receiveFromTTY sendToTTY | otherwise = do setTTY NoBuffering hSetEcho stdin False @@ -114,9 +103,9 @@ chatTerminal ct where run receive send = race_ (receive ct) (send ct) -receiveFromTTY :: IO ByteString -> ChatTerminal -> IO () -receiveFromTTY get ct = - forever $ get >>= atomically . writeTBQueue (inputQ ct) +receiveFromTTY :: ChatTerminal -> IO () +receiveFromTTY ct = + forever $ getLn stdin >>= atomically . writeTBQueue (inputQ ct) withTermLock :: ChatTerminal -> IO () -> IO () withTermLock ChatTerminal {termLock} action = do @@ -302,48 +291,12 @@ getKey = charsToKey . reverse <$> keyChars "" cs -> KeyChars cs keyChars cs = do - c <- getHiddenChar + c <- getChar more <- hReady stdin -- for debugging - uncomment this, comment line after: -- (if more then keyChars else \c' -> print (reverse c') >> return c') (c : cs) (if more then keyChars else return) (c : cs) -getChatLn :: ChatTerminal -> IO ByteString -getChatLn ct = do - setTTY NoBuffering - hSetEcho stdin False - getHiddenChar >>= \case - '/' -> getWithChar "/" - '@' -> getWithChar "@" - ch -> do - let s = encodeUtf8 $ T.singleton ch - readTVarIO (activeContact ct) >>= \case - Nothing -> getWithChar s - Just a -> getWithContact a s - where - getWithChar :: ByteString -> IO ByteString - getWithChar c = do - B.hPut stdout c - getRest c - getWithContact :: Contact -> ByteString -> IO ByteString - getWithContact a s = do - B.hPut stdout $ ttyToContact a <> " " <> s - getRest $ "@" <> toBs a <> " " <> s - getRest :: ByteString -> IO ByteString - getRest s = do - setTTY LineBuffering - hSetEcho stdin True - (s <>) <$> getLn stdin - -getHiddenChar :: IO Char --- #ifdef mingw32_HOST_OS --- getHiddenChar = fmap (chr.fromEnum) c_getch --- foreign import ccall unsafe "conio.h getch" --- c_getch :: IO CInt --- #else -getHiddenChar = getChar --- #endif - setTTY :: BufferMode -> IO () setTTY mode = do hSetBuffering stdin mode diff --git a/Types.hs b/Types.hs index 2b5c9b6d6e..ae03c01989 100644 --- a/Types.hs +++ b/Types.hs @@ -6,10 +6,9 @@ import Data.ByteString.Char8 (ByteString) newtype Contact = Contact {toBs :: ByteString} -data TermMode = TermModeBasic | TermModeSimple | TermModeEditor deriving (Eq) +data TermMode = TermModeBasic | TermModeEditor deriving (Eq) termModeName :: TermMode -> String termModeName = \case TermModeBasic -> "basic" - TermModeSimple -> "simple" TermModeEditor -> "editor"