{"id":24072936,"url":"https://github.com/markusmoenig/code_editor","last_synced_at":"2025-04-28T15:32:27.630Z","repository":{"id":58052241,"uuid":"529777056","full_name":"markusmoenig/code_editor","owner":"markusmoenig","description":"A standalone code editor with syntax highlighting and themes.","archived":false,"fork":false,"pushed_at":"2023-06-01T07:27:34.000Z","size":69296,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T10:51:10.931Z","etag":null,"topics":["code-editor","framebuffer","rust","syntax-highlighting","themes"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markusmoenig.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"markusmoenig"}},"created_at":"2022-08-28T06:02:49.000Z","updated_at":"2025-01-04T18:26:46.000Z","dependencies_parsed_at":"2023-02-10T07:46:09.291Z","dependency_job_id":null,"html_url":"https://github.com/markusmoenig/code_editor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2Fcode_editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2Fcode_editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2Fcode_editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2Fcode_editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markusmoenig","download_url":"https://codeload.github.com/markusmoenig/code_editor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251338603,"owners_count":21573584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-editor","framebuffer","rust","syntax-highlighting","themes"],"created_at":"2025-01-09T17:23:45.403Z","updated_at":"2025-04-28T15:32:27.576Z","avatar_url":"https://github.com/markusmoenig.png","language":"Rust","funding_links":["https://github.com/sponsors/markusmoenig"],"categories":[],"sub_categories":[],"readme":"[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/) [![version](https://img.shields.io/badge/version-0.3.4-red.svg)](https://shields.io/) [![Twitter](https://badgen.net/badge/icon/twitter?icon=twitter\u0026label)](https://twitter.com/markusmoenig)\n\n# CodeEditor\n\nA standalone code (and text) editor for people like me who write their own user interfaces utilizing crates like [pixels](https://github.com/parasyte/pixels).\n\nCodeEditor renders its display into a ```Vec\u003cu8\u003e``` and is completely independent from any UI crate. It utilizes [fontdue](https://github.com/mooman219/fontdue) for rendering fonts.\n\n## Example App\n\nA standalone ```pixels``` and ```winit``` based example app is included in this repo.\n\n![Screenshot](images/screenshot.png)\n\n## Usage\n\nAdd code_editor to your Cargo.toml\n\n```\ncode_editor = \"0.3.4\"\n```\n\nAnd than in your app\n\n```rust\nuse code_editor::prelude::*;\n\nlet mut code_editor = CodeEditor::new();\ncode_editor.set_font(\"fonts/Source_Code_Pro/static/SourceCodePro-Regular.ttf\");\ncode_editor.set_mode(CodeEditorMode::Rhai);\ncode_editor.set_font_size(17.0);\n\ncode_editor.set_text(\"Your source code\".to_string());\n```\n\nIn your draw loop you can than draw the editor\n\n```rust\ncode_editor.draw(frame, (0, 0, width, height), width);\n```\n\nThe second parameter is the drawing rectangle into your frame, the last parameter is the stride in pixels.\n\nYou 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. There are also slots for ```cut```, ```copy```, ```paste```, ```undo``` and ```redo```. You will need to connect these in your app as well (the example app does not handle them).\n\n#### Syntax Highlighting\n\nThe 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.\n\n#### Themes\n\nThe default theme has this implementation:\n\n```rust\nimpl Theme {\n    pub fn new() -\u003e Self {\n        Self {\n            background      : [34, 34, 36, 255],\n            line_numbers    : [160, 160, 160, 255],\n            line_numbers_bg : [30, 30, 32, 255],\n\n            text            : [255, 255, 255, 255],\n            cursor          : [170, 170, 170, 255],\n\n            identifier      : [120, 214, 255, 255],\n            number          : [159, 197, 146, 255],\n            keywords        : [45, 133, 200, 255],\n            brackets        : [226, 73, 146, 212],\n            comments        : [69, 128, 56, 212],\n            string          : [197, 117, 92, 212],\n\n            error           : [237, 55, 54, 255],\n        }\n    }\n}\n```\n\nYou can tweak it in the theme property of the CodeEditor struct or you can set a new theme via the ```set_theme(theme);``` function.\n\n# Disclaimer\n\nCodeEditor is actively maintained and I will improve it over time as I use it for my own applications.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusmoenig%2Fcode_editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkusmoenig%2Fcode_editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusmoenig%2Fcode_editor/lists"}