-
Notifications
You must be signed in to change notification settings - Fork 7
Tables
Javier Olaechea edited this page Nov 4, 2018
·
9 revisions
Tables are an nice way to present some data. All tables are sortable by their columns and vertical plus horizontal Highlighting is build in.
screen = RuTui::Screen.new
@table = RuTui::Table.new({
:x => 1, # X Position (must have)
:y => 1, # Y Position (must have)
:highlight_direction => :horizontal, # direction which can be highlighted, default :horizontal
:table => [
[1,"Some", "random","example"],
[2,"text", "presented", "in"],
[3,"an", "table","plus some random way to long text"]
], # table content (rows should have the same size)
:cols => [
{ :title => "ID", :title_color => Pixel.random.fg, :length => 3 },
{ :title => "Col 1", :color => Pixel.random.fg, :title_color => Pixel.random.fg },
{ :title => "Col 2", :color => Pixel.random.fg, :title_color => Pixel.random.fg },
{ :title => "Col 3", :max_length => 10 }
], # cols definitions, NOTE: :max_length & :length
:header => true, # show the header
:hover => 32, # hover color (default: none)
:background => 30, # background color (default: by theme)
:foreground => 122 # foreground color (default: by theme)
})
screen.add @table
Just tell the table which column should be ordered
@table.sort 1
@table.highlight_direction = :vertical
RuTui::ScreenManager.loop({ :autodraw => true }) do |key|
break if key.chr == "q" or key == 3 # CTRL+C
(@table.highlight += 1) if key.chr == "d" and highlight < @table.width-1
(@table.highlight -= 1) if key.chr == "a" and highlight >= 1
if key.chr == "x"
@table.sort @table.highlight
end
end
@table.add [4,"Another","Random","Row"]
@table.delete 3
All data is accessible via attributes, like
@table.table # returns the data table
To set and restructure the whole data table use
@table.set_table new_table