piotrmurach / tty-table

A flexible and intuitive table generator
https://ttytoolkit.org
MIT License
195 stars 22 forks source link

How to force table to rotate vertically #8

Open summera opened 8 years ago

summera commented 8 years ago

Maybe I'm missing something here, but when I try to render a table that is larger than the terminal window, tty-table throws Table's width is too small to contain the content (min width 3999, currently set 3999). When I mess with resize and width options, the table still does not want to rotate.

If I try

table.render width: 4000, resize: true

it throws NoMethodError: undefined method 'rindex' for nil:NilClass.

How do I get the table to flip vertically if it is too large? Also, can I have it so that the content overflows horizontally?

piotrmurach commented 8 years ago

Thanks for using the library!

It has some rough edges still, auto resizing is one of them. However, you should be able to flip the orientation:

table = TTY::Table.new ..... orientation: :vertical
summera commented 8 years ago

@peter-murach thanks for quick response

Just tried as you said, but something odd is happening

>> x = []
=> []
>> 2000.times{ |i| x <<i }
=> 2000
>> require 'tty-table'
=> true
>> table = TTY::Table.new [x, x], orientation: :vertical
=> #<TTY::Table header=nil rows=[#<TTY::Table::Row fields=["1", 0]>, #<TTY::Table::Row fields=["2", 1]>, #<TTY::Table::Row fields=["3", 2]>, #<TTY::Table::Row fields=["1", 0]>, #<TTY::Table::Row fields=["2", 1]>, #<TTY::Table::Row fields=["3", 2]>] orientation=#<TTY::Table::Orientation::Vertical:0x007fd439cd1530 @name=:vertical> original_rows=2 original_columns=2000>
>> puts table
1 0
2 1
3 2
1 0
2 1
3 2
=> nil
epinault commented 7 years ago

I have a similar issue. The vertical rotate is nice. But if my terminal is too small and resize is set to true, I get the NoMethodError: undefined method 'rindex' for nil:NilClass in truncate. I would be in favor of either throw an something that force to turn of resize true, or send a message to the user the table is to big for the terminal and need to be expanded or switch the resize to false to have vertical row..

SpComb commented 6 years ago

Full backtrace for the resize: true bug when the terminal width is too small for a column:

NoMethodError: undefined method `rindex' for nil:NilClass
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/verse-0.5.0/lib/verse/truncation.rb:71:in `truncate'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/verse-0.5.0/lib/verse/truncation.rb:36:in `truncate'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/verse-0.5.0/lib/verse.rb:47:in `truncate'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operation/truncation.rb:38:in `call'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:65:in `block (4 levels) in run_operations'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:64:in `each'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:64:in `block (3 levels) in run_operations'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:63:in `each'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:63:in `block (2 levels) in run_operations'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:61:in `each'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:61:in `each_with_index'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:61:in `block in run_operations'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:60:in `each'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:60:in `each_with_index'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/operations.rb:60:in `run_operations'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/renderer/basic.rb:203:in `render'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/renderer.rb:96:in `render'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table/renderer.rb:77:in `render_with'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table.rb:451:in `render_with'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/tty-table-0.9.0/lib/tty/table.rb:425:in `render'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:74:in `render'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:35:in `generate_table'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:39:in `print_table'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/containers/list_command.rb:25:in `execute'
  /home/kontena/kontena/kontena/cli/lib/kontena/command.rb:216:in `run'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/clamp-1.2.1/lib/clamp/subcommand/execution.rb:11:in `execute'
  /home/kontena/kontena/kontena/cli/lib/kontena/command.rb:216:in `run'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/clamp-1.2.1/lib/clamp/subcommand/execution.rb:11:in `execute'
  /home/kontena/kontena/kontena/cli/lib/kontena/command.rb:216:in `run'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/clamp-1.2.1/lib/clamp/command.rb:132:in `run'
  bin/kontena:22:in `<top (required)>'