Skip to content

Fix indent bug for tables without headers (issue piotrmurach/tty-table/issues/45)#44

Open
rogermarlow wants to merge 8 commits intopiotrmurach:masterfrom
rogermarlow:fix/indent_tables_without_headers
Open

Fix indent bug for tables without headers (issue piotrmurach/tty-table/issues/45)#44
rogermarlow wants to merge 8 commits intopiotrmurach:masterfrom
rogermarlow:fix/indent_tables_without_headers

Conversation

@rogermarlow
Copy link
Copy Markdown

@rogermarlow rogermarlow commented Mar 14, 2024

Describe the change

There is a bug rendering tables without headers with an indent. The top border is not indented.

Why are we doing this?

Bug fix.

Benefits

Bug fix.

Drawbacks

None.

Here is come code that demonstrates the problem:

require 'tty-table'

ok = TTY::Table.new(header: ["Home","H","A","Away"])
ok << ["team1",1,2,"team2"]
ok << ["team3",0,1,"team4"]

puts ok.render(:unicode, indent: 12)

broken = TTY::Table.new
broken << ["team1",1,2,"team2"]
broken << ["team3",0,1,"team4"]

puts broken.render(:unicode, indent: 12)

            ┌─────┬─┬─┬─────┐
            │Home │H│A│Away 
            ├─────┼─┼─┼─────┤
            │team1│1│2│team2│
            │team3│0│1│team4│
            └─────┴─┴─┴─────┘
┌─────┬─┬─┬─────┐
            │team1│1│2│team2│
            │team3│0│1│team4│
            └─────┴─┴─┴─────┘

Requirements

  • Tests written & passing locally?
  • Code style checked?
  • Rebased with master branch?
  • Documentation updated?
  • Changelog updated?

it "indents top border correctly" do
table = TTY::Table.new
table << ["a1","a2","a3"]
table << ["b1","b2","b3"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/WordArray: Use %w or %W for an array of words.
Layout/SpaceAfterComma: Space missing after comma.

RSpec.describe TTY::Table::Renderer::ASCII, 'indentation without headers' do
it "indents top border correctly" do
table = TTY::Table.new
table << ["a1","a2","a3"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/WordArray: Use %w or %W for an array of words.
Layout/SpaceAfterComma: Space missing after comma.

end
end

RSpec.describe TTY::Table::Renderer::ASCII, 'indentation without headers' do
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@rogermarlow rogermarlow changed the title Fix indent bug for tables without headers Fix indent bug for tables without headers (issue piotrmurach/tty-table/issues/45) Mar 14, 2024
@rogermarlow
Copy link
Copy Markdown
Author

This has failed at appveyor because of a github connectivity issue rather than a test failure. I don't know how to re-run the job so I will push a trivial change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants