Ruby 修改 terminal-table 显示中文对不齐的问题。

hhuai · 2012年09月28日 · 最后由 kennizchan 回复于 2012年09月28日 · 11186 次阅读

效果 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

看到这图突然想到一个问题,mysql 在命令行下查询,列太多的话排版就破了,楼主有办法吗?

使用\G: select * from users\G

需要 登录 后方可回复, 如果你还没有账号请 注册新账号