Skip to content

Commit 14ae792

Browse files
committed
✨ allow copy contents in console
1 parent fdd2cff commit 14ae792

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

nb_cli/locale/zh_CN/LC_MESSAGES/nb-cli.po

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: nb-cli 1.0.0\n"
99
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10-
"POT-Creation-Date: 2025-10-07 16:38+0000\n"
10+
"POT-Creation-Date: 2025-10-07 17:05+0000\n"
1111
"PO-Revision-Date: 2023-01-11 08:56+0000\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language: zh_Hans_CN\n"
@@ -967,32 +967,36 @@ msgstr "成功安装 \"{name}\"."
967967
msgid "Initializing..."
968968
msgstr "初始化中..."
969969

970-
#: nb_cli/tui/console.py:20
970+
#: nb_cli/tui/console.py:22
971971
msgid "Close"
972972
msgstr "关闭"
973973

974-
#: nb_cli/tui/console.py:21
974+
#: nb_cli/tui/console.py:23
975975
msgid "Clear output"
976976
msgstr "清空输出"
977977

978-
#: nb_cli/tui/console.py:22
978+
#: nb_cli/tui/console.py:24
979979
msgid "Cancel process"
980980
msgstr "取消进程"
981981

982-
#: nb_cli/tui/console.py:23
982+
#: nb_cli/tui/console.py:25
983983
msgid "Terminate process"
984984
msgstr "终止进程"
985985

986-
#: nb_cli/tui/console.py:25
986+
#: nb_cli/tui/console.py:26
987+
msgid "Copy content"
988+
msgstr "复制内容"
989+
990+
#: nb_cli/tui/console.py:28
987991
msgid "Console output"
988992
msgstr "控制台输出"
989993

990-
#: nb_cli/tui/console.py:61
994+
#: nb_cli/tui/console.py:64
991995
#, python-brace-format
992996
msgid "Process exited (code: {code}). Press ESC / q / Ctrl+C to close."
993997
msgstr "进程已退出 (状态码: {code}). 按 ESC / q / Ctrl+C 关闭."
994998

995-
#: nb_cli/tui/console.py:73
999+
#: nb_cli/tui/console.py:76
9961000
msgid "Cannot leave current console until the process is done or terminated."
9971001
msgstr "进程结束或终止前无法离开当前控制台."
9981002

nb_cli/tui/console.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from typing import Final, Optional
44
from asyncio.subprocess import Process
55

6+
import rich
7+
import rich.text
68
from textual.reactive import var
79
from textual.app import ComposeResult
810
from textual.screen import ModalScreen
@@ -21,6 +23,7 @@ class LogConsole(ModalScreen):
2123
("ctrl+l", "clear_output", _("Clear output")),
2224
("ctrl+c", "cancel_proc", _("Cancel process")),
2325
("ctrl+k", "terminate_proc", _("Terminate process")),
26+
("ctrl+n", "copy", _("Copy content")),
2427
]
2528
SUB_TITLE = _("Console output")
2629

@@ -89,6 +92,13 @@ async def action_clear_output(self):
8992
log = self.query_one(Log)
9093
log.clear()
9194

95+
async def action_copy(self):
96+
log = self.query_one(Log)
97+
# works on terminals that supports OSC 52.
98+
self.app.copy_to_clipboard(
99+
"\n".join(rich.text.Text.from_ansi(line).plain for line in log.lines)
100+
)
101+
92102
def check_action(
93103
self, action: str, parameters: tuple[object, ...]
94104
) -> Optional[bool]:

0 commit comments

Comments
 (0)