aboutsummaryrefslogtreecommitdiff
path: root/src/event_loop.rs
AgeCommit message (Collapse)Author
2018-01-06Add clippy check to travisChristian Duerr
This commit adds clippy as a required step of the build process. To make this possible, all existing clippy issues have been resolved.
2017-10-30fix some typos in commentsMartin Lindhe
2017-09-05Update most remaining depsJonathan Schleußer
2017-07-31Read more from ptyJoe Wilm
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.
2017-05-24Minor cleanup, style fix, dead code removalJoe Wilm
2017-05-24Add DrainResult enumAaron Hill
2017-05-24Fix typoAaron Hill
2017-05-24Ensure that the event loop thread cleanly exits on shutdownAaron Hill
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
2017-05-24Fix #573. Ensure we don't write 0 bytes to ptyMartin Algesten
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.
2017-04-03Better error handling in event loopJoe Wilm
Also checks hup first since if the terminal is either not readable or writable there's nothing for Alacritty to do. Closes #480.
2017-01-11Fix bug where event loop could get stuck readingJoe Wilm
One symptom of this bug was being unable to send C-c during `cat /dev/urandom`. cc #271
2017-01-06Handle EINTR in I/O loopJoe Wilm
This fixes an issue where encountering some signals panicked the event loop thread. Resolves #76
2016-12-29Fix pty read sometimes not triggering drawJoe Wilm
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.
2016-12-26Major cleanup for event handlingJoe Wilm
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.
2016-12-16Misc formatting fixesJoe Wilm
2016-12-16Rustup and clippyJoe Wilm
All of the changes in this commit are due to clippy lints.
2016-12-11Display manages window, renderer, rasterizerJoe Wilm
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.
2016-12-11Cleaning up main; Added window moduleJoe Wilm
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().
2016-12-11Implement Handler::identify_terminal for TermJoe Wilm
The identify_terminal function signature had to change to support writing to the terminal before processing additional input.
2016-11-19Add support for recording/running ref testsJoe Wilm
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`.
2016-11-11Fix alacritty shutdown when shell exits on macOSJoe Wilm
Readiness for the pty file descriptor will never be HUP or ERROR; the out-of-band flag raised by sigchld is used instead. Resolves #14.
2016-09-26Clean up event_loop moduleJoe Wilm
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.
2016-09-25Refactor EventLoop into event_loop moduleJoe Wilm
This type and its implementations were seriously cluttering main.rs.