效果 before
over
代码,只是思路伟码。
# encoding: UTF-8
require 'pry-debugger'
require "terminal-table"
class String
def size
self.encode('gbk').bytesize
end
end
module Terminal
class Table
class Cell
def render(line = 0)
left = " " * @table.style.padding_left
right = " " * @table.style.padding_right
render_width = lines[line].size - escape(lines[line]).size + width - (lines[line].size-lines[line].length)
"#{left}#{lines[line]}#{right}".align(alignment, render_width + @table.cell_padding)
end
end
end
rows = []
rows << ['O哈哈123ne', '明知山有虎',1]
rows << ['TwooTT','偏 向', 2]
rows << ['中国人', '土[email protected]',3]
table = Terminal::Table.new :rows => rows
# binding.pry
puts table