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

Visual glitches in the Termux app for Android when running v2021.08.28, even on a linux server #4339

Closed
finagolfin opened this issue Sep 10, 2021 · 8 comments
Labels

Comments

@finagolfin
Copy link

Steps

Open Kakoune with most any file in the Termux app, even when running Kakoune in Fedora linux remotely and accessing it through ssh.

Outcome

Random lines are highlighted in white, which comes and goes when the screen updates because of a keyboard press or any other touch update.

Expected

No random highlighting in white, see example below of running Fedora's kakoune system package in ssh from my Android 6 tablet.

Screenshot_2021-09-10-14-17-19

I'm able to reproduce on another device running Android 11, both running the Termux package locally or the Fedora package remotely through ssh.

@finagolfin finagolfin added the bug label Sep 10, 2021
@lenormf
Copy link
Contributor

lenormf commented Sep 10, 2021

What version of Kakoune is this? Have you tried other SSH clients like JuiceSSH?

@Screwtapello
Copy link
Contributor

I installed Kakoune v2012.08.28 from Termux 0.117, launched kak -n .bashrc and scrolled around, and did not see any white flashes like those depicted. I also tried SSHing to a Debian box and ran Kakoune inside tmux, and I didn't see any white flashes that way either.

@Screwtapello
Copy link
Contributor

OK, I don't get white glitches with kak -n or with my normal colour scheme, but I do get them with :colorscheme default. Also, when an infobox appears, often there are stripes of yellow to the left-hand edge of the screen. Perhaps the Termux terminal emulator doesn't treat background-color-erase the way Kakoune expects?

@finagolfin
Copy link
Author

What version of Kakoune is this?

It's noted in the issue title, no problem with the previous release.

Have you tried other SSH clients like JuiceSSH?

No, I only use Termux.

I'm not familiar with how the Termux app supports terminal sequences, maybe @agnostic-apollo can fill you in.

@agnostic-apollo
Copy link

I haven't really looked into the deep terminal level workings, but those commands are handled by TerminalEmulator and seems like resetting of background color is done here.

It would probably require checking which commands are being sent during updates and how termux is handling them to figure out the causes for various problems above.

@Screwtapello
Copy link
Contributor

I ran script kak -n to produce a typescript file containing all the sequences output by Kakoune. I then edited the file, removing chunks and catting it in both GNOME Terminal and Termux to isolate a difference, and I found one pretty quickly.

Terminal formatting sequences start with ESC [ and finish with m, and in between is a semicolon-separated list of codes to be applied. For example, ESC [1m produces bold text, ESC [32m produces green text, ESC [1;32m produces bold green text, and so forth. The special code 0 means "reset everything to defaults", so while ESC [1m adds bold to whatever formatting was currently in effect, ESC [0;1m always produces a bold version of the default text style.

An additional quirk: if a terminal sequence doesn't have a number, there's usually a sensible default. For example, ESC [5B moves the cursor down five lines, but ESC [B moves the cursor down one line. The default for the set-formatting code is 0, so ESC [m resets all formatting.

So far, Termux and GNOME Terminal are in agreement. Here's the difference:

printf '\e[4munderline\e[;3mitalic\n'

On GNOME Terminal, this produces the word "underline" underlined, followed by the word "italic" in italic.

On Termux, this produces "underline" underlined, followed by "italic" in italic and underlined.

That is, GNOME Terminal parses ESC [;3m as ESC [0;3m (expanding an empty field to the default value), while Termux parses it as ESC [3m (since a parameter exists, it doesn't apply the default). Kakoune uses ESC [;...m sequences all the time, so it's not surprising to me that things get confused on Termux. Termux should probably fix its formatting sequence parsing to match other terminals, but I think this is also a bug in Kakoune:

kakoune/src/terminal_ui.cc

Lines 241 to 277 in b3a1017

writer.write("\033[");
bool join = false;
if (face.attributes != m_active_face.attributes)
{
for (int i = 0; i < std::size(attr_table); ++i)
{
if (face.attributes & (Attribute)(1 << i))
format_with(writer, ";{}", attr_table[i]);
}
m_active_face = Face{{}, {}, face.attributes};
join = true;
}
if (m_active_face.fg != face.fg)
{
set_color(true, face.fg, join);
join = true;
}
if (m_active_face.bg != face.bg)
{
set_color(false, face.bg, join);
join = true;
}
if (m_active_face.underline != face.underline)
{
if (join)
writer.write(";");
if (face.underline != Color::Default)
{
if (face.underline.isRGB())
format_with(writer, "58:2::{}:{}:{}", face.underline.r, face.underline.g, face.underline.b);
else
format_with(writer, "58:5:{}", ul_table[(int)(char)face.underline.color]);
}
else
format_with(writer, "59");
}
writer.write("m");

When producing a formatting escape sequence, Kakoune uses a join flag so it can avoid starting an escape sequence with a semicolon, and seems to have logic to layer formatting styles together instead of deliberately resetting them from scratch every time. However, when setting a new formatting attribute, it always writes a leading semicolon regardless of the state of the join flag. On the other hand, I can't seem to trigger the bug I think should be there, and trying to fix it makes all the formatting go crazy. I'm not sure what's going on here.

@agnostic-apollo
Copy link

@Screwtapello thanks for finding the issue. I have fixed it on the termux side with termux/termux-app@4c47f4f7. It was not following the terminal spec. This issue can be closed now since issue was with termux and not with kakoune.

@finagolfin
Copy link
Author

Closing since this was most likely fixed on our end in Termux.

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

No branches or pull requests

4 participants