mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Use ctermid() instead of hardcoding /dev/tty
This commit is contained in:
3
glfw/wl_window.c
vendored
3
glfw/wl_window.c
vendored
@@ -1057,7 +1057,8 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|||||||
int _glfwPlatformWindowBell(_GLFWwindow* window)
|
int _glfwPlatformWindowBell(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
// TODO: Use an actual Wayland API to implement this when one becomes available
|
// TODO: Use an actual Wayland API to implement this when one becomes available
|
||||||
int fd = open("/dev/tty", O_WRONLY | O_CLOEXEC);
|
static char tty[L_ctermid + 1];
|
||||||
|
int fd = open(ctermid(tty), O_WRONLY | O_CLOEXEC);
|
||||||
if (fd > -1) {
|
if (fd > -1) {
|
||||||
int ret = write(fd, "\x07", 1) == 1 ? GLFW_TRUE : GLFW_FALSE;
|
int ret = write(fd, "\x07", 1) == 1 ? GLFW_TRUE : GLFW_FALSE;
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from kitty.cli import parse_args
|
from kitty.cli import parse_args
|
||||||
|
|
||||||
from ..tui.handler import Handler
|
from ..tui.handler import Handler
|
||||||
@@ -62,7 +64,7 @@ def main(args):
|
|||||||
data = None
|
data = None
|
||||||
if not sys.stdin.isatty():
|
if not sys.stdin.isatty():
|
||||||
data = sys.stdin.buffer.read()
|
data = sys.stdin.buffer.read()
|
||||||
sys.stdin = open('/dev/tty', 'r')
|
sys.stdin = open(os.ctermid(), 'r')
|
||||||
loop = Loop()
|
loop = Loop()
|
||||||
handler = Clipboard(data, args)
|
handler = Clipboard(data, args)
|
||||||
loop.loop(handler)
|
loop.loop(handler)
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ def main(args):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
text = sys.stdin.buffer.read().decode('utf-8')
|
text = sys.stdin.buffer.read().decode('utf-8')
|
||||||
sys.stdin = open('/dev/tty')
|
sys.stdin = open(os.ctermid())
|
||||||
try:
|
try:
|
||||||
args, items = parse_hints_args(args[1:])
|
args, items = parse_hints_args(args[1:])
|
||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
|
|||||||
@@ -260,13 +260,13 @@ def main(args=sys.argv):
|
|||||||
|
|
||||||
if args.print_window_size:
|
if args.print_window_size:
|
||||||
screen_size_function.ans = None
|
screen_size_function.ans = None
|
||||||
with open('/dev/tty') as tty:
|
with open(os.ctermid()) as tty:
|
||||||
ss = screen_size_function(tty)()
|
ss = screen_size_function(tty)()
|
||||||
print('{}x{}'.format(ss.width, ss.height), end='')
|
print('{}x{}'.format(ss.width, ss.height), end='')
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
||||||
if not sys.stdout.isatty():
|
if not sys.stdout.isatty():
|
||||||
sys.stdout = open('/dev/tty', 'w')
|
sys.stdout = open(os.ctermid(), 'w')
|
||||||
screen_size = screen_size_function()
|
screen_size = screen_size_function()
|
||||||
signal.signal(signal.SIGWINCH, lambda signum, frame: setattr(screen_size, 'changed', True))
|
signal.signal(signal.SIGWINCH, lambda signum, frame: setattr(screen_size, 'changed', True))
|
||||||
if screen_size().width == 0:
|
if screen_size().width == 0:
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from kitty.cli import parse_args
|
from kitty.cli import parse_args
|
||||||
from ..tui.operations import styled
|
|
||||||
|
|
||||||
|
from ..tui.operations import styled
|
||||||
|
|
||||||
OPTIONS = '''\
|
OPTIONS = '''\
|
||||||
--title
|
--title
|
||||||
@@ -17,7 +18,7 @@ The title for the error message.
|
|||||||
|
|
||||||
def real_main(args):
|
def real_main(args):
|
||||||
error_message = sys.stdin.buffer.read().decode('utf-8')
|
error_message = sys.stdin.buffer.read().decode('utf-8')
|
||||||
sys.stdin = open('/dev/tty')
|
sys.stdin = open(os.ctermid())
|
||||||
msg = 'Show an error message'
|
msg = 'Show an error message'
|
||||||
args, items = parse_args(args, OPTIONS, '', msg, 'hints')
|
args, items = parse_args(args, OPTIONS, '', msg, 'hints')
|
||||||
print(styled(args.title, fg_intense=True, fg='red', bold=True))
|
print(styled(args.title, fg_intense=True, fg='red', bold=True))
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
#ifdef WITH_PROFILER
|
#ifdef WITH_PROFILER
|
||||||
#include <gperftools/profiler.h>
|
#include <gperftools/profiler.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -123,7 +124,8 @@ open_tty(PyObject *self UNUSED, PyObject *args) {
|
|||||||
if (!PyArg_ParseTuple(args, "|p", &read_with_timeout)) return NULL;
|
if (!PyArg_ParseTuple(args, "|p", &read_with_timeout)) return NULL;
|
||||||
int flags = O_RDWR | O_CLOEXEC | O_NOCTTY;
|
int flags = O_RDWR | O_CLOEXEC | O_NOCTTY;
|
||||||
if (!read_with_timeout) flags |= O_NONBLOCK;
|
if (!read_with_timeout) flags |= O_NONBLOCK;
|
||||||
int fd = open("/dev/tty", flags);
|
static char ctty[L_ctermid+1];
|
||||||
|
int fd = open(ctermid(ctty), flags);
|
||||||
struct termios *termios_p = calloc(1, sizeof(struct termios));
|
struct termios *termios_p = calloc(1, sizeof(struct termios));
|
||||||
if (!termios_p) return PyErr_NoMemory();
|
if (!termios_p) return PyErr_NoMemory();
|
||||||
if (tcgetattr(fd, termios_p) != 0) { free(termios_p); PyErr_SetFromErrno(PyExc_OSError); return NULL; }
|
if (tcgetattr(fd, termios_p) != 0) { free(termios_p); PyErr_SetFromErrno(PyExc_OSError); return NULL; }
|
||||||
|
|||||||
Reference in New Issue
Block a user