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

New repo code review #11

Merged
merged 17 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONRTIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

## Reporting Bugs

When submitting a new bug report, please first [search](https://github.com/oclif/multi-stage-output/issues) for an existing or similar report & then use one of our existing [issue templates](https://github.com/oclif/multi-stage-output/issues/new/choose) if you believe you've come across a unique problem. Duplicate issues, or issues that don't use one of our templates may get closed without a response.
When submitting a new bug report, please first [search](https://github.com/oclif/table/issues) for an existing or similar report & then use one of our existing [issue templates](https://github.com/oclif/table/issues/new/choose) if you believe you've come across a unique problem. Duplicate issues, or issues that don't use one of our templates may get closed without a response.

## Development

**1. Clone this repository...**

```bash
$ git clone [email protected]:oclif/multi-stage-output.git
$ git clone [email protected]:oclif/table.git
```

**2. Navigate into project & install development-specific dependencies...**

```bash
$ cd ./multi-stage-output && yarn
$ cd ./table && yarn
```

**3. Write some code &/or add some tests...**
Expand All @@ -30,7 +30,7 @@ $ cd ./multi-stage-output && yarn
$ yarn test
```

**5. Open a [Pull Request](https://github.com/oclif/multi-stage-output/pulls) for your work & become the newest contributor to `@oclif/multi-stage-output`! 🎉**
**5. Open a [Pull Request](https://github.com/oclif/table/pulls) for your work & become the newest contributor to `@oclif/table`! 🎉**

## Pull Request Conventions

Expand Down
3 changes: 3 additions & 0 deletions examples/multiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const projects = [
},
]

// Occasionally, if you have two maxWidths that add up to 100% they will stack vertically instead of horizontally.
// At first I thought this might be when the window has an odd number of pixels, but it seems to be more random than that.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-10-03 at 10 19 33 AM Screenshot 2024-10-03 at 10 20 08 AM


const employeesTable: TableOptions<(typeof employees)[number]> = {
columns: ['id', 'name', 'age', 'description'],
data: employees,
Expand Down
21 changes: 21 additions & 0 deletions examples/orientation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ printTable({
titleOptions: {bold: true},
})

// When the vertical orientation table wraps, the "value" does not stay in its column
// Example (note the "description" column):
//
// ──────────────────────────────────────────────────────────────────────────────────────
// Item Item 1
// Description
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor
// incididunt ut labore et dolore magna aliqua.
// Url https://www.example.com/item/1
//
// I would expect it to look like this:
//
// Example (note the "description" column):
// ------------------------------------------------
// Item Item 1
// Description Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
// eiusmod tempor incididunt ut labore et dolore magna aliqua.
// Url https://www.example.com/item/1



printTable({
columns: ['item', 'description', 'url'],
data,
Expand Down
32 changes: 32 additions & 0 deletions examples/overflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ printTable({
titleOptions: {bold: true},
})

// I would expect this for wrapping on align-center:
//
// Wrap (aligned center)
// ┌───────┬─────────┬─────┬───────────────────────────────────────────────────────────────────────────┐
// │ Id │ Name │ Age │ Description │
// ├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
// │ 36329 │ Alice │ 20 │ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod │
// │ │ │ │ tempor incididunt ut labore et dolore magna aliqua. │
// ├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
// │ 49032 │ Bob │ 21 │ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod │
// │ │ │ │ tempor incididunt ut labore et dolore magna aliqua. │
// ├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
// │ 51786 │ Charlie │ 22 │ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod │
// │ │ │ │ tempor incididunt ut labore et dolore magna aliqua. │
// └───────┴─────────┴─────┴───────────────────────────────────────────────────────────────────────────┘

printTable({
columns: ['id', 'name', 'age', 'description'],
data,
Expand All @@ -84,6 +100,22 @@ printTable({
titleOptions: {bold: true},
})

// Similar for align-right:
//
// Wrap (aligned right)
// ┌───────┬─────────┬─────┬───────────────────────────────────────────────────────────────────────────┐
// │ Id │ Name │ Age │ Description │
// ├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
// │ 36329 │ Alice │ 20 │ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod │
// │ │ │ │ tempor incididunt ut labore et dolore magna aliqua. │
// ├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
// │ 49032 │ Bob │ 21 │ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod │
// │ │ │ │ tempor incididunt ut labore et dolore magna aliqua. │
// ├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
// │ 51786 │ Charlie │ 22 │ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod │
// │ │ │ │ tempor incididunt ut labore et dolore magna aliqua. │
// └───────┴─────────┴─────┴───────────────────────────────────────────────────────────────────────────┘

printTable({
columns: ['id', 'name', 'age', 'description'],
data,
Expand Down
4 changes: 2 additions & 2 deletions examples/sort-and-filter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {printTable} from '../src/index.js'

const data = [
{age: 25, id: '10245', name: 'Bob'},
{age: 26, id: '10345', name: 'Bill'},
{age: 100, id: '10245', name: 'Bob'},
{age: 10, id: '10345', name: 'Bill'},
{age: 30, id: '20245', name: 'Alice'},
{age: 20, id: '20345', name: 'Amy'},
{age: 30, id: '30245', name: 'Charlie'},
Expand Down
13 changes: 13 additions & 0 deletions examples/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@
})
console.log()
}

printTable({
borderStyle: 'all',
columns: ['id', {key: 'name', name: 'First Name'}, 'age'],
data,
headerOptions: {
formatter: 'capitalCase',
},
horizontalAlignment: 'center',
title: 'Remove style with "noStyle: true"',
titleOptions: {bold: true},
noStyle: true,

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (current)

Expected "noStyle" to come before "titleOptions"

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (current)

Expected "noStyle" to come before "titleOptions"

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (current)

Expected "noStyle" to come before "titleOptions"

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (lts/*)

Expected "noStyle" to come before "titleOptions"

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (lts/*)

Expected "noStyle" to come before "titleOptions"

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (lts/*)

Expected "noStyle" to come before "titleOptions"

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (lts/-1)

Expected "noStyle" to come before "titleOptions"

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (lts/-1)

Expected "noStyle" to come before "titleOptions"

Check failure on line 47 in examples/styles.ts

View workflow job for this annotation

GitHub Actions / linux-unit-tests / linux-unit-tests (lts/-1)

Expected "noStyle" to come before "titleOptions"
})
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"description": "Display table in terminal",
"version": "0.1.10",
"author": "Salesforce",
"bugs": "https://github.com/oclif/multi-stage-output/issues",
"bugs": "https://github.com/oclif/table/issues",
"dependencies": {
"@oclif/core": "^4",
"@types/react": "^18.3.10",
"change-case": "^5.4.4",
"cli-truncate": "^4.0.0",
"ink": "^5.0.1",
Expand All @@ -23,6 +22,7 @@
"@types/mocha": "^10.0.8",
"@types/node": "^18",
"@types/object-hash": "^3.0.6",
"@types/react": "^18.3.10",
"@types/sinon": "^17.0.3",
"ansis": "^3.3.2",
"chai": "^4.5.0",
Expand Down Expand Up @@ -52,7 +52,7 @@
"files": [
"/lib"
],
"homepage": "https://github.com/oclif/core",
"homepage": "https://github.com/oclif/table",
"keywords": [
"oclif",
"cli",
Expand All @@ -62,7 +62,7 @@
"exports": {
".": "./lib/index.js"
},
"repository": "oclif/core",
"repository": "oclif/table",
"publishConfig": {
"access": "public"
},
Expand Down
1 change: 1 addition & 0 deletions src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ export function Skeleton(props: React.PropsWithChildren & {readonly height?: num
export function printTable<T extends Record<string, unknown>>(options: TableOptions<T>): void {
const instance = render(<Table {...options} />)
instance.unmount()
// It might be nice to have a "paddingBefore" and "paddingAfter" option for the number of newlines to enter.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary. People can print as many newlines as they want before or after the table. This new line only exists because, otherwise, the next output will appear on the same line as the last line of the table. For example

┌───────┬─────────┬─────┬───────────────────────────────────────────────────────────────────────────┐
│  Id   │  Name   │ Age │                                Description                                │
├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
│ 36329 │  Alice  │ 20  │  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod  │
│       │         │     │            tempor incididunt ut labore et dolore magna aliqua.            │
├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
│ 49032 │   Bob   │ 21  │  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod  │
│       │         │     │            tempor incididunt ut labore et dolore magna aliqua.            │
├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
│ 51786 │ Charlie │ 22  │  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod  │
│       │         │     │            tempor incididunt ut labore et dolore magna aliqua.            │
└───────┴─────────┴─────┴───────────────────────────────────────────────────────────────────────────┘my next line

process.stdout.write('\n')
}

Expand Down
Loading