Commit Graph
80 Commits
Author SHA1 Message Date
Joe Wilm d514b38223 Vendor upcoming Utf8Chars iterator from libstd
The upcoming Utf8Chars iterator was vendored from a libstd PR. The
iterator works on BufRead types which is critical for improving
performance. A small modification was made where the number of unused
bytes is included with Utf8CharsError::IncompleteUtf8.

The pty reader thread was updated to use this new type. Next steps will
be moving the parsing there and either sending parse results in batches
or updating the terminal directly from that thread.
2016-06-30 21:26:26 -07:00
Joe Wilm d304ea9b77 Add config file
Configuration may now be specified in either `$HOME/.alacritty.yml` or
`$HOME/.config/alacritty.yml`. See `alacritty.yml` in the repository
root for an example.

When a configuration file cannot be located, a default configuration is
used.
2016-06-30 09:04:06 -07:00
Joe Wilm 58146acea5 Add license header to glsl files 2016-06-29 21:01:22 -07:00
Joe Wilm c8fd2c090c Add license headers to source files 2016-06-29 20:59:14 -07:00
Joe Wilm a445ae92a8 Fix resizing on macOS
The resize callback is the only way to perform live resizing on macOS. A
callback is provided, and a static variable is used to provide a Sender
to that function so that resize events may be processed in the usual
way.
2016-06-29 20:14:37 -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 8454bbe183 Enable vsync
The input/pty processing loop previously consumed input on a channel and
hit the rendering when the queue became empty. This had a couple of
problems

1. It was possible to be overwhelmed with input and not give the
   renderer an opportunity to update the screen. This gave the
   appearance of locking up.
2. Multiple frames could be rendered for a single vblank (redundant
   work)
3. Open loop rendering would inevitably have buffer swapping out of sync
   with vblanks and visual tearing would occur.

This commit enables vsync on the glutin window. The rendering was all
moved onto a separate thread from input/pty processing to support vsync.
However, the rendering thread must be 100% synchronized with the updater
thread. There's now a Mutex on the Term, and an atomic bool to ask the
input/pty processing to yield to the renderer.

One aspect of this feature that hasn't been worked out is how to limit
the frame rate. Currently, it just free runs at the screen refresh rate.
The initial attempt here included the input/pty processor holding a lock
while waiting for input. This *almost* worked, but there was a (not
uncommon) edge case where the terminal state was "dirty" but the
renderer was not ready to draw.

Instead of blocking on the refresh issue, it's being punted to after an
MVP is released. The overhead of drawing at 60Hz was profiled to be ~5%
CPU usage, and this is deemed acceptable for an MVP.
2016-06-27 19:46:24 -07:00
Joe Wilm 23dbf72154 Fix subpixel rendering for macOS
This adds a bunch of APIs to CGContext (and supporting types) that
aren't actually necessary to turn on subpixel rendering. The key for
subpixel rendering were the options passed to bitmap_context_create().
Specifically, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host
are necessary to enable it.
2016-06-24 21:58:13 -07:00
Joe Wilm 078dd41e37 Function keys send escape sequences
This doesn't currently handle any of the modifiers, but it does mean
applications like `htop` can be used.
2016-06-23 21:24:35 -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 f5faa40066 Fix a few compiler warnings 2016-06-14 08:26:02 -07:00
Joe Wilm 4ecc4a15f1 Cache cargo dependencies on travis
This should improve build times.
2016-06-14 07:55:00 -07:00
Joe Wilm 432922d624 Add macOS to CI matrix 2016-06-14 07:53:45 -07:00
Joe Wilm bd8bd26c8b Add support for macOS
Alacritty now runs on macOS using CoreText for font rendering.

The font rendering subsystems were moved into a separate crate called
`font`. The font crate provides a unified (albeit limited) API which
wraps CoreText on macOS and FreeType/FontConfig on other platforms. The
unified API differed slightly from what the original Rasterizer for
freetype implemented, and it was updated accordingly.

The cell separation properties (sep_x and sep_y) are now premultiplied
into the cell width and height. They were previously passed through as
uniforms to the shaders; removing them prevents a lot of redundant work.

`libc` has some differences between Linux and macOS. `__errno_location`
is not available on macOS, and the `errno` crate was brought in to
provide a cross-platform API for dealing with errno.

Differences in `openpty` were handled by implementing a macOS specific
version. It would be worth investigating a way to unify the
implementations at some point.

A type mismatch with TIOCSCTTY was resolved with a cast.

Differences in libc::passwd struct fields were resolved by using
std::mem::uninitialized instead of zeroing the struct ourselves. This
has the benefit of being much cleaner.

The thread setup had to be changed to support both macOS and Linux.
macOS requires that events from the window be handled on the main
thread. Failure to do so will prevent the glutin window from even
showing up! For this reason, the renderer and parser were moved to their
own thread, and the input is received on the main thread. This is
essentially reverse the setup prior to this commit. Renderer
initialization (and thus font cache initialization) had to be moved to
the rendering thread as well since there's no way to make_context(null)
with glx on Linux. Trying to just call make_context a second time on the
rendering thread had resulted in a panic!.
2016-06-14 07:39:06 -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 a60dbd564b Sort some imports 2016-06-09 08:16:44 -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 8b1e82f31a Fix shutdown deadlock
Calling ::std::process::exit() from the SIGCHLD handler would sometimes
deadlock some OpenGL internal shutdown procedure. To resolve this, a
flag was added that can be checked with `process_should_exit`.
2016-06-08 21:24:31 -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 781c67f0a0 Parse a few more ansi terminal mode commands 2016-06-07 21:13:08 -07:00
Joe Wilm 6f3e890197 Handle pty char recv errors
The main loop is now exitted if the char sender hangs up.
2016-06-07 21:12:21 -07:00
Joe Wilm 06451fbab1 Add named thread for pty reader 2016-06-07 21:11:23 -07:00
Joe Wilm 5e920b893a Unwrap some unhandled errors
They're still unhandled, but they won't silently pass by anymore.

TODO
2016-06-07 21:10:45 -07:00
Joe Wilm 3d62c2b8f5 Add explicit bounds check when advancing cursor 2016-06-06 17:46:26 -07:00
Joe Wilm 581eb6b69f Tweak some Grid methods
Adds some #[inline] tags, and delegates to internals for num_rows and
num_cols. In case these become different than the expected values, this
should help to fail sooner.
2016-06-06 17:45:09 -07:00
Joe Wilm 7834bd177f Fix bug where there were extra grid rows
Apparently VecDeque::with_capacity is more of a suggestion.
2016-06-06 17:44:06 -07:00
Joe Wilm 1a7eda7b05 Terminal sets more attributes on grid Cells 2016-06-06 17:43:14 -07:00
Joe Wilm 263a4e8a2e Fix escape bytes as input bug in ANSI parser
There were several unrecognized escape codes that have arguments which
were being interpretted as input. Naturally, this caused state to be
corrupt. The escape codes are now handled by throwing away the bytes.
Consider this a TODO for later.
2016-06-06 17:41:03 -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 e5aeae69aa Update task list 2016-06-06 14:59:45 -07:00
Joe Wilm a25c9bf1a7 Handle SIGCHLD
Closes alacritty after joining with child process.
2016-06-06 14:57:48 -07:00
Joe Wilm 78f5de4935 Support dynamic character loading
The glyph cache was previously initialized with a list of glyphs from
INIT_LIST, and never updated again. This meant that code points not
included in that list were not displayed. Now, the glyph cache has
gained the ability to load new glyphs at render time.

This seems to have lightly decreased performance for some reason.
2016-06-06 14:31:12 -07:00
Joe Wilm b977a15187 Batching flushes on texture change
This fixes a bug when multiple atlases are required.
2016-06-06 13:29:05 -07:00
Joe Wilm ed7aa96907 Refactor Instanced Drawing to use Vertex Arrays
Per-instanced data was previously stored in uniforms. This required
several OpenGL calls to upload all of the data, and it was more complex
to prepare (several vecs vs one).

Additionally, drawing APIs are now accessible through a `RenderApi`
(obtained through `QuadRenderer::with_api`) which enables some RAII
patterns. Specifically, checks for batch flushing are handled in Drop.
2016-06-06 13:20:35 -07:00
Joe Wilm 1f3f9add49 Optimize Rendering with batched draw calls
Draw calls are now batched for performance. Render times on git log at
the default size are now ~200usec.
2016-06-04 21:31:41 -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 2f058bd053 Optimize rendering
This moves some logic that was previously being done per-character into
the vertex shader. At this time, we've traded CPU computation for
additional gl::Uniform2f calls. This is only a marginal improvement.
However, this patch positions the renderer well for instanced drawing,
and that will be a huge performance win.
2016-06-04 15:30:17 -07:00
Joe Wilm f944b517fa Add live-reload for shaders
Recompiling the entire program whenever a shader changes is slow, and it
can interrupt flow. Shader reloads are essentially instantaneous now. If
the new shader fails to compile, no state is changed; the previous
program continues to be used.
2016-06-04 10:54:33 -07:00
Joe Wilm c475c82c69 render: cleanup active_tex handling
- Removes a spammy printn!
- Sets active_tex to zero wherever gl::BindTexture is called with zero
2016-06-03 21:31:33 -07:00
Joe Wilm 97867d86f2 Move debug timer
It was near the left side; it will be less in-the-way on the right.
2016-06-03 09:26:22 -07:00
Joe Wilm 2e51d92a92 Use texture atlas for glyphs
This dramatically reduces the number of BindTexture calls needed when
rendering the grid. Draw times for a moderately full terminal of the
default size are ~1ms with this patch.
2016-06-02 22:14:55 -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 a8024f64c7 Update Cargo dependencies
Most importantly, freetype-rs was updated to use freetype-sys 0.4 which
includes the LCD_FILTER apis.
2016-06-02 19:54:16 -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