Skip to content

Let custom pagers detect lazygit #3419

@bash

Description

@bash

Hi folks 👋🏼

Background

I have recently implemented automatic color detection in delta as part of dandavison/delta#1615.
This involves sending an escape sequence (OSC 10 / OSC 11) to the terminal and waiting for a response.
Delta uses the terminal-colorsaurus library for this.

There are a couple of mechanisms in place to detect terminals that don't support this escape sequence to prevent waiting forever. Quoting myself from dandavison/delta#1664 (comment):

  • The DA1 trick 1 which works for most terminals emulators
  • If the environment variable TERM is dumb, do nothing (This originates from NCURSES)
  • Finally a 1 second timeout. This is intentionally quite high as to not bail out too early for high-latency situations such as when connected via SSH.

From what I can tell lazygit runs git (and delta) inside a PTY. This PTY however does not respond to queries (such as OSC 10 or DA1). It also does not identify itself via an environment variable such as TERM or similar means.

For delta this currently means that we hit the timeout which we are trying to prevent as it is the last resort mechanism.

Feature Request

Would you be open to changing lazygit's PTY to identify itself somehow?

My preferred mechanism would be setting the environment variable TERM=dumb 2 since terminal-colorsaurus (the library that delta uses) already detects this and other libraries / applications do too.

From some preliminary testing git still starts the pager when TERM=dumb which seems to be the primary reason for using a PTY in the first place.

Footnotes

  1. Colorsaurus sends two escape sequences: OSC 11 (the actual color querying sequence) followed by DA1 (which is supported by almost all terminals out there). Since terminals answer in the same order as the sequences were received we know that if we receive the answer to DA1 then the terminal does not support OSC 11 and can bail out early and avoid a long timeout.

  2. It might make sense in that case to also clear out TERM_PROGRAM and TERM_PROGRAM_VERSION if they exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions