Resolves an issue with partial draws where programs like vim would send
data, but only part of it would be drawn.
The logic for escaping when a write is pending has been removed in favor
of limiting bytes processed during a pty_read call.
The value of MAX_READ may not be ideal.
Background:
If a shell process exits with children still alive (typically due to the
`disown` shell builtin), POLLHUP will not be sent to the master PTY file
descriptor. This is due to the fact that the disowned process still has
the slave PTY open as its STDIN, STDOUT, and STDERR.
If a disowned process never reads or writes from its file descriptors
(which is often the case for graphical applications), the event loop
will end up blocking on poll()/select() when not handling user input
received over the mio channel. When Alacritty shuts down and joins on the
event loop thread, there can never be any more input on the mio channel -
the main thread is no longer handling user keystrokes from the window. Unless
a disowned process happens to access its slave PTY file descriptors, the
event loop will never get the chance to deetect that it should exit.
This commit extends the `Msg` enum to include an explicit `Shutdown`
message, which ensures a clean shutdown (e.g. closing the 'recording'
file). This allows the select()/poll() call to remain blocking, instead
of needing to periodically check the shutdown state in between
timed-out calls.
Fixes#339
Any action that results in 0 bytes, such as pasting 0 bytes
from the clipboard hangs the terminal (`pbcopy </dev/null`
followed by ctrl-v), hangs the terminal on both macOS and
Linux. This ensures we never send 0 bytes.
There was a lot of complexity around the threadsafe `Flag` type and
waking up the event loop. The idea was to prevent unnecessary calls to
the glutin window's wakeup_event_loop() method which can be expensive.
This complexity made it difficult to get synchronization between the pty
reader and the render thread correct. Now, the `dirty` flag on the
terminal is also used to prevent spurious wakeups. It is only changed
when the mutex is held, so race conditions associated with that flag
shouldn't happen.
The event handling code grew organically over time, and with that came a
number of warts. The primary issue was with passing some random
selection of arguments to the input::Processor based on what the input
was. There was the issue that if multiple events were drained from a
single PollEventsIterator, the terminal mutex was potentially locked and
unlocked many times. Finally, and perhaps most importantly, there was no
good way to pass necessary state to the Action executor without going
through several API layers.
To fix all that, the input::ActionContext and input::Processor are now
generated once per call to the event::Processor. The input::Processor
holds onto the ActionContext so that it doesn't need to be passed
through layers of function calls. When a binding is activated, the
ActionContext is simply passed to the handler.
This did have the effect of breaking the input::Processor tests
(specifically, those relating to bindings). The issue was not addressed
in this commit since a larger refactor of the bindings is planned which
should also improve testability.
This is part of an ongoing decoupling effort across the codebase and
tidying effort in main.rs. Everything to do with showing the window with
a grid of characters is now managed by the `Display` type. It owns the
window, the font rasterizer, and the renderer. The only info needed from
it are dimensions of characters and the window itself for sizing the
terminal properly. Additionally, the I/O loop has access to wake it up
when new data arrives.
Adds a wrapper for the glutin::Window which provides strongly typed
APIs and more convenient interfaces. Moves some gl calls into the
opengl-based renderer.
The point of most of the changes here is to clean up main().
Ref tests use a recording of the terminal protocol and a serialization
of the grid state to check that the parsing and action handling systems
produce the correct result. Ref tests may be recorded by running
alacritty with `--ref-test` and closing the terminal by using the window
"X" button. At that point, the recording is fully written to disk, and a
serialization of important state is recorded. Those files should be
moved to an appropriate folder in the `tests/ref/` tree, and the
`ref_test!` macro invocation should be updated accordingly.
A couple of changes were necessary to make this work:
* Ref tests shouldn't create a pty; the pty was refactored out of the
`Term` type.
* Repeatable lines/cols were needed; on startup, the terminal is resized
* by default to 80x24 though that may be changed by passing
`--dimensions w h`.
* Calculating window size based on desired rows/columns and font metrics
required making load_font callable multiple times.
* Refactor types into library crate so they may be imported in an
integration test.
* A whole bunch of types needed symmetric serialization and
deserialization. Mostly this was just adding derives, but the custom
deserialization of Rgb had to change to a deserialize_with function.
This initially adds one ref test as a sanity check, and more will be
added in subsequent commits. This initial ref tests just starts the
terminal and runs `ll`.
The main loop body was originally all written inline. There's now
separate functions for each of the actions the loop handles including
channel events, pty reading, and pty writing. There's also helper
functions on State for managing the write list.
The `EventLoop` and its `State` are returned when joining with the
thread it spawns. This will potentially be helpful once config reloading
is introduced.