packages feed

mc (empty) → 0.1.0.0

raw patch · 6 files changed

+155/−0 lines, 6 filesdep +asyncdep +basedep +mc

Dependencies added: async, base, mc, optparse-applicative, process, stm

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for mc++## 0.1.0.0 -- 11-21-2026++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2026 David Cox++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ README.md view
@@ -0,0 +1,23 @@+# MC+Master of Ceremonies++Usage++```+mc -k a -v "espeak-ng \"hello\"" \+   -k b -v "espeak-ng \"goodbye\"" \+   -k c -v "tonwav 420 | aplay"+```++Install++```+cabal install mc+```++Development++```+cabal build+cabal run mc -- --help+```
+ exe/Main.hs view
@@ -0,0 +1,45 @@+module Main (main) where++import Control.Concurrent.MC+import Control.Concurrent.STM+import Control.Exception+import Control.Monad+import Data.Version+import Options.Applicative+import Paths_mc+import System.IO+import System.Process++main :: IO ()+main = do+  CLI c qs kvs <- customExecParser prefs' $ pinfo $ showVersion version+  q <- checkChar qs+  km <- forM kvs $ \(ks, cmd) -> checkChar ks >>= \k ->+    return (k, putStrLn (k:"!") >> callCommand cmd)+  kv <- newTVarIO km+  hSetBuffering stdin NoBuffering+  bracket (hGetEcho stdin <* hSetEcho stdin False) (hSetEcho stdin) $ const $+    mc c (Just q) (\k -> putStrLn (k:"?")) kv getChar++checkChar :: String -> IO Char+checkChar [c] = return c+checkChar cs  = fail $ "invalid char: " ++ cs++prefs' :: ParserPrefs+prefs' = prefs $ showHelpOnError <> showHelpOnEmpty++pinfo :: String -> ParserInfo CLI+pinfo v = info (parser <**> simpleVersioner v <**> helper) $+  progDesc "master of ceremonies"++data CLI = CLI Int String [(String, String)]++parser :: Parser CLI+parser = CLI+  <$> option auto (short 'c' <> long "conc" <> metavar "INT" <> value 64+      <> showDefault <> help "concurrency factor")+  <*> strOption (short 'q' <> long "quit" <> metavar "CHR" <> value "q"+      <> showDefault <> help "quit key")+  <*> many ((,)+      <$> strOption (short 'k' <> metavar "CHR" <> help "key")+      <*> strOption (short 'v' <> metavar "CMD" <> help "cmd"))
+ lib/Control/Concurrent/MC.hs view
@@ -0,0 +1,23 @@+module Control.Concurrent.MC (mc) where++import Control.Concurrent.Async+import Control.Concurrent.STM+import Control.Monad+import Data.Maybe++mc+  :: Eq a+  => Int               -- ^ concurrency factor+  -> Maybe a           -- ^ quit value+  -> (a -> IO ())      -- ^ unknown value+  -> TVar [(a, IO ())] -- ^ IO map+  -> IO a              -- ^ input value+  -> IO ()+mc c q u m i = newTChanIO >>= \t -> race_ (reader q i t) $+  replicateConcurrently_ c $ forever $ join $ atomically $+  (\a l -> fromMaybe (u a) $ lookup a l) <$> readTChan t <*> readTVar m++reader :: Eq a => Maybe a -> IO a -> TChan a -> IO ()+reader q i t = loop+  where+    loop = i >>= \a -> when (Just a /= q) $ atomically (writeTChan t a) >> loop
+ mc.cabal view
@@ -0,0 +1,38 @@+cabal-version:      3.0+name:               mc+version:            0.1.0.0+synopsis:           Master of Ceremonies+homepage:           https://github.com/dopamane/mc+license:            MIT+license-file:       LICENSE+author:             dopamane+maintainer:         dwc1295@gmail.com+copyright:          David Cox+category:           Concurrency+build-type:         Simple+extra-doc-files:    CHANGELOG.md+                    README.md++library+  default-language: Haskell2010+  ghc-options:      -Wall -O2+  hs-source-dirs:   lib+  exposed-modules:  Control.Concurrent.MC+  build-depends:+    async,+    base < 5,+    stm++executable mc+  default-language: Haskell2010+  ghc-options:      -Wall -O2 -threaded+  hs-source-dirs:   exe+  main-is:          Main.hs+  other-modules:    Paths_mc+  autogen-modules:  Paths_mc+  build-depends:+    base < 5,+    optparse-applicative,+    process,+    mc,+    stm