Created
September 1, 2013 06:11
-
-
Save mxswd/6402641 to your computer and use it in GitHub Desktop.
This file contains 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
-- for people too lazy to read the chmod man page | |
import Graphics.Input as Input | |
import Window | |
scene : (Int, Int) -> Element -> [Element] -> Element | |
scene (w, h) strInput strVal = flow down | |
[ container w 100 topLeft strInput, | |
container w (h - 100) topLeft (case strVal of | |
[] -> plainText "wtf" | |
xs -> flow down (map (width 200) xs))] | |
fmapM : (a -> b) -> Maybe a -> Maybe b | |
fmapM f v = case v of | |
Nothing -> Nothing | |
Just v -> Just (f v) | |
getSources : Signal String -> Signal [Element] | |
getSources str = flip lift str (mkHex 0) | |
mkHex : Int -> String -> [Element] | |
mkHex dep y = case y of | |
[] -> [] | |
(x::xs) -> (justs [(val (readInt [x]) dep)]) ++ (mkHex (dep + 1) xs) | |
val : Maybe Int -> Int -> Maybe Element | |
val x dep = case x of | |
Just v -> fmapM plainText (whatMean v dep) | |
Nothing -> Nothing | |
whatMean : Int -> Int -> Maybe String | |
whatMean x dep = let colN = fmapM (\x -> x ++ " - ") (colName dep) | |
xs n = foldl catStrs n vs | |
vs = [cWorld x, cGroup x, cUser x, cNone x] | |
in case colN of | |
Nothing -> Nothing | |
Just vz -> if | length (xs vz) == 0 -> Nothing | |
| otherwise -> Just (xs vz) | |
colName : Int -> Maybe String | |
colName x = if | x == 0 -> Just "User" | |
| x == 1 -> Just "Group" | |
| x == 2 -> Just "World" | |
| otherwise -> Nothing | |
catStrs : Maybe String -> String -> String | |
catStrs x s = case x of | |
Just v -> s ++ v | |
Nothing -> s | |
cWorld : Int -> Maybe String | |
cWorld x = if | x `div` 4 == 1 -> Just "r" | |
| otherwise -> Nothing | |
cGroup : Int -> Maybe String | |
cGroup x = if | x `rem` 4 `div` 2 == 1 -> Just "w" | |
| otherwise -> Nothing | |
cUser : Int -> Maybe String | |
cUser x = if | x `rem` 4 `rem` 2 `div` 1 == 1 -> Just "x" | |
| otherwise -> Nothing | |
cNone : Int -> Maybe String | |
cNone x = if | x == 0 -> Just "none" | |
| otherwise -> Nothing | |
(strInput, strs) = Input.field "Permission string" | |
main = scene <~ Window.dimensions | |
~ strInput | |
~ getSources (dropRepeats strs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment