A standalone code editor with syntax highlighting and themes.

Overview

MIT License version Twitter

CodeEditor

A standalone code (and text) editor for people like me who write their own user interfaces utilizing crates like pixels.

CodeEditor renders its display into a Vec<u8> and is completely independent from any UI crate. It utilizes fontdue for rendering fonts.

Example App

A standalone pixels and winit based example app is included in this repo.

Screenshot

Usage

Add code_editor to your Cargo.toml

code_editor = "0.2.2"

And than in your app

use code_editor::prelude::*;

let mut code_editor = CodeEditor::new();
code_editor.set_font("fonts/Source_Code_Pro/static/SourceCodePro-Regular.ttf");
code_editor.set_mode(CodeEditorMode::Rhai);
code_editor.set_font_size(17.0);

code_editor.set_text("Your source code".to_string());

In your draw loop you can than draw the editor

code_editor.draw(frame, (0, 0, width, height), width);

The second parameter is the drawing rectangle into your frame, the last parameter is the stride in pixels.

You can get the edited text via get_text(). You will also need to connect mouse and keyboard events to the code editor, see the example app.

Syntax Highlighting

The syntax highlighting is right now not configurable but is pretty universal. Supported modes are right now Rhai and Text (which has no highlighting). I will try to make the syntax highlighting more configurable in the future, in the meantime you can tweak the source code to your needs.

Themes

The default theme has this implementation:

impl Theme {
    pub fn new() -> Self {
        Self {
            background      : [34, 34, 36, 255],
            line_numbers    : [160, 160, 160, 255],
            line_numbers_bg : [30, 30, 32, 255],

            text            : [255, 255, 255, 255],
            cursor          : [170, 170, 170, 255],

            identifier      : [120, 214, 255, 255],
            number          : [159, 197, 146, 255],
            keywords        : [45, 133, 200, 255],
            brackets        : [226, 73, 146, 212],
            comments        : [69, 128, 56, 212],
            string          : [197, 117, 92, 212],

            error           : [237, 55, 54, 255],
        }
    }
}

You can tweak it in the theme property of the CodeEditor struct or you can set a new theme via the set_theme(theme); function.

Disclaimer

CodeEditor is actively maintained and I will improve it over time as I use it for my own applications.

You might also like...
Standalone analytics provider and realtime dashboard designed for self-hosting.
Standalone analytics provider and realtime dashboard designed for self-hosting.

Stats Stats is a high-performance, standalone analytics provider designed for self-hosting, enabling the collection and viewing of event data from web

Ox is a code editor that runs in your terminal
Ox is a code editor that runs in your terminal

Ox editor Ox is a code editor that runs in your terminal. About The Project Ox is a code editor. It was written in Rust using ANSI escape sequences. I

Simple code editor made with Freya πŸ¦€
Simple code editor made with Freya πŸ¦€

Simple code editor made with Freya πŸ¦€ This is a work in progress simple code editor that showcases how to use tree-sitter and freya together. WARNIN

A standalone Command Line Interface debugging tool for The Witcher 3 written in Rust
A standalone Command Line Interface debugging tool for The Witcher 3 written in Rust

A standalone Command Line Interface debugging tool for The Witcher 3 written in Rust. This tool is intended for Witcher 3 modders who make mainly scri

πŸ“¦ Distribute Roblox games as standalone executables -- No existing client necessary. 🚧
πŸ“¦ Distribute Roblox games as standalone executables -- No existing client necessary. 🚧

πŸ“¦ Packer Distribute Roblox games as standalone executables. 🚧 Packer is still being worked on. Among many other things, Windows is not currently sup

A standalone Luau script runner πŸŒ™

Lune πŸŒ™ A standalone Luau script runner πŸš€ Use the ergonomics and readability of Luau for your shell scripts πŸš€ βš™οΈ Installation The preferred way of i

Valq - macros for querying and extracting value from structured data by JavaScript-like syntax

valq   valq provides a macro for querying and extracting value from structured data in very concise manner, like the JavaScript syntax. Look & Feel: u

Shellharden is a syntax highlighter and a tool to semi-automate the rewriting of scripts to ShellCheck conformance, mainly focused on quoting
Shellharden is a syntax highlighter and a tool to semi-automate the rewriting of scripts to ShellCheck conformance, mainly focused on quoting

Shellharden is a syntax highlighter and a tool to semi-automate the rewriting of scripts to ShellCheck conformance, mainly focused on quoting

A superset of PHP with extended syntax and runtime capabilities.

PXP PXP is a superset of the PHP programming language that provides an extended set of syntax rules and language features to improve developer experie

Owner
Markus Moenig
Creator of Open Source graphic applications and games using Rust, Swift and Metal. Enjoying life in Thailand.
Markus Moenig
A cat(1) clone with syntax highlighting and Git integration.

A cat(1) clone with syntax highlighting and Git integration. Key Features β€’ How To Use β€’ Installation β€’ Customization β€’ Project goals, alternatives [δΈ­

David Peter 38.9k Jan 8, 2023
A syntax-highlighting pager for git, diff, and grep output

Get Started Install delta and add this to your ~/.gitconfig: [core] pager = delta [interactive] diffFilter = delta --color-only [delta]

Dan Davison 16k Dec 31, 2022
Simple calculator REPL, similar to bc(1), with syntax highlighting and persistent history

eva simple calculator REPL, similar to bc(1), with syntax highlighting and persistent history installation Homebrew $ brew install eva crates.io $ car

Akshay 632 Jan 4, 2023
🌴 Syntax highlighting in Rust.

?? HL (WIP) Syntax highlighting written in Rust. The project is designed to generate html syntax highlighting for the given file. This software is ins

ahmadrosid 8 Jun 28, 2022
🌈 A nushell plugin for syntax highlighting.

nu-plugin-highlight A nushell plugin for syntax highlighting. About nu-plugin-highlight is a plugin for Nushell that provides syntax highlighting for

Piepmatz 4 Jun 29, 2023
Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. A tokei/scc/cloc alternative.

tcount (pronounced "tee-count") Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. Quick Start Simply run tcount

Adam P. Regasz-Rethy 48 Dec 7, 2022
Terminal UI that allows Alacritty users to quickly and easily shuffle through provided themes πŸ¦„

Alac-pretty alac-pretty.mp4 If you're like me in that you constantly need to change the colors of your dev environment because visual stagnation reall

Benji Nguyen 17 Aug 29, 2022
Convert your favorite images and wallpapers with your favorite color palettes/themes

dipc doprz' image palette converter Convert your favorite images and wallpapers with your favorite color palettes/themes Color Palettes/Themes catppuc

null 50 Apr 26, 2023
A cli util to apply themes to hyprland

Hyprtheme works with themes installed at ~/.config/hypr/themes additional themes can be installed from hyprland-community/theme-repo theme.toml this f

Hyprland Community 4 Jan 15, 2023
WIP. Goals: Treesitter highlighting, snippets, and a smooth intergration with neovim.

typst.nvim WIP. Goals: Tree-sitter highlighting, snippets, and a smooth integration with neovim. For the past week, I've been thinking what I want for

SeniorMars 66 Apr 9, 2023