Commit Graph

29 Commits

Author SHA1 Message Date
Joe Wilm f895c2da30 Add support for application keypad mode
Nothing uses it yet, but it is tracked in the terminal state.
2016-07-04 09:19:48 -07:00
Joe Wilm b0444f05d6 Term::ansi::Handler methods use debug_println!
debug_println! statements are compiled out in release builds. This
allows us to see what the terminal is sending in debug builds while
having good perf in release builds.
2016-07-04 08:42:18 -07:00
Joe Wilm f8579ff53e Make ansi::Handler methods strongly typed
ansi::Handler methods dealing with lines or columns now accept a `Line`
or `Column` where appropriate instead of ambiguous `i64`.
2016-07-03 21:58:35 -07:00
Joe Wilm 8a4f14188e Make ansi::TermInfo strongly typed
The rows function has been renamed to lines, and it now returns `Line`.
The cols function correspondingly returns `Column`.
2016-07-03 21:12:43 -07:00
Joe Wilm 6639e6f24f Move ::grid::index to ::index
The grid and term modules already rely on the index types, and ansi is
about to be updated with strongly typed APIs. Since Cursor, Line, and
Column are fundamental to the code in several modules, namespacing them
under one of them seems less correct than a module that stands by
itself.
2016-07-03 21:07:58 -07:00
Joe Wilm 63098f210e Remove now unused CursorExt
Since the addition of `Line` and `Column`, the CursorExt methods were
essentially unused.
2016-07-03 17:12:16 -07:00
Joe Wilm da19fa1940 Mark ansi::Handler methods for Term with #[inline]
The original idea with ansi::Handler and the ansi::Parser was that the
Parser being generic over Handler could result in code equivalent to a
hand written parser + handler from a method dispatch perspective. Proper
inlining is required to achieve that, so this marks the ansi::Handler
methods appropriately.
2016-07-03 17:07:23 -07:00
Joe Wilm 7f1c1efe47 Grid API is now generic and strongly typed
The Grid no longer knows about a `Cell` and is instead generic. The
`Cell` type is coupled to the `term` module already, and it's been moved
there to reflect the strong relationship.

Grid APIs previously accepted `usize` for many arguments. If the caller
intended rows to be columns, but the function accepted them in reverse,
there would be no compiler error. Now there is, and this should prevent
such bugs from entering the code.

The Grid internals grew significantly to accomodate the strongly typed
APIs. There is now a `grid::index` module which defines Cursor, Line,
and Column. The Grid APIs are all based on these types now. Indexing for
Ranges proved to be somewhat awkward. A new range had to be constructed
in the implementation. If the optimizer can't figure out what's going on
in that case, the ranges may not be a zero-cost abstraction.
2016-07-03 17:00:00 -07:00
Joe Wilm f2e6d66a5e Improve ergonomics of iterating on grid::Row
Iterating on grid::Row types no longer requires calls to iter() or
iter_mut().
2016-07-02 08:25:21 -07:00
Joe Wilm a2ca10643f Implement Term::erase_chars
Fixes last known issue with htop. I think this implementation might not
be correct, but I don't yet understand the difference between erasing
and deleting (I imagine it's the difference between graphics state vs
grid state). Will probably need to circle back here.

Adds all range indexing operations to rows. Some were needed for the
erase_chars impl, and the rest are there for fully generality.
2016-07-01 21:13:09 -07:00
Joe Wilm 9e45eea0c9 Fix sign error with scroll directions
This resolves an issue with the htop process list becoming corrupt.
2016-07-01 21:12:30 -07:00
Joe Wilm c8fd2c090c Add license headers to source files 2016-06-29 20:59:14 -07:00
Joe Wilm 22789f35c7 Implement terminal resizing
The resize event is received from glutin on the update thread, but the
renderer needs to be informed as well for updating the viewport and
projection matrix. This is achieved with an mpsc::channel.

To support resizing, the grid now offers methods for growing and
shrinking, and there are several implementations available for
clear_region based on different Range* types.

Core resize logic is all in Term::resize. It attempts to keep as much
context as possible when shinking the window. When growing, it's
basically just adding rows.
2016-06-29 10:21:02 -07:00
Joe Wilm 69ed81d249 Refactor Tty and Grid creation into Term::new
This moves more logic out of main() and prepares the Term type to handle
resizing. By providing all size data to Term, it is now possible to
implement a resize function there which handles all resizing logic save
for the rendering subsystem.
2016-06-28 09:18:54 -07:00
Joe Wilm 00223b32c9 Implement special input handling
There's a number of keys/combinations that should emit escape sequences
to the PTY when triggered. This commit adds a framework to support that.
The input::Processor is a type which tracks state of modifier keys. When
special keys (like arrow, function) are detected, the processor pulls up
a list of candidate escapes to send, and picks the first one based on
terminal mode and active modifier keys. The input::Processor is generic
over the thing receiving the escape sequences, the input::Notify type.
Included is a wrapper for `&mut io::Write` which implements
input::Notify and is currently used to connect the processor to the PTY
stream.

This added handling of the APP_CURSOR mode which changes affects input
processing.
2016-06-23 09:48:31 -07:00
Joe Wilm 09600a3d40
Fix bug handling ansi mode sequences
The sense of set_mode and unset_mode was inverted. The
TextCursor/ShowCursor mode depended on the incorrect behavior, and that
was fixed as well. TextCursor was renamed to ShowCursor to be perfectly
clear on the intent.
2016-06-23 09:43:55 -07:00
Joe Wilm 2395066318
Fix backspace
There's never a count associated with this, and it has been removed from
the Handler method to reflect as much.
2016-06-09 08:37:59 -07:00
Joe Wilm 8566e17860
Fix all trivial compiler warnings
Of note are the `ansi` and `grid` modules becoming public. There are
several bits of unused code in each of these. In the case of `grid`, the
unused parts are generally useful, like some indexing implementations.
In ansi, there are pieces that will be used once the parser is more
complete. In any case, these modules are fairly generic and mostly
usable outside of Alacritty.

Unused cargo packages were also removed.
2016-06-09 08:30:55 -07:00
Joe Wilm aff56a65a4
Make state updates and rendering event driven
The main thing preventing this system being event driven in the past was
input from the keyboard had to be polled separately from pty activity.
This commit adds a thread for the window event iterator and sends them
on the same channel as pty characters.

With that in place, the render loop looks like

    - Block on 1 available input
    - Get all remaining available input that won't cause blocking
    - Render

Which means that rendering is only performed on state changes. This
obsoleted the need for a `dirty` flag in the Term struct.
2016-06-09 08:06:47 -07:00
Joe Wilm 8126841ed3
Add support for scrolling regions
It's now possible to move around within Vim without the screen becoming
corrupt!

The ANSI parser now calls a (new) `set_scrolling_region` on the handler
when the DECSTBM CSI is received. In order to provide a sensible default
in case that the sequence doesn't include arguments, a TermInfo trait
was added which currently has methods for inspecting number of rows and
columns. This was added as an additional trait instead of being included
on Handler since they have semantically different purposes. The tests
had to be updated to account for the additional trait bounds.

The utilities module now has a `Rotate` trait which is implemented for
the built-in slice type. This means that slices and anything derefing to
a slice can be rotated. Since VecDeque doesn't support slicing (it's
a circular buffer), the grid rows are now held in a Vec to support
rotation.

For ergomomic access to the grid for scrolling and clearing regions,
additional Index/IndexMut implementations were added to the grid::Row
type.

Finally, a `reset` method was added to `Cell` which properly resets the
state to default (instead of just clearing the char). This supports
region clearing and also fixed a bug where cell backgrounds would remain
after being cleared.
2016-06-08 10:39:49 -07:00
Joe Wilm 0e7bb8d76e
Handle TEXT_CURSOR mode
When the flag is unset, the cursor is not rendered.
2016-06-07 21:17:48 -07:00
Joe Wilm 6c82fa9d7b
Only draw when terminal state has changed
This is achieved by setting a `dirty` flag when the terminal receives
an event that causes visible state to change. The implementation is
pretty much crap because most methods know about the flag.

Figure out something better later.
2016-06-07 21:15:53 -07:00
Joe Wilm 3d62c2b8f5
Add explicit bounds check when advancing cursor 2016-06-06 17:46:26 -07:00
Joe Wilm 1a7eda7b05
Terminal sets more attributes on grid Cells 2016-06-06 17:43:14 -07:00
Joe Wilm cdea958e71
Add support for drawing background colors 2016-06-06 16:54:15 -07:00
Joe Wilm 6636cf6b9f
Minor updates to terminal handling
Properly handles goto_col and goto_row. Additionally, input wrapping is
handled.

Truecolor specs are now set appropriately.
2016-06-06 15:13:45 -07:00
Joe Wilm 4fdd5280f1
Add iterator methods to Grid and Row types
The iterator methods simplify logic in the main grid render function. To
disambiguate iterator methods from those returning counts (and to free
up names), the `rows()` and `cols()` methods on `Grid` have been renamed
to `num_rows()` and `num_cols()`, respectively.
2016-06-04 19:40:30 -07:00
Joe Wilm 2f98871b02
Refactor renderer functions out of main.rs
This moves the rendering logic to draw the grid, to draw strings, and to
draw the cursor into the renderere module. In addition to being an
organizational improvement, this also allowed for some optimizations
managing OpenGL state. Render times for a moderate screen of text
dropped from ~10ms to ~4ms.
2016-06-02 20:27:07 -07:00
Joe Wilm 30ec145109
Initial support for Terminal Emulation (woo!)
This patch introduces basic support for terminal emulation. Basic means
commands that don't use paging and are not full screen applications like
vim or tmux. Some paging applications are working properly, such as as
`git log`. Other pagers work reasonably well as long as the help menu is
not accessed.

There is now a central Rgb color type which is shared by the renderer,
terminal emulation, and the pty parser.

The parser no longer owns a Handler. Instead, a mutable reference to a
Handler is provided whenever advancing the parser. This resolved some
potential ownership issues (eg parser owning the `Term` type would've
been unworkable).
2016-06-02 19:42:28 -07:00