Skip to content

交互式模式方向键无法正常使用 #223

@yueweicode

Description

@yueweicode

System Info / 系統信息

在使用交互式模式 ( python main.py ) 时,方向键(←/→/↑/↓)无法正常用于光标导航或历史记录浏览。

Who can help? / 谁可以帮助到您?

No response

Information / 问题信息

  • The official example scripts / 官方的示例脚本
  • My own modified scripts / 我自己修改的脚本和任务

Reproduction / 复现过程

复现步骤

  1. 运行 python main.py
  2. 进入交互式模式
  3. 尝试使用方向键进行导航或浏览历史记录
  4. 观察到方向键会产生转义序列(如 ^[[C^[[D )而不是预期的行为

根本原因
默认的 Python input() 函数缺少 readline 支持,而 readline 是实现终端输入处理功能(如方向键导航)所必需的

解决方案
在 main.py 文件开头添加 readline 模块支持:
try: import readline except ImportError: pass

Expected behavior / 期待表现

已修复

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions