Class: RubyRich::RichPrint
- Inherits:
-
Object
- Object
- RubyRich::RichPrint
- Defined in:
- lib/ruby_rich/print.rb
Instance Method Summary collapse
-
#initialize ⇒ RichPrint
constructor
A new instance of RichPrint.
- #print(*args) ⇒ Object
Constructor Details
#initialize ⇒ RichPrint
Returns a new instance of RichPrint.
3 4 5 |
# File 'lib/ruby_rich/print.rb', line 3 def initialize @style_regex = /\[([\w\s]+)\](.*?)\[\/[\w]*\]/ end |
Instance Method Details
#print(*args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_rich/print.rb', line 7 def print(*args) processed_args = args.map do |arg| next arg unless arg.is_a?(String) # 处理表情符号 text = if arg.start_with?(':') && arg.end_with?(':') Emoji.find_by_alias(arg[1..-2])&.raw || arg else arg end # 处理样式标记 while text.match?(@style_regex) text = text.gsub(@style_regex) do |_| style, content = $1, $2 apply_style(content, style) end end text end puts processed_args.join(' ') end |