Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

rogermarlow
Copy link

@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"]

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"]

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.

@@ -37,3 +37,17 @@
end
end
end

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

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