cpjreynolds / rustty

A terminal UI library
https://docs.rs/rustty
MIT License
153 stars 14 forks source link

Handle out of bounds error #2

Closed ghost closed 9 years ago

ghost commented 9 years ago

Accessing out of bounds indexes would make us panic (without message because of our messing up with the TTY). This commits handles out of bounds errors be returning a dummy cell.

This required to change the indexing API from term[y][x] to term[(y, x)] because otherwise, we would have had to override Vec's indexing methods (our rows are plain vectors and although our first indexing go through CellBuffer's indexing implementation, our second indexing is handled directly by Vec).

The old API was left there for now, to avoid breakeage.

@cpjreynolds, what do you think of the proposed indexing API? Is there a particular reason why term[y][x] was chosen instead of term[(y, x)] in the first place?

cpjreynolds commented 9 years ago

Thanks for the PR!

I definitely agree that we should handle out of bounds indexes without crashing, and possibly leaving the TTY in a messed up state on exit. I chose to use term[y][x] primarily for ergonomic reasons and didn't consider handling out of bounds indexes, however this is definitely something we should address.

I like what you have proposed, and I'm happy to merge it. Luckily since we're only version 0.1.3 (0.1.4 after this commit), we can still break things before committing to a stable API.

I've got a pretty free week coming up so I'll be able to put in a lot more work on this; I'm planning on finishing tidying up the driver module tomorrow and then I'll take a closer look at our cellbuffer implementation.