@@ -11,42 +11,12 @@ defmodule IO.ANSI.Docs do
1111 doc_bold: "bright" ,
1212 doc_underline: "underline" ]
1313
14- @ shared_print_doc """
15- In addition to the priting string, takes a truth value for whether to use ANSI
16- escape codes, and a keyword list for the printing color settings. Supported
17- keys for the color settings are:
18-
19- * `:enabled` - toggles coloring on and off (true)
20- * `:doc_code` - code blocks (cyan, bright)
21- * `:doc_inline_code` - inline code (cyan)
22- * `:doc_headings` - h1 and h2 headings (yellow, bright)
23- * `:doc_title` - top level heading (reverse, yellow, bright)
24- * `:doc_bold` - bold text (bright)
25- * `:doc_underline` - underlined text (underline)
26-
27- Values for the color settings are strings with comma-separated attributes.
28- Supported attributes are:
29-
30- * Colors: `black red green yellow blue magenta cyan white`
31- * Intensity: `normal bright`
32- * Decoration: `underline reverse`
33- """
34-
3514 @ doc """
3615 Prints the head of the documentation (i.e. the function signature).
3716
38- #{ @ shared_print_doc }
17+ See `print/3` for docs on the supported options.
3918 """
40- def print_heading ( string , use_ansi // IO.ANSI . terminal? , colors // @ default_colors ) do
41- if use_ansi do
42- write_doc_heading ( string , colors )
43- else
44- IO . puts "* #{ string } \n "
45- end
46- dont_display_result
47- end
48-
49- defp write_doc_heading ( heading , colors ) do
19+ def print_heading ( heading , colors // @ default_colors ) do
5020 IO . puts IO.ANSI . reset
5121 width = column_width ( )
5222 padding = div ( width + String . length ( heading ) , 2 )
@@ -57,22 +27,32 @@ defmodule IO.ANSI.Docs do
5727 @ doc """
5828 Prints the documentation body.
5929
60- #{ @ shared_print_doc }
30+ In addition to the priting string, takes a truth value for whether to use ANSI
31+ escape codes, and a keyword list for the printing color settings. Supported
32+ keys for the color settings are:
33+
34+ * `:enabled` - toggles coloring on and off (true)
35+ * `:doc_code` - code blocks (cyan, bright)
36+ * `:doc_inline_code` - inline code (cyan)
37+ * `:doc_headings` - h1 and h2 headings (yellow, bright)
38+ * `:doc_title` - top level heading (reverse, yellow, bright)
39+ * `:doc_bold` - bold text (bright)
40+ * `:doc_underline` - underlined text (underline)
41+
42+ Values for the color settings are strings with comma-separated attributes.
43+ Supported attributes are:
44+
45+ * Colors: `black red green yellow blue magenta cyan white`
46+ * Intensity: `normal bright`
47+ * Decoration: `underline reverse`
6148 """
62- def print ( doc , use_ansi // IO.ANSI . terminal? , colors // @ default_colors ) do
63- if use_ansi do
64- doc
65- |> String . split ( [ "\r \n " , "\n " ] , trim: false )
66- |> Enum . map ( & String . rstrip / 1 )
67- |> process ( "" , colors )
68- else
69- IO . puts doc
70- end
71- dont_display_result
49+ def print ( doc , colors // @ default_colors ) do
50+ doc
51+ |> String . split ( [ "\r \n " , "\n " ] , trim: false )
52+ |> Enum . map ( & String . rstrip / 1 )
53+ |> process ( "" , colors )
7254 end
7355
74- defp dont_display_result , do: :"do not show this result in output"
75-
7656 defp process ( [ ] , _indent , _colors ) , do: nil
7757
7858 defp process ( [ "# " <> heading | rest ] , _indent , colors ) do
0 commit comments