BUG: Fix categorical formatter not folding the output when it exceeds display width
State: closed

- [x] closes #12066
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Let me know if further refactoring is required.

Labels:
name: Bug
name: Output-Formatting
description: __repr__ of pandas objects, to_string
name: Categorical
description: Categorical Data Type

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=h1) Report
> Merging [#17639](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/f797c1dc8d838eb9df5ede3be681949dab852148?src=pr&el=desc) will **decrease** coverage by `0.02%`.
> The diff coverage is `85%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/17639/graphs/tree.svg?height=150&width=650&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17639      +/-   ##
==========================================
- Coverage   91.22%   91.19%   -0.03%     
==========================================
  Files         163      163              
  Lines       49655    49710      +55     
==========================================
+ Hits        45297    45334      +37     
- Misses       4358     4376      +18
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.99% <85%> (-0.01%)` | :arrow_down: |
| #single | `40.13% <1.66%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.59% <100%> (ø)` | :arrow_up: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `95.61% <84.74%> (-0.47%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.77% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=footer). Last update [f797c1d...640149e](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=h1) Report
> Merging [#17639](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/f797c1dc8d838eb9df5ede3be681949dab852148?src=pr&el=desc) will **decrease** coverage by `0.02%`.
> The diff coverage is `85%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/17639/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17639      +/-   ##
==========================================
- Coverage   91.22%   91.19%   -0.03%     
==========================================
  Files         163      163              
  Lines       49655    49710      +55     
==========================================
+ Hits        45297    45334      +37     
- Misses       4358     4376      +18
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.99% <85%> (-0.01%)` | :arrow_down: |
| #single | `40.13% <1.66%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.59% <100%> (ø)` | :arrow_up: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `95.61% <84.74%> (-0.47%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.77% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=footer). Last update [f797c1d...640149e](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=h1) Report
> Merging [#17639](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/f797c1dc8d838eb9df5ede3be681949dab852148?src=pr&el=desc) will **decrease** coverage by `0.02%`.
> The diff coverage is `85%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/17639/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17639      +/-   ##
==========================================
- Coverage   91.22%   91.19%   -0.03%     
==========================================
  Files         163      163              
  Lines       49655    49710      +55     
==========================================
+ Hits        45297    45334      +37     
- Misses       4358     4376      +18
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.99% <85%> (-0.01%)` | :arrow_down: |
| #single | `40.13% <1.66%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.59% <100%> (ø)` | :arrow_up: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `95.61% <84.74%> (-0.47%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.77% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=footer). Last update [f797c1d...640149e](https://codecov.io/gh/pandas-dev/pandas/pull/17639?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

can you rebase / update (and move whatsnew to 0.22.0)
closing as stale. if you want to re-visit this, pls ping.