mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-08-17 18:40:54 +03:00
DRYer
This commit is contained in:
parent
d51a424b98
commit
683e5a4754
@ -18,16 +18,19 @@
|
||||
from queue import Empty, Queue
|
||||
|
||||
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,
|
||||
decode_key_event, enter_key
|
||||
)
|
||||
from kitty.utils import screen_size_function
|
||||
|
||||
from .handler import Handler
|
||||
from .operations import clear_screen, init_state, reset_state
|
||||
|
||||
|
||||
screen_size = screen_size_function()
|
||||
|
||||
|
||||
def debug(*a, **kw):
|
||||
fd = getattr(debug, 'fd', None)
|
||||
if fd is None:
|
||||
|
@ -293,8 +293,8 @@ def wrap(text, limit=80):
|
||||
|
||||
|
||||
def print_help_for_seq(seq, usage, message, appname):
|
||||
from kitty.icat import screen_size
|
||||
screen_size.changed = True
|
||||
from kitty.utils import screen_size_function
|
||||
screen_size = screen_size_function()
|
||||
try:
|
||||
linesz = min(screen_size().cols, 76)
|
||||
except EnvironmentError:
|
||||
|
@ -2,16 +2,13 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import array
|
||||
import codecs
|
||||
import fcntl
|
||||
import mimetypes
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import termios
|
||||
import zlib
|
||||
from base64 import standard_b64encode
|
||||
from collections import namedtuple
|
||||
@ -20,8 +17,9 @@
|
||||
|
||||
from kitty.cli import parse_args
|
||||
from kitty.constants import appname
|
||||
from kitty.utils import read_with_timeout
|
||||
from kitty.utils import read_with_timeout, screen_size_function
|
||||
|
||||
screen_size = screen_size_function()
|
||||
try:
|
||||
fsenc = sys.getfilesystemencoding() or 'utf-8'
|
||||
codecs.lookup(fsenc)
|
||||
@ -100,21 +98,6 @@ def options_spec():
|
||||
return options_spec.ans
|
||||
|
||||
|
||||
Size = namedtuple('Size', 'rows cols width height')
|
||||
|
||||
|
||||
def screen_size():
|
||||
if screen_size.changed:
|
||||
buf = array.array('H', [0, 0, 0, 0])
|
||||
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
|
||||
screen_size.ans = Size(*buf)
|
||||
screen_size.changed = False
|
||||
return screen_size.ans
|
||||
|
||||
|
||||
screen_size.changed = True
|
||||
|
||||
|
||||
def write_gr_cmd(cmd, payload=None):
|
||||
cmd = ','.join('{}={}'.format(k, v) for k, v in cmd.items())
|
||||
w = sys.stdout.buffer.write
|
||||
|
@ -76,6 +76,25 @@ def parse_color_set(raw):
|
||||
continue
|
||||
|
||||
|
||||
def screen_size_function():
|
||||
from collections import namedtuple
|
||||
import array
|
||||
import fcntl
|
||||
import termios
|
||||
Size = namedtuple('Size', 'rows cols width height')
|
||||
|
||||
def screen_size():
|
||||
if screen_size.changed:
|
||||
buf = array.array('H', [0, 0, 0, 0])
|
||||
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
|
||||
screen_size.ans = Size(*buf)
|
||||
screen_size.changed = False
|
||||
return screen_size.ans
|
||||
screen_size.changed = True
|
||||
|
||||
return screen_size
|
||||
|
||||
|
||||
def set_primary_selection(text):
|
||||
if is_macos or is_wayland:
|
||||
return # There is no primary selection
|
||||
|
Loading…
Reference in New Issue
Block a user