Crates.io | egui_code_editor |
lib.rs | egui_code_editor |
version | |
source | src |
created_at | 2023-07-17 12:35:58.472444 |
updated_at | 2025-02-10 13:43:37.508441 |
description | egui Code Editor widget with numbered lines and syntax highlighting.. |
homepage | |
repository | https://github.com/p4ymak/egui_code_editor |
max_upload_size | |
id | 918462 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Text Editor Widget for egui with numbered lines and simple syntax highlighting based on keywords sets.
use egui_code_editor::{CodeEditor, ColorTheme, Syntax};
CodeEditor::default()
.id_source("code editor")
.with_rows(12)
.with_fontsize(14.0)
.with_theme(ColorTheme::GRUVBOX)
.with_syntax(Syntax::rust())
.with_numlines(true)
.show(ui, &mut self.code);
Cargo.toml
[dependencies]
egui_code_editor = { version = "0.2" , default-features = false }
colorful = "0.2.2"
main.rs
use colorful::{Color, Colorful};
use egui_code_editor::{Syntax, Token, TokenType};
fn color(token: TokenType) -> Color {
match token {
TokenType::Comment(_) => Color::Grey37,
TokenType::Function => Color::Yellow3b,
TokenType::Keyword => Color::IndianRed1c,
TokenType::Literal => Color::NavajoWhite1,
TokenType::Numeric(_) => Color::MediumPurple,
TokenType::Punctuation(_) => Color::Orange3,
TokenType::Special => Color::Cyan,
TokenType::Str(_) => Color::Green,
TokenType::Type => Color::GreenYellow,
TokenType::Whitespace(_) => Color::White,
TokenType::Unknown => Color::Pink1,
}
}
fn main() {
let text = r#"// Code Editor
CodeEditor::default()
.id_source("code editor")
.with_rows(12)
.with_fontsize(14.0)
.with_theme(self.theme)
.with_syntax(self.syntax.to_owned())
.with_numlines(true)
.vscroll(true)
.show(ui, &mut self.code);
"#;
let syntax = Syntax::rust();
for token in Token::default().tokens(&syntax, text) {
print!("{}", token.buffer().color(color(token.ty())));
}
}
Based on themes in Helix Editor.
Font used in examples is Comic Code by Toshi Omagari.