Comments (7)
Got something minimal to share and seeking some direction - opening a file from arguments, rendering the text contents to a window.
I've included a super simple implementation of a Piece table which looks to be the easiest way to build a text editor.
I've also used the text segmentation from roc-lang/unicode to split the input file into graphemes so in theory this should support unicode out of the box π€
So far the demo only renders text, the editing and saving functionality hasn't been included yet.
I'm pretty sure the undo/redo will be essentially free. The plan is to just keep a new copy of the Piece Table (sans buffers) on each significant user action (edits) in a list. This is just duplicating the indexes into the buffers and so shouldn't grow too significantly unless the user has very long editing session. We can always just keep the latest N edits or something if it becomes a problem.
WIP code for this demo (I haven't removed any of the code from the menu example, just added the parts for editor)
Questions
- Do you think it is acceptable to render newlines just using
"ΒΆ"
, this dramatically simplifies the code code. Though if we want to include line numbers then we will need to handle CLRF breaks anyway? - Do we want multiple "pages", like a menu or something, or keep it simple an just open straight into the editing window?
- Do we want multiple "modes", like vim, command and insert and support different controls in each? This should be pretty easy to support, maybe just a couple of the basics.
Demo
from book-of-examples.
Quick update on progress this weekend.
- handle line breaks
- remove unused code from previous example
- implement a ViewPort to draw the content (was helpful for testing edge cases, may be useful in future for e.g. editing multiple files)
- enable saving of changes using Ctrl-S keypress
- add text insertion (and implementation for the PieceTable data structure)
I've had to make a few changes to the roc-ansi package, so this has been good to flush those issues out and resolve them.
I've also been adding a lot of inline comments and thinking about the dot points for the chapter content.
Demo
from book-of-examples.
π to a simple text editor - I found with the Python version that mapping various coordinate systems to each other and handling basic keyboard input was one chapter, while adding undo/redo was another. Don't know if it would be the same here?
from book-of-examples.
This is a great start - well done! I based the editor in the Python book on the first few parts of Wasim Lorgat's tutorial https://wasimlorgat.com/posts/editor.html - I think we definitely want the line breaks, but modes and windows and what-not won't fit into the one-hour limit.
from book-of-examples.
this is great work - thank you very much. I think you may already have an hour's worth of teachable material - if you'd like to grab some time with me ([email protected]) I'd be happy to talk you through next steps.
from book-of-examples.
Sounds good. I sent you a meeting request via email. Just took a guess at a suitable time re timezones. Apologies if it's too short notice, I could find a time next week.
I'd like to implement text deletion to close out the Piece table basics. Also I'll need to make a release for the unicode and ansi dependencies before this will be usable more generally.
If you don't mind I'd love to write something up about this for my blog and share in the online meetup this weekend, it won't be the same content as the book more my experience.
from book-of-examples.
Blogging about this would be great, and no worries about overlap with whatever you're going to write for the book: you own the rights to your blog posts, so you can decide to recycle them.
from book-of-examples.
Related Issues (20)
- infrastructure proposal: create a blog for this book HOT 4
- topic proposal: discrete event simulator HOT 5
- topic: continuous integration HOT 2
- topic proposal: machine learning from first principles HOT 2
- topic proposal: property-based testing framework HOT 3
- topic proposal: a parser with useful error messages
- topic proposal: pseudorandom number generators HOT 1
- topic: regex pattern matching HOT 1
- topic proposal: Redis-like key value store with write-ahead log HOT 7
- topic: JSON ADT and codecs HOT 5
- topic proposal: Parser combinator library HOT 5
- proposal: Prohibit external packages HOT 9
- topic: compression
- proposal: use Jekyll/GitHub Pages _temporarily_ to build a website for this material HOT 2
- Topic proposal: A transpiler to JavaScript HOT 3
- meeting 2024-04-10 HOT 1
- discuss: how to manage inter-chapter dependencies? HOT 1
- topic: package manager
- topic: pretty-printing library HOT 2
- add link to rendered site
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from book-of-examples.