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

Terminal Height and Width Exception #34

Closed
utsavsomaiya opened this issue Aug 3, 2023 · 11 comments
Closed

Terminal Height and Width Exception #34

utsavsomaiya opened this issue Aug 3, 2023 · 11 comments
Assignees

Comments

@utsavsomaiya
Copy link

Laravel Prompts Version

0.1.3

Laravel Version

10.17.0

PHP Version

8.2

Operating System & Version

Linux

Terminal Application

Vs code terminal

Description

image


May be at this moment can we use old prompts which used in laravel 10.16!!?

Steps To Reproduce

#3

@jessarcher
Copy link
Member

Hi @utsavsomaiya,

Is Prompts incorrectly calculating your terminal height? From your screenshot, it looks like you have far more than the minimum 8 lines.

If you'd like to fall back to the old prompts, you can add the following to routes/console.php, providing whatever conditional you like:

\Laravel\Prompts\Prompt::fallbackWhen(true);

If your system has tput available, you could try something like this (untested):

\Laravel\Prompts\Prompt::fallbackWhen(shell_exec('tput lines') < 8);

@utsavsomaiya
Copy link
Author

utsavsomaiya commented Aug 4, 2023

Thank you, @jessarcher.

I just checked your suggestion, but my concern is not exactly what you suggested. My concern is when the terminal's scrollback lines are set to 6, can we still show the old prompts?

This becomes an issue because sometimes I unknowingly start the database seeding in my VS Code terminal and then close it to continue with my work. Later, when I check again, it throws an exception because the terminal closed, and I missed the error.

Is there a way to address this?

@utsavsomaiya
Copy link
Author

And my screenshot is captured by bigger height. So don't worry. It's works fine in my machine.

@crynobone
Copy link
Member

I wonder if we can check for requirement when configuring Prompt to Laravel Command and fallback automatically instead of seeing an exception.

@jessarcher
Copy link
Member

Thank you, @jessarcher.

I just checked your suggestion, but my concern is not exactly what you suggested. My concern is when the terminal's scrollback lines are set to 6, can we still show the old prompts?

I'm unaware of a way to determine the number of scrollback lines from within the shell or PHP. The default in VS Code is 1000, so I'm curious to know why you've reduced it so drastically?

When I set the scrollback lines to 6, the prompts work fine for me in VS Code terminal. It's just the number of visible lines that impact it (i.e. the height), which can be determined in a few ways:

tput lines

stty size

echo $LINES # This won't work inside PHP because it's a shell variable not an environment variable

image

This becomes an issue because sometimes I unknowingly start the database seeding in my VS Code terminal and then close it to continue with my work. Later, when I check again, it throws an exception because the terminal closed, and I missed the error.

Is there a way to address this?

I'm not sure what you mean. How do you unknowingly start database seeding? And how are Prompts involved?

I have tried adding a prompt to DatabaseSeeder.php and running sleep 5 && php artisan db:seed before closing the terminal. When I open the terminal after 5 seconds, the prompt has displayed fine, as long as the terminal was at least 8 lines tall before it was closed.

image

I can look at making Laravel automatically fall back to Symfony when the terminal is less than 8 lines, but I'd like to understand a bit more about your issue first.

@utsavsomaiya
Copy link
Author

image

As I closed my vs code terminal height will be set to the 6 right?

Then at that time my databaseseeder is running but outro function is remaining to called. See the height will 6 and give me exceptions. But my old one is 8.

So I need no exception but the give me old laravel prompts. And I also put the fallback in console but may be it is not running.

image

@utsavsomaiya
Copy link
Author

utsavsomaiya commented Aug 10, 2023

Can I change the color of the font? @jessarcher

image

@jessarcher
Copy link
Member

As I closed my vs code terminal height will be set to the 6 right?

In my tests the terminal height reported to Prompts is whatever height the terminal was before it was closed.

Then at that time my databaseseeder is running but outro function is remaining to called. See the height will 6 and give me exceptions. But my old one is 8.

Could you perhaps create a minimal reproduction repo and steps? It sounds like you've customised your database seeder a fair bit. When I test locally with a fresh Laravel installation in a fresh VS Code installation, I can't replicate the issue unless I resize the terminal height to be less than 8 lines.

So I need no exception but the give me old laravel prompts. And I also put the fallback in console but may be it is not running.

image

This should be true, not false:

Prompt::fallbackWhen(true);

@utsavsomaiya
Copy link
Author

Yeah.. it works. Thanks jess. 😊
But sometimes I just close the terminal background process is give me failure but after set it true then its works fine.

Thanks.. It's out of my knowledge.

@Abdalmalekshd
Copy link

can you tell what is the solution please,because the images won't upload

@utsavsomaiya
Copy link
Author

#34 (comment)

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

No branches or pull requests

4 participants