Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Copies newline-separated text from the clipboard, replaces tab
- -- characters with rightwards arrows surrounded by spaces, numbers the
- -- lines, replaces the original text in the clipboard with the output.
- import System.Clipboard as SC
- main :: IO ()
- main = do
- input <- SC.getClipboardString
- if input == Nothing
- then SC.setClipboardString "There was nothing in the clipboard!"
- else SC.setClipboardString $ processData input
- processData :: Maybe String -> String
- processData = numberedListItemsToString . numberListItems . replaceTabsWithArrows . inputToListOfStrings
- inputToListOfStrings :: Maybe String -> [String]
- inputToListOfStrings Nothing = ["Nothing!"]
- inputToListOfStrings (Just string) = lines string
- replaceTabsWithArrows :: [String] -> [String]
- replaceTabsWithArrows = map aux
- where
- aux [] = []
- aux (x:xs)
- | x == '\t' = ' ' : '→' : ' ' : aux xs
- | otherwise = x : aux xs
- numberListItems :: [String] -> [(Int, String)]
- numberListItems = zip [1 ..]
- numberedListItemsToString :: [(Int, String)] -> String
- numberedListItemsToString = unlines . map (\(number, string) -> show number ++ ". " ++ string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement