Hecto: Appendices

First chapter - Overview - Last chapter

How the diffs work

Most steps in this tutorial are presented as a diff. A diff shows you the changes you need to make to the previous step’s code to get to the current step. Here’s a sample diff:

src/main.rs CHANGED
@@ -1,3 +1,7 @@
1
+ use std::io::{self, Read};
1
2
  fn main() {
2
- println!("Hello, world!");
3
+ for b in io::stdin().bytes() {
4
+ let c = b.unwrap() as char;
5
+ println!("{}", c);
6
+ }
3
7
  }

See this step on github

Each diff contains one block per modified file. Each block starts with a header that contains the filename of the file you need to edit (“src/main.rs”). After the header, the contents of the file are shown. Additions are highlighted in green, deletions in red. The old line numbers are printed at the left, the new line numbers on the right.

In this example, you need to add a new line on top of the file, leave the next line alone, delete the line that starts with “println” and add a couple of more lines in its place.

At the bottom of each diff, you find a link to github. If you follow that link, you can see the project on github with the code changes applied.

What to do if you are stuck

2022 Update: It has been a few years since I wrote this tutorial, and while the Rust world has been moving along, this tutorial is stuck firmly in place. This means that whenever your code is not working when the tutorial says it should, you might have hit something that is no longer working with the most recent versions of Rust.
In other words: It’s not you, it’s me, and I am sorry.

Some of the code in this tutorial is very tricky to type in exactly, especially if you’re not used to Rust. It’s specially easy to make a mistake when you’re making a change to a line, and you think you’re done changing that line, but you missed one little change to another part of that same line. It’s important to take your time, and compare the changed parts of the diff character-by-character with your code to make sure they’re the same.

If you suspect you made an error, but don’t know where it is, you should do a diff between your version and the tutorial’s version. The easiest way to do so is to use an online diffing tool like DiffChecker. You paste the code from the tutorial to the left (you can obtain it from github by following the “See this change on github” link), and your code to the right and check the differences.

Where to get help

If you are having trouble, feel free to email me.

Ideas for improvements and features

If you want to extend hecto on your own, I suggest trying to actually use hecto as your text editor for a while. You will very quickly become painfully aware of all sorts of features you’re used to having in a text editor, but are missing in hecto. Those are the features you should try to add. And you should use hecto when you work on hecto.

If you’re still looking for ideas, here’s a small list.

  • Support more filetypes
  • Make highlighting markers configurable. For instance, in some languages, a single # instead of two slashes indicate a single line comment.
  • Allow alternatives. For instance, in many languages, characters are not highlighted separately, but instead, strings can be delimited with single or double quotes.
  • Line numbers: Display the line number to the left of each line of the file.
  • Auto indent: When starting a new line, indent it to the same level as the previous line.+
  • Hard-wrap lines: Insert a newline in the text when the user is about to type past the end of the screen. Try not to insert the newline where it would split up a word.
  • Soft-wrap lines: When a line is longer than the screen width, use multiple lines on the screen to display it instead of horizontal scrolling.
  • Better handling of indices: We have been a bit indicisive about when to use saturating_add and similar functions and when to do pointer arithmetic. We also have not done a good job at safely and consistently accessing entries of a Vec.
  • Copy and paste: Give the user a way to select text, and then copy the selected text when they press Ctrl-C, and let them paste the copied text when they press Ctrl-V.
  • Multiple buffers: Allow having multiple files open at once, and have some way of switching between them.
  • Take a look at the Pull Requests for hecto and check out which bugs they are fixing and when they were introduced.

Credits

As written in the beginning, this tutorial has been heavily inspired by this Build your own text editor tutorial. The nifty diffs have been done with diff2html.

License