Add fill/screen_fill primitives and string style support
New drawing primitives: fill(x:, y:, w:, h:, bg:) — fills a rectangle with background color screen_fill(bg:) — fills the entire terminal Box now accepts bg: which fills its interior with a background color. All drawing methods (text, bar, list, box) now accept raw ANSI escape strings as style/highlight values in addition to named symbols. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,12 @@ module BBS
|
|||||||
class Context
|
class Context
|
||||||
STYLES = FlowRunner::STYLES
|
STYLES = FlowRunner::STYLES
|
||||||
|
|
||||||
|
BG_COLORS = {
|
||||||
|
black: "\e[40m", red: "\e[41m", green: "\e[42m",
|
||||||
|
yellow: "\e[43m", blue: "\e[44m", cyan: "\e[46m",
|
||||||
|
white: "\e[47m",
|
||||||
|
}.freeze
|
||||||
|
|
||||||
def initialize(session, session_id, tui)
|
def initialize(session, session_id, tui)
|
||||||
@session = session
|
@session = session
|
||||||
@session_id = session_id
|
@session_id = session_id
|
||||||
@@ -84,7 +90,7 @@ module BBS
|
|||||||
|
|
||||||
def text(content, x: nil, y: nil, style: nil)
|
def text(content, x: nil, y: nil, style: nil)
|
||||||
at(x, y) if x && y
|
at(x, y) if x && y
|
||||||
color = STYLES[style]
|
color = resolve_style(style)
|
||||||
@buf << (color ? "#{color}#{content}\e[0m" : content.to_s)
|
@buf << (color ? "#{color}#{content}\e[0m" : content.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -94,30 +100,44 @@ module BBS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def list(items, x:, y:, selected: nil, style: :muted, highlight: :success)
|
def list(items, x:, y:, selected: nil, style: :muted, highlight: :success)
|
||||||
norm = STYLES.fetch(style, STYLES[:muted])
|
norm = resolve_style(style) || STYLES[:muted]
|
||||||
hi = STYLES.fetch(highlight, STYLES[:success])
|
hi = resolve_style(highlight) || STYLES[:success]
|
||||||
items.each_with_index do |item, i|
|
items.each_with_index do |item, i|
|
||||||
at x, y + i
|
at x, y + i
|
||||||
@buf << (i == selected ? "#{hi}▶ #{item}\e[0m" : "#{norm} #{item}\e[0m")
|
@buf << (i == selected ? "#{hi}▶ #{item}\e[0m" : "#{norm} #{item}\e[0m")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def box(x:, y:, w:, h:, title: nil, style: :muted)
|
def fill(x:, y:, w:, h:, bg:)
|
||||||
color = STYLES.fetch(style, STYLES[:muted])
|
color = BG_COLORS.fetch(bg, bg.to_s)
|
||||||
inner = w - 2
|
h.times do |dy|
|
||||||
|
at x, y + dy
|
||||||
|
@buf << "#{color}#{' ' * w}\e[0m"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def screen_fill(bg:)
|
||||||
|
fill(x: 1, y: 1, w: term_cols, h: term_rows, bg: bg)
|
||||||
|
end
|
||||||
|
|
||||||
|
def box(x:, y:, w:, h:, title: nil, style: :muted, bg: nil)
|
||||||
|
color = resolve_style(style) || STYLES[:muted]
|
||||||
|
inner = w - 2
|
||||||
|
bg_str = bg ? BG_COLORS.fetch(bg, bg.to_s) : nil
|
||||||
|
|
||||||
at x, y
|
at x, y
|
||||||
if title
|
if title
|
||||||
prefix = "══ #{title} "
|
prefix = "══ #{title} "
|
||||||
fill = [inner - prefix.length, 0].max
|
pad = [inner - prefix.length, 0].max
|
||||||
@buf << "#{color}╔#{prefix}#{'═' * fill}╗\e[0m"
|
@buf << "#{color}╔#{prefix}#{'═' * pad}╗\e[0m"
|
||||||
else
|
else
|
||||||
@buf << "#{color}╔#{'═' * inner}╗\e[0m"
|
@buf << "#{color}╔#{'═' * inner}╗\e[0m"
|
||||||
end
|
end
|
||||||
|
|
||||||
(1...h - 1).each do |dy|
|
(1...h - 1).each do |dy|
|
||||||
at x, y + dy
|
at x, y + dy
|
||||||
@buf << "#{color}║\e[0m#{' ' * inner}#{color}║\e[0m"
|
interior = bg_str ? "#{bg_str}#{' ' * inner}\e[0m" : ' ' * inner
|
||||||
|
@buf << "#{color}║\e[0m#{interior}#{color}║\e[0m"
|
||||||
end
|
end
|
||||||
|
|
||||||
at x, y + h - 1
|
at x, y + h - 1
|
||||||
@@ -125,6 +145,15 @@ module BBS
|
|||||||
|
|
||||||
yield x + 1, y + 1, inner, h - 2 if block_given?
|
yield x + 1, y + 1, inner, h - 2 if block_given?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def resolve_style(style)
|
||||||
|
case style
|
||||||
|
when Symbol then STYLES[style]
|
||||||
|
when String then style
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user