idea: markdown, liquid and lua code editor with syntax highlighting in the TUI #32
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
the TUI needs a proper support for syntax highlighting. there are libraries compatible with Ratatui, which is the base for ExRatatui, so maybe a subproject that builds an extended Ratatui NIF with a custom widget for ExRatatui could be a way to go. This code editor also needs to support auto-word-wrapping for long lines.
Maybe this suggestion from another AI can help to achieve it without building my own ratatui library?
To display source code with syntax highlighting inside an ExRatatui panel, you must use the built-in CodeBlock widget.ExRatatui provides the CodeBlock component out of the box, which leverages the syntect engine under the hood to handle syntax highlighting across seven curated themes and optional line numbers.Standard ImplementationHere is how you can render a syntax-highlighted code editor panel using Elixir and ExRatatui:elixir
Key Configurations for CodeBlockLanguages Supported: Pass the language identifier as an atom (e.g., :elixir, :rust, :javascript, :python).Curated Themes: Swap look-and-feel easily using built-in themes like :dracula, :gruvbox, :nord, or :one_dark.Custom Layouts: You can expose the raw tokenized tokens using ExRatatui.CodeBlock.highlight/3 if you need to build custom diff viewers or code inspectors.Handling User InputIf your panel needs to be actively editable (instead of a read-only viewer), you will need to manage a text buffer state inside your handle_event/2 loop using a TextInput state variable. You pass the raw string from that state into the CodeBlock widget during the render/2 frame cycle so that every keystroke re-tokenizes and updates live.Would you like help setting up the interactive input state for this editor panel, or do you need a specific code theme configuration?