class Clio::Layout::Split
TODO: name LeftRight instead?
Constants
- FILL
- PAD
- RATIO
Attributes
fill[RW]
left[RW]
pad[RW]
ratio[RW]
right[RW]
Public Class Methods
new(left, right, options={})
click to toggle source
# File lib/clio/layout/split.rb, line 26 def initialize(left, right, options={}) @left = left @right = right @fill = FILL @ratio = RATIO @pad = PAD options.each do |k,v| send("#{k}=",v) if respond_to?("#{k}=") end end
Public Instance Methods
fill=(letter)
click to toggle source
# File lib/clio/layout/split.rb, line 51 def fill=(letter) case letter when '', nil letter = ' ' else letter = letter[0,1] end @fill = letter end
print()
click to toggle source
# File lib/clio/layout/split.rb, line 39 def print print_justified(@left, @right) end
ratio=(value)
click to toggle source
# File lib/clio/layout/split.rb, line 43 def ratio=(value) if value < 0 @ratio = 1 + value else @ratio = value end end
to_s()
click to toggle source
# File lib/clio/layout/split.rb, line 61 def to_s print_justified(left, right) end
Private Instance Methods
print_justified(left, rite)
click to toggle source
Print a justified line with left and right entries.
A fill option can be given to fill in any empty space between the two. And a ratio option can be given which defaults to 0.8 (eg. 80/20)
# File lib/clio/layout/split.rb, line 73 def print_justified(left, rite) left_size = left.size rite_size = rite.size left = left.to_s rite = rite.to_s width = screen_width l = (width * ratio).to_i r = width - l left = left[0,l] rite = rite[0,r] str = fill * width str[0,pad.size] = pad str[pad.size,left_size] = left str[-(pad.size+rite_size), rite_size] = rite str[-pad.size, pad.size] = pad Kernel.print(str) end
screen_width()
click to toggle source
# File lib/clio/layout/split.rb, line 99 def screen_width @screen_width ||= Terminal.screen_width end