-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add Cursor class to control the cursor in the terminal #27444
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
Conversation
For reference purposes, I've look for the APIs for this feature in other projects:
https://godoc.org/github.com/nsf/termbox-go func HideCursor()
func SetCursor(x, y int) https://godoc.org/github.com/gdamore/tcell func HideCursor()
func ShowCursor(x int, y int) .Net (https://msdn.microsoft.com/en-us/library/system.console_methods(v=vs.110).aspx) SetCursorPosition(Int32, Int32) And some properties: CursorLeft
CursorTop
CursorVisible
...
https://github.com/cronvel/terminal-kit/blob/master/doc/low-level.md#ref.movingCursor .saveCursor()
.restoreCursor()
.up(int n)
.down(int n)
.right(int n)
.left(int n)
.nextLine(int n)
.previousLine(int n)
.column(int x)
.scrollUp(int n)
.scrollDown(int n)
.scrollingRegion(top, bottom)
.resetScrollingRegion()
.moveTo(int x, int y)
.move(int x, int y)
.hideCursor()
.tabSet()
.tabClear()
.tabClearAll()
.forwardTab(int n)
.backwardTab(int n) So we need to think if we want a simple (but enough) API or a complex (but useful) API. |
Also see the HOA Project Console |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this feature! I left two minor comments.
@pierredup see test failures :) Also, any comment when comparing the proposed API with the linked ones? Do any of them provide any idea to borrow? |
7501b0f
to
2ad0290
Compare
I prefer having a few explicit methods (E.G |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update QuestionHelper
to make it use this for autocompletion?
I'm fine with the current naming.
2ad0290
to
6ff2395
Compare
@chalasr Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a CHANGELOG entry and rebase to see tests green?
public function clearScreen() | ||
{ | ||
$this->output->write("\x1b[2J", false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really belong to the cursor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Can we also have methods to get the max x and max y of the console/cursor? I think we already have the code in Symfony, that would be good to have it here as well.
Maybe we can simplify the progress bar code as well.
2015276
to
b7b8b4f
Compare
I've rebased from master, and updated the Progress bar to use the Cursor class as well.
This is currently available in the Terminal class for this component, so I'm not sure if it should be in the Cursor class as well |
Agree about keeping the terminal size logic in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :) Missing CHANGELOG entry
Thanks @pierredup for working on this feature, this is much appreciated. |
This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [Console] cursor tweaks | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Refs #27444 | License | MIT | Doc PR | n/a While playing with the new cursor class, I realized that I would like to make some changes. Mainly having a fluent interface: `$cursor->moveUp(10)->clearOutput()` for instance. I have also separater the `clearLine()` method in two method to avoid the bool arg. /cc @pierredup Commits ------- 5a7b314 Make the Cursor class final b0e7eb6 Make Cursor fluent 55fef91 Split a method d00b5b5 Remove default value
This PR was submitted for the 5.4 branch but it was squashed and merged into the 5.2 branch instead. Discussion ---------- [Console] Document console cursor fixes #13529 feature symfony/symfony#27444 ping `@wouterj` I've seen your slack recently and wanted to give it a try as I will use the feature very soon :) feel free to comment, specialy if I need to document all the cursor features or not text and image taken from the feature PR description inspired by https://symfony.com/doc/current/components/console/helpers/progressbar.html Commits ------- 232c519 [Console] Document console cursor
Add a new
Cursor
class to the Console component, that allows to manipulate the cursor in the terminal.Options to move the cursor include: moveUp, moveDown, moveLeft, moveRight, show, hide, save and restore position, get current position etc.
Example usage:
Result: