Skip to content

Commit

Permalink
Python, CLI example
Browse files Browse the repository at this point in the history
  • Loading branch information
p4ymak committed Jan 19, 2024
1 parent c78189b commit eff369e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ CodeEditor::default()

## Usage as lexer

*Cargo.toml*
**Cargo.toml**

```toml
[dependencies]
egui_code_editor = { version = "0.2" , default-features = false }
colorful = "0.2.2"
```

**main.rs**

```rust
use colorful::{Color, Colorful};
use egui_code_editor::{Syntax, Token, TokenType};
Expand Down
54 changes: 53 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(rustdoc::invalid_rust_codeblocks)]
//! Text Editor Widget for [egui](https://github.com/emilk/egui) with numbered lines and simple syntax highlighting based on keywords sets.
//!
//! ## Usage
//! ## Usage with egui
//!
//! ```rust
//! use egui_code_editor::{CodeEditor, ColorTheme, Syntax};
Expand All @@ -15,6 +15,58 @@
//! .with_numlines(true)
//! .show(ui, &mut self.code);
//! ```
//!
//! ## Usage as lexer
//!
//! **Cargo.toml**
//!
//! ```toml
//! [dependencies]
//! egui_code_editor = { version = "0.2" , default-features = false }
//! colorful = "0.2.2"
//! ```
//!
//! **main.rs**
//!
//! ```rust
//! 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())));
//! }
//! }
//! ```
pub mod highlighting;
mod syntax;
Expand Down

0 comments on commit eff369e

Please sign in to comment.