php-school / cli-menu

🖥 Build beautiful PHP CLI menus. Simple yet Powerful. Expressive DSL.
http://www.phpschool.io
MIT License
1.94k stars 106 forks source link

Fix various width issues #220

Closed AydinHassan closed 4 years ago

AydinHassan commented 4 years ago

Hopefully this should fix #219. This has taken me all day to fix 😭

Also adds a few utils, debug mode for menu style and mock terminal class for tests.

Going to add a few more tests for the changes regarding width and margins.

codecov-io commented 4 years ago

Codecov Report

Merging #220 into master will increase coverage by <.01%. The diff coverage is 97.61%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #220      +/-   ##
============================================
+ Coverage     93.01%   93.02%   +<.01%     
- Complexity      591      606      +15     
============================================
  Files            30       31       +1     
  Lines          1761     1791      +30     
============================================
+ Hits           1638     1666      +28     
- Misses          123      125       +2
Impacted Files Coverage Δ Complexity Δ
src/Util/StringUtil.php 100% <100%> (ø) 8 <2> (+2) :arrow_up:
src/Util/ArrayUtil.php 100% <100%> (ø) 1 <1> (?)
src/MenuStyle.php 96.35% <97.22%> (-0.45%) 76 <6> (+12)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1316f37...587fd8b. Read the comment docs.

AydinHassan commented 4 years ago

@jtreminio could you make some tests with PR see if it fixes your problems?

jtreminio commented 4 years ago

This is almost perfect, but the margin is being applied only to left-side:

I've highlighted the scrollbar area on my terminal:

image

This is with your patch of

    protected function calculateContentWidth() : void
    {
        $this->contentWidth = $this->width
            - ($this->paddingLeftRight * 2)
            - ($this->borderRightWidth + $this->borderLeftWidth)
            - ($this->margin);

        if ($this->contentWidth < 0) {
            $this->contentWidth = 0;
        }
    }

image

AydinHassan commented 4 years ago

That was the wrong fix actually, it's all related to shrinking the menu width when the terminal is too narrow. Regarding the right margin, yeah we actually don't ever print that because it's obviously empty space, so it never got handled when the terminal is too narrow. Will implement that in another PR.