mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-02 10:52:22 +00:00
Shorten Escape key delay in OCI dialog menus
This commit is contained in:
@@ -38,5 +38,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
python3 -m unittest discover -s oci/tests -p test_modify_latency.py -v
|
python3 -m unittest discover -s oci/tests -p test_modify_latency.py -v
|
||||||
python3 -m unittest discover -s oci/tests -p test_menu_performance.py -v
|
python3 -m unittest discover -s oci/tests -p test_menu_performance.py -v
|
||||||
|
python3 -m unittest discover -s oci/tests -p test_dialog_escape.py -v
|
||||||
python3 -m unittest discover -s oci/tests -p test_work_backup.py -v
|
python3 -m unittest discover -s oci/tests -p test_work_backup.py -v
|
||||||
python3 -m unittest discover -s oci/tests -p test_recreation.py -v
|
python3 -m unittest discover -s oci/tests -p test_recreation.py -v
|
||||||
|
|||||||
@@ -221,6 +221,10 @@ class DialogUI:
|
|||||||
|
|
||||||
def _run(self, widget: list[str], title: str | None = None) -> subprocess.CompletedProcess[str]:
|
def _run(self, widget: list[str], title: str | None = None) -> subprocess.CompletedProcess[str]:
|
||||||
environment = os.environ.copy()
|
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"}:
|
if environment.get("TERM", "").casefold() in {"", "dumb", "unknown"}:
|
||||||
environment["TERM"] = "xterm-256color"
|
environment["TERM"] = "xterm-256color"
|
||||||
# dialog draws on the terminal and writes the selection to stderr.
|
# 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