mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-01 10:22:08 +00:00
Shorten Escape key delay in OCI dialog menus
This commit is contained in:
@@ -221,6 +221,10 @@ class DialogUI:
|
||||
|
||||
def _run(self, widget: list[str], title: str | None = None) -> subprocess.CompletedProcess[str]:
|
||||
environment = os.environ.copy()
|
||||
# ncurses otherwise waits a full second to distinguish Escape from
|
||||
# the prefix of a cursor/function key. Keep a short sequence window,
|
||||
# while respecting an explicit terminal-specific setting.
|
||||
environment.setdefault("ESCDELAY", "150")
|
||||
if environment.get("TERM", "").casefold() in {"", "dumb", "unknown"}:
|
||||
environment["TERM"] = "xterm-256color"
|
||||
# dialog draws on the terminal and writes the selection to stderr.
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
"""Escape delay is scoped to dialog and preserves terminal-specific overrides."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'src'))
|
||||
from proxmenux_oci.ui import DialogUI, UserCancelled
|
||||
|
||||
|
||||
class DialogEscapeTests(unittest.TestCase):
|
||||
def test_escape_uses_short_delay_without_changing_parent_environment(self):
|
||||
with patch.dict(os.environ, {'TERM': 'xterm'}, clear=True), \
|
||||
patch('proxmenux_oci.ui.subprocess.run', return_value=subprocess.CompletedProcess([], 255, stderr='')) as run:
|
||||
self.assertIsNone(DialogUI().choose('Menu', [('1', 'First')]))
|
||||
self.assertEqual(run.call_args.kwargs['env']['ESCDELAY'], '150')
|
||||
self.assertNotIn('ESCDELAY', os.environ)
|
||||
|
||||
def test_explicit_delay_is_preserved(self):
|
||||
with patch.dict(os.environ, {'ESCDELAY': '900'}), \
|
||||
patch('proxmenux_oci.ui.subprocess.run', return_value=subprocess.CompletedProcess([], 0, stderr='1')) as run:
|
||||
self.assertEqual(DialogUI().choose('Menu', [('1', 'First')]), '1')
|
||||
self.assertEqual(run.call_args.kwargs['env']['ESCDELAY'], '900')
|
||||
|
||||
def test_escape_in_search_input_keeps_cancellation_behavior(self):
|
||||
with patch('proxmenux_oci.ui.subprocess.run', return_value=subprocess.CompletedProcess([], 255, stderr='')):
|
||||
with self.assertRaises(UserCancelled):
|
||||
DialogUI().ask('Search')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user