Created
November 28, 2012 12:21
-
-
Save Heimdell/4160855 to your computer and use it in GitHub Desktop.
Vim-tasks generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# Language RecordWildCards #-} | |
| module TaskGen where | |
| import Control.Monad | |
| data Task = Task { combos :: [String] | |
| , description :: String | |
| , actions :: [String] | |
| , shouldBe :: String | |
| , excersize :: String | |
| } | |
| combo str = join $ every str $ \c -> ['`', c, '`'] | |
| every = flip map | |
| instance Show Task where | |
| show t@Task {..} = [ header t | |
| , newline | |
| , [unlines $ listOf actions] | |
| , newline | |
| , ["```"] | |
| , [tab, shouldBe] | |
| , [tab, excersize] | |
| , ["```"] | |
| , newline] | |
| |> map join | |
| |> unlines | |
| header Task {..} = [ "* " | |
| , anyOfCombos combos | |
| , " - " | |
| , description] | |
| (|>) = flip ($) | |
| tab = " " | |
| indent = " " | |
| newline = [[]] | |
| -- anyOfCombos ["dw", "dd", "c4c"] => "dw, dd или c4c" | |
| anyOfCombos [a] = a | |
| anyOfCombos [a, b] = a ++ " или " ++ b | |
| anyOfCombos (a:as) = a ++ ", " ++ anyOfCombos as | |
| -- unlines $ listOf ["kill", "crush", "destroy"] => " 1. kill\n 2. crush\n 3. destroy\n" | |
| listOf actions = listOf' 1 actions | |
| where listOf' _ [] = [] | |
| listOf' n (a:as) = (indent ++ show n ++ ". " ++ a) | |
| : listOf' (n+1) as | |
| bake :: [Task] -> String | |
| bake tasks = join $ (unlines $ join $ map header tasks ++ [[]]) | |
| : map show tasks | |
| -- anyOf "hjkl" => "`h`, `j`, `k` или `l`" | |
| anyOf = anyOfCombos . (map (combo . (:[]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import TaskGen | |
| main = putStr $ bake | |
| [ Task { combos = [ combo "c$" | |
| , combo "C" ] | |
| , description = "удалить от текущей позиции до конца строки и начать ввод" | |
| , actions = [ "Устанавливаем курсор на перед ошибкой" | |
| , "Для удаления лишнего символа используем " ++ combo "c$" | |
| , "Если требуется - вводим нужные символы" | |
| , "Во второй строке используем " ++ combo "C" ++ " для удаления" | |
| , "Не забываем, что для навигации используем клавиши " | |
| ++ anyOf "hjkl" ++ ", а также " ++ anyOf "wbe$^"] | |
| , shouldBe = "Fix some errors in this string." | |
| , excersize = "Edw wefwvf wefs in this string." } | |
| , Task { combos = [ combo "cw" | |
| , combo "cW" | |
| , combo "sd"] | |
| , description = "delete everything" | |
| , actions = [ "first" | |
| , "second" | |
| , "third" ] | |
| , shouldBe = "adasd asdasda adasdasd" | |
| , excersize = "adasda asdasdaa adasd" } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment