Show ASCII table: Difference between revisions

Content added Content deleted
(Add QB64)
Line 2,455: Line 2,455:
import Data.List (transpose)
import Data.List (transpose)
import Data.List.Split (chunksOf)
import Data.List.Split (chunksOf)
import Text.Printf (printf)


----------------------- ASCII TABLE ----------------------
main :: IO ()
main = putStrLn asciiTable


asciiTable :: String
asciiTable :: String
asciiTable =
asciiTable =
unlines $
unlines $
(justifyLeft 12 ' ' =<<)
(printf "%-12s" =<<)
<$> transpose
<$> transpose
(chunksOf 16 $ asciiEntry <$> [32 .. 127])
(chunksOf 16 $ asciiEntry <$> [32 .. 127])
Line 2,469: Line 2,469:
asciiEntry n
asciiEntry n
| null k = k
| null k = k
| otherwise =
| otherwise = concat [printf "%3d" n, " : ", k]
concat
[justifyRight 4 ' ' (show n), " : ", k]
where
where
k = asciiName n
k = asciiName n
Line 2,483: Line 2,481:
| otherwise = [chr n]
| otherwise = [chr n]



justifyLeft, justifyRight :: Int -> Char -> String -> String
--------------------------- TEST -------------------------
justifyLeft n c s = take n (s <> replicate n c)
main :: IO ()
justifyRight n c = (drop . length) <*> (replicate n c <>)</lang>
main = putStrLn asciiTable
</lang>
{{Out}}
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p