Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Text (Text, pack, replace, unpack)
- import System.Hclip (setClipboard, getClipboard)
- import System.Process (callCommand)
- import Text.Regex (Regex, mkRegexWithOpts, subRegex, matchRegex)
- tab :: Text
- tab = pack "\t"
- arrow :: Text
- arrow = pack " → "
- regex :: Regex
- regex = mkRegexWithOpts "^[0-9]+\\. " True False
- arrowsWithTabs :: Text -> String
- arrowsWithTabs = unpack . replace arrow tab
- tabsWithArrows :: Text -> String
- tabsWithArrows = unpack . replace tab arrow
- lineNumberer :: String -> String
- lineNumberer =
- unlines .
- map (\(number, string) -> show number ++ ". " ++ string) . zip [1 ..] . lines
- lineDenumberer :: String -> String
- lineDenumberer =
- unlines . map (\item -> Text.Regex.subRegex regex item "") . lines
- inputCheck :: String -> Maybe [String]
- inputCheck = matchRegex regex
- dispatcher :: String -> IO ()
- dispatcher input
- | inputCheck input == Nothing = do
- setClipboard . lineNumberer . tabsWithArrows $ pack input
- callCommand "espeak -v whisper -a 25 -s 300 'Numbered!'"
- | otherwise = do
- setClipboard . lineDenumberer . arrowsWithTabs $ pack input
- callCommand "espeak -v whisper -a 25 -s 300 'Denumbered!'"
- main :: IO ()
- main = do
- input <- getClipboard
- dispatcher input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement