Move COLORS and c() to BBS::Color in rubbs
include BBS::Color at top level — c() available everywhere including instance_eval blocks and OutputBuilder. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
14
bbs.rb
14
bbs.rb
@@ -7,21 +7,13 @@ require_relative 'lib/repository/message_board_repository'
|
|||||||
require_relative 'lib/repository/wiki_repository'
|
require_relative 'lib/repository/wiki_repository'
|
||||||
require_relative 'lib/repository/catalog_repository'
|
require_relative 'lib/repository/catalog_repository'
|
||||||
|
|
||||||
|
include BBS::Color
|
||||||
|
|
||||||
ONLINE = OnlineUsersRepository.new
|
ONLINE = OnlineUsersRepository.new
|
||||||
MESSAGES = MessageBoardRepository.new(ENV.fetch('MESSAGES_PATH', 'data/messages.dat'))
|
MESSAGES = MessageBoardRepository.new(ENV.fetch('MESSAGES_PATH', 'data/messages.dat'))
|
||||||
WIKI = WikiRepository.new(token: ENV['WEBAPP_WIKIJS_TOKEN'])
|
WIKI = WikiRepository.new(token: ENV['WEBAPP_WIKIJS_TOKEN'])
|
||||||
CATALOG = CatalogRepository.new
|
CATALOG = CatalogRepository.new
|
||||||
|
|
||||||
COLORS = {
|
|
||||||
reset: "\e[0m", gray: "\e[0;37m", yellow: "\e[0;33m",
|
|
||||||
white: "\e[1;37m", blue: "\e[0;34m", cyan: "\e[0;36m",
|
|
||||||
green: "\e[1;32m", magenta: "\e[0;35m", red: "\e[1;31m"
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
def c(color, text)
|
|
||||||
"#{COLORS.fetch(color)}#{text}#{COLORS[:reset]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
class OutputBuilder
|
class OutputBuilder
|
||||||
def initialize = (@buf = +''; @badges = [])
|
def initialize = (@buf = +''; @badges = [])
|
||||||
def to_s = (flush_badges; @buf)
|
def to_s = (flush_badges; @buf)
|
||||||
@@ -52,8 +44,6 @@ class OutputBuilder
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def c(color, text) = "#{COLORS.fetch(color)}#{text}#{COLORS[:reset]}"
|
|
||||||
|
|
||||||
def flush_badges
|
def flush_badges
|
||||||
return if @badges.empty?
|
return if @badges.empty?
|
||||||
@buf << " #{@badges.join(' ')}\r\n"
|
@buf << " #{@badges.join(' ')}\r\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user