Skip to content

Defer CharacterReader initialization until command execution#1092

Merged
dantleech merged 2 commits intophpbench:masterfrom
jbboehr:hotfix/prevent-garbage-readline-output
Apr 10, 2024
Merged

Defer CharacterReader initialization until command execution#1092
dantleech merged 2 commits intophpbench:masterfrom
jbboehr:hotfix/prevent-garbage-readline-output

Conversation

@jbboehr
Copy link
Copy Markdown
Contributor

@jbboehr jbboehr commented Apr 9, 2024

The call to readline_callback_handler_install in CharacterReader is causing some junk output (see below) in all commands that was breaking the CSV output. Clearing out TERM and COLORTERM also prevents the issue.

This commit defers the installation of the readline callback handler until log is actually run.

$ COLORTERM="truecolor" TERM="xterm-256color" php -r "readline_callback_handler_install('', function (): void {});" | xxd
00000000: 1b5b 3f32 3030 3468 1b5b 3f32 3030 346c  .[?2004h.[?2004l
00000010: 0d                                       .

$ COLORTERM= TERM= php -r "readline_callback_handler_install('', function (): void {});" | xxd

$ COLORTERM="truecolor" TERM="xterm-256color" php -r "" | xxd

Fixes #1090

@jbboehr
Copy link
Copy Markdown
Contributor Author

jbboehr commented Apr 9, 2024

There's a few other ways this could be done e.g. CharacterReaderFactory,initialize in read.

Comment thread lib/Console/CharacterReader.php Outdated
* press <return> in order to paginate.
*/
public function __construct()
public function initialize(): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's make this priate an lazily initialize it when we call read ? this avoids "temporal coupling" and in anycase, it's not a hotpath.

jbboehr added 2 commits April 9, 2024 07:23
> In FixerFactory.php line 164:  [phpdoc_align] Configuration must be an array and may not be empty.
The call to `readline_callback_handler_install` in `CharacterReader` is
causing some junk output (see below) *in all commands* that was
breaking the CSV output. Clearing out `TERM` and `COLORTERM` also
prevents the issue.

This commit defers the installation of the readline callback handler
until log is actually run.

```console
$ COLORTERM="truecolor" TERM="xterm-256color" php -r "readline_callback_handler_install('', function (): void {});" | xxd
00000000: 1b5b 3f32 3030 3468 1b5b 3f32 3030 346c  .[?2004h.[?2004l
00000010: 0d                                       .

$ COLORTERM= TERM= php -r "readline_callback_handler_install('', function (): void {});" | xxd

$ COLORTERM="truecolor" TERM="xterm-256color" php -r "" | xxd
```

Fixes phpbench#1090
@jbboehr jbboehr force-pushed the hotfix/prevent-garbage-readline-output branch from 659d0e0 to 2eb8d6b Compare April 9, 2024 14:27
@dantleech dantleech merged commit bc4461a into phpbench:master Apr 10, 2024
@dantleech
Copy link
Copy Markdown
Member

thanks!

@jbboehr jbboehr deleted the hotfix/prevent-garbage-readline-output branch April 11, 2024 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Garbage output from readline_callback_handler_install (CharacterReader)

2 participants