diff --git a/README.md b/README.md index 882b3d6..c9fe474 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ project read `miso.yml` in the current directory (not in a parent). | `miso upgrade [VERSION]` | install the latest release (or `VERSION`) in place | | `miso uninstall [--yes]` | remove miso's files: in `$MISO_HOME` (packages, caches; the caches only when the folder holds nothing else) and the tool where `install.sh` put it (not one installed with nix). It shows what it removes and asks first; without a terminal it needs `--yes`. It lists the lines of your shell files that add miso to `PATH` (it does not edit them) | | `miso version` | the version of miso and of MicroHs (also `--version`) | -| `miso help` | the commands (also `--help`, or no command) | +| `miso help` | the commands (also `--help`, `-h`, or no command) | | `miso mhs ARGS` / `miso mcabal ARGS` | the MicroHs compiler, and MicroCabal | Output is colored on a terminal; set `NO_COLOR=1` to turn that off. diff --git a/docs/manual.md b/docs/manual.md index 74ea9bc..f9b095d 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -474,17 +474,20 @@ miso version miso --version ``` -Prints `miso VERSION (MicroHs VERSION)`. +Prints `miso VERSION (MicroHs VERSION)`. On a terminal, `miso --version` +shows the logo, a bowl of ramen, above it. ### miso help ``` miso help miso --help +miso -h miso ``` -Prints the commands. An unknown command prints them too, and fails. +Prints the commands, under the logo when the output is a terminal. An +unknown command prints them too (without the logo), and fails. `miso COMMAND --help` (or `-h`) prints the usage of that command, and does not run it. For `run` and `test`, which give their arguments to the diff --git a/src/Miso/CLI/Logo.hs b/src/Miso/CLI/Logo.hs new file mode 100644 index 0000000..8d1ab9e --- /dev/null +++ b/src/Miso/CLI/Logo.hs @@ -0,0 +1,84 @@ +-- | The miso logo: a bowl of ramen (🍜), in ASCII, shown by miso, miso +-- help (-h, --help) and miso --version when the output is a terminal. +module Miso.CLI.Logo (printLogo) where + +import Control.Monad (when) +import Data.List (groupBy) +import Data.Function (on) + +import Miso.CLI.Color + +-- | Print the logo, if stdout is a terminal (so $(miso --version) is one line). +printLogo :: IO () +printLogo = do + tty <- isTerminal + when tty $ do + ls <- mapM line (zip art paint) + putStrLn (unlines ls) + where + line (a, p) = concat <$> mapM run (groupBy ((==) `on` snd) (zip a (p ++ repeat ' '))) + run cs = colored 1 (colors (snd (head cs))) (map fst cs) + colors k = + case k of + 's' -> [Dim] -- steam + 'c' -> [Bold] -- chopsticks + 'n' -> [Yellow] -- noodles + 't' -> [Magenta] -- naruto and egg + 'b' -> [Red] -- the bowl + _ -> [] + +-- The art, generated, with paint: the color of each character +-- (s steam, c chopsticks, n noodles, t toppings, b bowl). +art :: [String] +art = + [ " / /" + , " ( ( ( / /" + , " ) ) ) / /" + , " ( ( ( / /" + , " ) ) ) / /" + , " ( ( ( / /" + , " ) ) ) / /" + , " ( ( ( / /" + , " / /" + , " _..--'''''''''''''''''''''''''/''/'''''''''''--.._" + , " .-'' ~~~~ ~~~~~ ~~~~~~ ~~~~~ /~~/~~ ~~~~~ ~~~~ ''-." + , " .' ~~~~ ~~~~ .-\"\"-. ~~~~~ ~~~ .--. ~~~~~ ~~~~ ~~~ '." + , " ( ~~~~~ ~~~ ( @ ) ~~~ ~~~~ ( () ) ~~~~ ~~~~~~ ~~ )" + , " |'-..~~~~~~ '-..-' ~~~~~~~~~~~ '--' ~~~~~~ ~~~~~~ __..-'|" + , " | ''''-----..............................-----'''' |" + , " \\ /" + , " \\ /" + , " '. .'" + , " '. .'" + , " '-._ _.-'" + , " '-..__ __..-'" + , " ''---..................---''" + , " |______________________|" + ] + +paint :: [String] +paint = + [ " c c" + , " s s s c c" + , " s s s c c" + , " s s s c c" + , " s s s c c" + , " s s s c c" + , " s s s c c" + , " s s s c c" + , " c c" + , " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcbbcbbbbbbbbbbbbbbbb" + , " bbbb nnnn nnnnn nnnnnn nnnnn cnncnn nnnnn nnnn bbbb" + , " bb nnnn nnnn tttttt nnnnn nnn tttt nnnnn nnnn nnn bb" + , " b nnnnn nnn t t t nnn nnnn t tt t nnnn nnnnnn nn b" + , " bbbbbnnnnnn tttttt nnnnnnnnnnn tttt nnnnnn nnnnnn bbbbbbb" + , " b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb b" + , " b b" + , " b b" + , " bb bb" + , " bb bb" + , " bbbb bbbb" + , " bbbbbb bbbbbb" + , " bbbbbbbbbbbbbbbbbbbbbbbbbbbb" + , " bbbbbbbbbbbbbbbbbbbbbbbb" + ] diff --git a/src/Miso/CLI/Main.hs b/src/Miso/CLI/Main.hs index 6c31586..99c5463 100644 --- a/src/Miso/CLI/Main.hs +++ b/src/Miso/CLI/Main.hs @@ -26,6 +26,7 @@ import Miso.CLI.Config import Miso.CLI.Deps import Miso.CLI.Docs (docs) import Miso.CLI.Doctor (doctor) +import Miso.CLI.Logo (printLogo) import Miso.CLI.Serve (dev, serve, watch) import Miso.CLI.Templates (licenseText, templateNames, templates) import Miso.CLI.Util @@ -103,10 +104,11 @@ main' = do ["upgrade"] -> upgrade Nothing ["upgrade", v] -> upgrade (Just v) ["version"] -> printVersion - ["--version"] -> printVersion - ["help"] -> usage - ["--help"] -> usage - [] -> usage + ["--version"] -> printLogo >> printVersion + ["help"] -> printLogo >> usage + ["--help"] -> printLogo >> usage + ["-h"] -> printLogo >> usage + [] -> printLogo >> usage _ -> usage >> failWith ("unknown command: miso " ++ unwords args) -- | The commands, in the sections of miso help: the command as typed,