diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2014-05-08 20:13:29 +0200 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2014-05-08 20:13:29 +0200 |
commit | 8b203a8379018e04d5ead2bfd1080863534b7fdb (patch) | |
tree | 4cb0d499db2f6d5315adcf1489a4e865891999ea /lib/elixir/lib/io/ansi/docs.ex | |
parent | de26484bdab3cb033ad4086c33d9587953d0253b (diff) | |
download | elixir-8b203a8379018e04d5ead2bfd1080863534b7fdb.tar.gz |
Use IO.ANSI.Docs to format mix help
Diffstat (limited to 'lib/elixir/lib/io/ansi/docs.ex')
-rw-r--r-- | lib/elixir/lib/io/ansi/docs.ex | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/lib/elixir/lib/io/ansi/docs.ex b/lib/elixir/lib/io/ansi/docs.ex index 3e733f0c1..19a7cb3fa 100644 --- a/lib/elixir/lib/io/ansi/docs.ex +++ b/lib/elixir/lib/io/ansi/docs.ex @@ -3,23 +3,42 @@ defmodule IO.ANSI.Docs do @bullets [?*, ?-, ?+] - @default_options [enabled: true, - doc_code: "cyan,bright", - doc_inline_code: "cyan", - doc_headings: "yellow,bright", - doc_title: "reverse,yellow,bright", - doc_bold: "bright", - doc_underline: "underline", - width: 80] + @doc """ + The default options used by this module. + + The supported values are: + + * `:enabled` - toggles coloring on and off (true) + * `:doc_code` - code blocks (cyan, bright) + * `:doc_inline_code` - inline code (cyan) + * `:doc_headings` - h1 and h2 headings (yellow, bright) + * `:doc_title` - top level heading (reverse, yellow, bright) + * `:doc_bold` - bold text (bright) + * `:doc_underline` - underlined text (underline) + * `:width` - the width to format the text (80) + + Values for the color settings are strings with + comma-separated ANSI values. + """ + def default_options do + [enabled: true, + doc_code: "cyan,bright", + doc_inline_code: "cyan", + doc_headings: "yellow,bright", + doc_title: "reverse,yellow,bright", + doc_bold: "bright", + doc_underline: "underline", + width: 80] + end @doc """ Prints the head of the documentation (i.e. the function signature). - See `print/3` for docs on the supported options. + See `default_options/0` for docs on the supported options. """ def print_heading(heading, options \\ []) do IO.puts IO.ANSI.reset - options = Keyword.merge(@default_options, options) + options = Keyword.merge(default_options, options) width = options[:width] padding = div(width + String.length(heading), 2) heading = heading |> String.rjust(padding) |> String.ljust(width) @@ -29,25 +48,11 @@ defmodule IO.ANSI.Docs do @doc """ Prints the documentation body. - In addition to the priting string, takes a truth value for whether to use ANSI - escape codes, and a keyword list for the printing color settings. Supported - options are: - - * `:enabled` - toggles coloring on and off (true) - * `:doc_code` - code blocks (cyan, bright) - * `:doc_inline_code` - inline code (cyan) - * `:doc_headings` - h1 and h2 headings (yellow, bright) - * `:doc_title` - top level heading (reverse, yellow, bright) - * `:doc_bold` - bold text (bright) - * `:doc_underline` - underlined text (underline) - * `:width` - the width to format the text - - Values for the color settings are strings with comma-separated - ansi values. - + In addition to the priting string, takes a set of options + defined in `default_options/1`. """ def print(doc, options \\ []) do - options = Keyword.merge(@default_options, options) + options = Keyword.merge(default_options, options) doc |> String.split(["\r\n","\n"], trim: false) |> Enum.map(&String.rstrip/1) |