8000 Choose to clear background for TTY by MitchNine · Pull Request #1050 · alecthomas/chroma · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Choose to clear background for TTY #1050

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

Closed

Conversation

MitchNine
Copy link
@MitchNine MitchNine commented Feb 19, 2025

I want to be able to have a background colour for the output in tty. This would help in getting a nicer looking code snippet in projects like https://charm.sh/.

The functionality of clearing the background is still present. But now it is done explicitly though the style.ClearBackgound() function. An example of this would look like the following:

func main() {
	in := `int main(int argc, char** argv) { return 0; }`

	lexer := lexers.Get("C")
	if lexer == nil {
		lexer = lexers.Fallback
	}
	style := styles.Get("monokai")
	if style == nil {
		style = styles.Fallback
	}
	formatter := formatters.Get("terminal256BG") // Formats with the BG suffix in the name have background colours enabled
	if formatter == nil {
		formatter = formatters.Fallback
	}

	iterator, _ := lexer.Tokenise(nil, string(in))
	formatter.Format(os.Stdout, style, iterator)
}

I want to be able to have a background colour for the output in tty.
This would help in getting a nicer looking code snippet in projects
like https://charm.sh/.

The functionality of clearing the background is still present. But
now it is done explicitly though the style.ClearBackgound() function.
@alecthomas
Copy link
Owner

I don't mind the ability to configure this behaviour, but this is a backwards incompatible behavioural change. It'll have to be opt-out, not opt-in.

@MitchNine
Copy link
Author

I don't mind the ability to configure this behaviour, but this is a backwards incompatible behavioural change. It'll have to be opt-out, not opt-in.

Fair enough, I'll see what I can do

Using different formats with the BG suffix to specify if we will
enable the background color for tty outputs.
@MitchNine
Copy link
Author
MitchNine commented Feb 27, 2025

@alecthomas I've changed the default behavior back to no background colour for tty by default. Couldn't figure out a neat way to specify if we should enable the background colour so instead I've just created formats with the BG suffix that have background colours enabled.

Copy link
Owner
@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

I don't really love the proliferation of formatters TBH, but I also don't have any better ideas, so LGTM

@alecthomas alecthomas closed this May 12, 2025
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.

2 participants
0