这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@krobelus
Copy link
Contributor

@krobelus krobelus commented Mar 1, 2025

  • To-do: this is untested, would appreciate your help on that (I don't have Android Studio or a device set up).

Standard ECMA-48: Control Functions for Coded Character Sets specifies
the format of CSI commands. Wikipedia has a concise description:
https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Sequence_Introducer_commands

Do this for at least for sequences like "CSI = 5 u" that
contain non-numeric parameter bytes.

This fixes a problem with fish shell 4.0.0 which (for better or worse)
uses that sequence.

This patch introduces a slight inconsistency: for the above example,
"unknownSequence('u')" will be called. The resulting log message may
be confusing, because we do support "CSI u". We should fix this to
log the entire unknown sequence. I can try doing that.

In future we should also fully consume all other unknown CSI commands.
A contrived example would be "CSI ! ! a". If desired, I'm happy to
fix those as well, as I have some context already (but I don't think
that would block this patch).

Closes #4338

@robertkirkman
Copy link
Member

I have compiled and tested this PR

I can confirm that this passes the test case given in the issue,
the command printf '\x1b[=5u' no longer prints anything, whereas without this PR it prints 5u.

Tested device: Samsung Galaxy S III SPH-L710, Android 7.1.2

…ameter and intermediate bytes

Standard ECMA-48: Control Functions for Coded Character Sets specifies the format of CSI commands.
- https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Sequence_Introducer_commands
- https://invisible-island.net/xterm/ecma-48-parameter-format.html#section5.4

Previously unsupported bytes would be echoed to the terminal.

```shell
$ printf '\x1b[=u' # PF
u
$ printf '\x1b[=5u' # PPF
5u
$ printf '\x1b[=5!u' # PPIF
5!u
$ printf '\x1b[=5!%u' # PPIIF
5!0
$ printf '\x1b[=?5!%u' # PPPIIF
?5!0
```

This fixes a problem with fish shell 4.0.0 which uses that sequence.

Closes termux#4338

Co-authored-by: @krobelus <aclopte@gmail.com>
Co-authored-by: @agnostic-apollo  <agnosticapollo@gmail.com>
@agnostic-apollo agnostic-apollo force-pushed the partial-CSI-command-parser-fix branch from 9161c07 to 7c0821a Compare March 14, 2025 07:03
@agnostic-apollo
Copy link
Member

Test this and let me know, I will merge within next 24 hr.

@krobelus
Copy link
Contributor Author

I'm not sure if it's easy for me to test but FWIW the changes look good.
There are some (contrived) cases missing like CSI ! ! a; fixing them would require a slightly larger change.

@agnostic-apollo
Copy link
Member

You can grab a build from https://github.com/termux/termux-app/actions/runs/13851563135?pr=4417 if you are using github releases instead of F-Droid.

There is no need to handle invalid sequences as there would be tonne/or infinite possibilities, the above was handled because it was valid, but unsupported by our terminal currently. The ! is already captured by ESC_CSI_EXCLAMATION, but only CSI ! p is valid for a DECSTR reset, other parameters would result in error being logged if logging is enabled.

@krobelus
Copy link
Contributor Author

krobelus commented Mar 14, 2025 via email

@krobelus
Copy link
Contributor Author

krobelus commented Mar 14, 2025 via email

@agnostic-apollo
Copy link
Member

CSI ! ! a is a syntactically valid CSI command, we should consume the whole thing.

Under what spec is it valid and what operation is supposed to be performed?

I don't have Android Studio or Android set up.

Github action already builds the APKs for you, download the attached zip, extract the apk and install.

https://github.com/termux/termux-app#github

@robertkirkman
Copy link
Member

I have tested the newer version. For me it is still working the same (printf '\x1b[=5u' is not printing anything)

@krobelus
Copy link
Contributor Author

krobelus commented Mar 14, 2025 via email

@agnostic-apollo
Copy link
Member

I have tested the newer version. For me it is still working the same (printf '\x1b[=5u' is not printing anything)

I already tested that part, checking fish shell, or at least no apparent issue with text editors is what would need testing.

@robertkirkman
Copy link
Member

robertkirkman commented Mar 14, 2025

oh ok, now I have tested fish with termux/termux-packages#23686 reverted, vim, and vim inside fish with termux/termux-packages#23686 reverted, and nothing seems to be wrong.
I have previously seen the basic symptoms of fish with termux/termux-packages#23686 reverted inside the current official Termux APK releases, so I can tell that the basic symptoms are no longer a problem, but I am not a heavy user of fish or highly experienced with it, so if fish relies on subtler behaviors for some operations that aren't easy to encounter during normal use, I might not have been able to check those.

@agnostic-apollo
Copy link
Member

The only supported byte after a ! is a p as per spec. A double !! is not a valid command. Additionally, even ! is not part of original ECMA-48 standard, as it only allows bit combinations from 03/00 to 03/15, which are 0–9:;<=>?. Private modes would require starting the sequence with one of the officially supported bit combinations, or publishing a spec.

CSI ! p Soft terminal reset (DECSTR), VT220 and up.

@agnostic-apollo
Copy link
Member

Thanks for testing @robertkirkman. That should probably be enough.

@krobelus
Copy link
Contributor Author

krobelus commented Mar 14, 2025

I agree that it's enough testing for this fish version. Every new CSI related command is sent at fish startup so errors should be noticeable.

Thanks everyone for your work. We've had a bunch of reports about this since late December (from the fish beta release); I'll try to act faster next time.


Now on to getting nerd-sniped:

I'm not thinking of any commands that are in use today.
I agree that the ! byte is never a parameter byte but it's an intermediate byte (of which there may be multiple according to
ECMA-48).

I'm also not talking about private mode. Only about commands that
are possibly allowed by ECMA-48, either by future versions of a
standard or (more likely) by other protocols. Since I don't know how
to read "are available for private or experimental use" in section 5.4 d)
of ECMA-48, I do not know if the standard allows the latter outside
private mode.

To me it looks like a complete CSI parser should parse any (unknown) "private or experimental use" commands.
I read most of section 5.4 but I may easily be wrong in my interpretation.

@agnostic-apollo
Copy link
Member

I agree that the ! byte is never a parameter byte but it's an intermediate byte.

But an intermediate byte must always be proceeded by a valid parameter byte, which ! is not, at least as per ECMA-48. The VT200 series did have CSI ! p, but no other command exists for any standard or spec that I have seen where ! is a parameter byte. If there is one, let me know, and we can support it.

To me it looks like a complete CSI parser should parse any (unknown) "private or experimental use" commands.

This pull already started parsing all private and experimental ranges and ignoring them. Any other character outside the supported ranges should not be used and should be an error, until someone publishes a standard. There is enough range left for private/experimental use left by the standard for someone to have to go outside it.

The unallocated bit combinations are reserved for future standardization and shall not be used.

If the first bit combination of the parameter string is in the range 03/12 to 03/15, the parameter string
is available for private (or experimental) use. Its format and meaning are not defined by this
Standard.

The number of Intermediate Bytes is not limited by this Standard; in practice, one Intermediate Byte will be
sufficient since with sixteen different bit combinations available for the Intermediate Byte over one
thousand control functions may be identified.

Bit combinations 07/00 to 07/14 are available as Final Bytes of control sequences for private (or
experimental) use.

Check the code table in following link and compare the <column>/<row> combinations to get the ranges.

Additionally, the 5.1.2 section of 3rd and 4.1.2 section of 2nd editors of the standard had an explicit error condition statement for using unsupported combinations, which seems to have gotten removed in later editions for some reason.

The occurrence of any bit combinations which do not conform to the above format is an error condition for which recovery is not specified by this Standard.

@agnostic-apollo
Copy link
Member

You are welcome and thanks again for the pull.

@agnostic-apollo agnostic-apollo merged commit a988383 into termux:master Mar 15, 2025
4 checks passed
robertkirkman added a commit to termux/termux-packages that referenced this pull request Oct 14, 2025
- Fixes #26707

- Revert fish-shell/fish-shell@70bd49f as planned and previously noted in #26466

- After fish-shell/fish-shell@eb4cec1, `fix-import-when-posix-spawn-disabled.patch` is necessary to prevent compilation error `failed to resolve: use of undeclared type 'Pid'`

- After fish-shell/fish-shell@91ee45b, `revert-6644cc9.patch` is no longer necessary to prevent a compilation failure, and can be removed.

- termux/termux-app#4417 has been in [Termux 0.118.3](https://github.com/termux/termux-app/releases/tag/v0.118.3) for 4 months, meaning that `status test-feature keyboard-protocols && set -U fish_features no-keyboard-protocols` can be removed.
termux-pacman-bot added a commit to termux-pacman/termux-packages that referenced this pull request Oct 14, 2025
- Fixes termux/termux-packages#26707

- Revert fish-shell/fish-shell@70bd49f as planned and previously noted in termux/termux-packages#26466

- After fish-shell/fish-shell@eb4cec1, `fix-import-when-posix-spawn-disabled.patch` is necessary to prevent compilation error `failed to resolve: use of undeclared type 'Pid'`

- After fish-shell/fish-shell@91ee45b, `revert-6644cc9.patch` is no longer necessary to prevent a compilation failure, and can be removed.

- termux/termux-app#4417 has been in [Termux 0.118.3](https://github.com/termux/termux-app/releases/tag/v0.118.3) for 4 months, meaning that `status test-feature keyboard-protocols && set -U fish_features no-keyboard-protocols` can be removed.
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.

[Bug]: may fail to ignore escape sequences for kitty progressive enhancements

4 participants