Skip to content

Commit

Permalink
Demonstrate basic Frame content compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
acook committed Oct 6, 2023
1 parent ac4662f commit 0b4dc40
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/remedy/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@ module Remedy
# Frames can be nested within other Frames or Panes
class Frame
def initialize
# origin is where the inner pane will be attached to
# origin is where the frame will be attached to
# :left, :right, :top, :bottom, :center
@origin = :center

# offset is what the offset from that origin the pane should be placed
# offset is what the offset from that origin the frame should be placed
@offset = Tuple.zero

# depth is the z index or layer, higher numbers cover lower numbers
# if two panes have the same layer but would overlap, then the one added most recently should come out on top
# if two frames have the same layer but would overlap, then the one added most recently should come out on top
@depth = 0

# arrangement, if this frame contains multiple panes, then they will be arranged according to this
# arrangement, if this frame contains multiple content items, then they will be arranged according to this
# :stacked, :columnar, :tabbed(?)
@arragement = :stacked

# the maximum size that this frame wants to be
# zero means fill
@max_size = Tuple.zero

# empty list of panes
@panes = Array.new
# empty list of contents
@contents = Array.new

# background fill
@fill = " "

# newline character
@nl = ?\n
end
attr_accessor :panes, :nl, :fill
attr_accessor :contents, :nl, :fill

def to_a
compile_panes
compile_contents
end

def to_s
compile_panes.join nl
compile_contents.join nl
end

def to_ansi
compile_panes.join ANSI.cursor.next_line
compile_contents.join ANSI.cursor.next_line
end

def compile_panes
panes
def compile_contents
contents.map{|c| Array c}.flatten
end
end
end
28 changes: 28 additions & 0 deletions spec/frame_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative "spec_helper"
require "remedy/frame"
require "remedy/partial"

describe Remedy::Frame do
subject(:f){ described_class.new }
Expand All @@ -19,4 +20,31 @@
expect(actual).to eq expected
end
end

describe "#compile_contents" do
it "compiles the contents of a single string" do
expected = "foo"
content = "foo"
f.contents << content
actual = f.to_s
expect(actual).to eq expected
end

it "compiles the contents of multiple strings" do
expected = "foo\nbar\nbaz"
f.contents << "foo"
f.contents << "bar"
f.contents << "baz"
actual = f.to_s
expect(actual).to eq expected
end

it "compiles the contents of partials" do
expected = "foo\nbar"
f.contents << "foo"
f.contents << ::Remedy::Partial.new(["bar"])
actual = f.to_s
expect(actual).to eq expected
end
end
end

0 comments on commit 0b4dc40

Please sign in to comment.