generated from athena-framework/component-template
/
output_style_interface.cr
99 lines (94 loc) · 2.73 KB
/
output_style_interface.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require "colorize"
# Output styles represent reusable formatting information that can be used when formatting output messages.
# `Athena::Console` comes bundled with a few common styles including:
#
# * error
# * info
# * comment
# * question
#
# Whenever you output text via an `ACON::Output::Interface`, you can surround the text with tags to color its output. For example:
#
# ```
# # Green text
# output.puts "<info>foo</info>"
#
# # Yellow text
# output.puts "<comment>foo</comment>"
#
# # Black text on a cyan background
# output.puts "<question>foo</question>"
#
# # White text on a red background
# output.puts "<error>foo</error>"
# ```
#
# ## Custom Styles
#
# Custom styles can also be defined/used:
#
# ```
# my_style = ACON::Formatter::OutputStyle.new :red, "#f87b05", Colorize::Mode[:bold, :underline]
# output.formatter.set_style "fire", my_style
#
# output.puts "<fire>foo</>"
# ```
#
# ### Global Custom Styles
#
# You can also make your style global by extending `ACON::Application` and adding it within the `#configure_io` method:
#
# ```
# class MyCustomApplication < ACON::Application
# protected def configure_io(input : ACON::Input::Interface, output : ACON::Output::Interface) : Nil
# super
#
# my_style = ACON::Formatter::OutputStyle.new :red, "#f87b05", Colorize::Mode[:bold, :underline]
# output.formatter.set_style "fire", my_style
# end
# end
# ```
#
# ## Inline Styles
#
# Styles can also be defined inline when printing a message:
#
# ```
# # Using named colors
# output.puts "<fg=green>foo</>"
#
# # Using hexadecimal colors
# output.puts "<fg=#c0392b>foo</>"
#
# # Black text on a cyan background
# output.puts "<fg=black;bg=cyan>foo</>"
#
# # Bold text on a yellow background
# output.puts "<bg=yellow;options=bold>foo</>"
#
# # Bold text with underline.
# output.puts "<options=bold,underline>foo</>"
# ```
#
# ## Clickable Links
#
# Commands can use the special `href` tag to display links within the console.
#
# ```
# output.puts "<href=https://athenaframework.org>Athena</>"
# ```
#
# If your terminal [supports](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) it, you would be able to click
# the text and have it open in your default browser. Otherwise, you will see it as regular text.
module Athena::Console::Formatter::OutputStyleInterface
# Sets the foreground color of `self`.
abstract def foreground=(foreground : Colorize::Color)
# Sets the background color of `self`.
abstract def background=(background : Colorize::Color)
# Adds a text mode to `self`.
abstract def add_option(option : Colorize::Mode) : Nil
# Removes a text mode to `self`.
abstract def remove_option(option : Colorize::Mode) : Nil
# Applies `self` to the provided *text*.
abstract def apply(text : String) : String
end