Closed cpjreynolds closed 9 years ago
This mimics Vec
's behavior, so it's a better idea than silently returning a dummy cell.
@cpjreynolds, as I looked more closely, I noticed that you inverted what was previously (y, x)
into (x, y)
everywhere. I just want to point out that this breaks with ncurses' convention. Not that it's necessarily a bad thing, but I thought it was worth mentioning.
@hsoft, regarding swapping (y, x) for (x, y). I thought about keeping it the same as ncurses' convention, but I found myself continually getting caught up confusing (y, x) with the more traditional (x, y). Since the actual indexing is all abstracted by the library anyway, it would be trivial to extend it later on to include (y, x) indexing if there is demand.
This PR implements a major refactoring of the CellBuffer API and makes breaking changes to the Terminal interface.
Breaking changes:
get
andget_mut
, which return an option containingNone
if the index is out of bounds. Indexing the Terminal with the indexing operator, (term[(x, y)]
) will now panic on out-of-bounds indexes, reverting the change made in #2, as we have theget
methods for safe indexing now.Note: Out-of-bounds indexing with the index operator WILL panic and WILL cause the tty to be left in and indeterminate and possibly broken state. Rust does not guarantee that
drop
will run, so we cannot guarantee that the terminal state will be restored on panic. If you are not sure your index will be in bounds, useget
andget_mut
. This is especially important if the terminal re-sizes and your application is not prepared.