Fix URL hints not working on macOS

Fixes #363
This commit is contained in:
Kovid Goyal
2018-03-08 13:38:16 +05:30
parent 964ffadc8e
commit eaea0b16b5
2 changed files with 17 additions and 4 deletions

View File

@@ -16,7 +16,7 @@ from collections import namedtuple
from contextlib import closing, contextmanager
from functools import partial
from kitty.fast_data_types import parse_input_from_terminal
from kitty.fast_data_types import parse_input_from_terminal, safe_pipe
from kitty.icat import screen_size
from kitty.key_encoding import (
ALT, CTRL, PRESS, RELEASE, REPEAT, SHIFT, C, D, backspace_key,
@@ -144,8 +144,10 @@ class Loop:
sanitize_bracketed_paste='[\x03\x04\x0e\x0f\r\x07\x7f\x8d\x8e\x8f\x90\x9b\x9d\x9e\x9f]'):
self.input_fd = sys.stdin.fileno() if input_fd is None else input_fd
self.output_fd = sys.stdout.fileno() if output_fd is None else output_fd
self.wakeup_read_fd, self.wakeup_write_fd = os.pipe()
self.sel = s = selectors.DefaultSelector()
self.wakeup_read_fd, self.wakeup_write_fd = safe_pipe()
# For some reason on macOS the DefaultSelector fails when input_fd is
# open('/dev/tty')
self.sel = s = selectors.PollSelector()
s.register(self.input_fd, selectors.EVENT_READ, self._read_ready)
s.register(
self.wakeup_read_fd, selectors.EVENT_READ, self._wakeup_ready
@@ -169,7 +171,10 @@ class Loop:
def _read_ready(self, handler):
if not self.read_allowed:
return
data = os.read(self.input_fd, io.DEFAULT_BUFFER_SIZE)
try:
data = os.read(self.input_fd, io.DEFAULT_BUFFER_SIZE)
except BlockingIOError:
return
if not data:
raise EOFError('The input stream is closed')
data = self.decoder.decode(data)

View File

@@ -1255,8 +1255,16 @@ PyTypeObject ChildMonitor_Type = {
.tp_new = new,
};
static PyObject*
safe_pipe(PyObject *self UNUSED) {
int fds[2] = {0};
if (!self_pipe(fds)) return PyErr_SetFromErrno(PyExc_OSError);
return Py_BuildValue("ii", fds[0], fds[1]);
}
static PyMethodDef module_methods[] = {
METHOD(simple_render_screen, METH_VARARGS)
METHODB(safe_pipe, METH_NOARGS),
{NULL} /* Sentinel */
};