Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 113 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ edition = "2024"
[dependencies]
crossterm = "0.29"
lsp-types = "0.97"
portable-pty = "0.9.0"
ratatui = "0.30.2"
ratatui-code-editor = { version = "0.0.6", features = ["crossterm"] }
serde_json = "1.0.151"
unicode-width = "0.2"
vt100 = "0.16.2"
17 changes: 17 additions & 0 deletions doc/shortcuts/shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,20 @@
* **Search forward / backward**: `Ctrl + S` / `Ctrl + R`. (`Enter` to stop, `Ctrl + G` to go back.)
* **Query replace**: `Alt + %`. Then answer at each match: `Y`/`Space` replace, `N` skip, `!` replace all, `.` replace and stop, `Q` stop.
* **Go to line**: `Alt + G` `G` (or `Alt + G` `Alt + G`).

## Terminal

* `Ctrl + C` `T` `T`: open or hide the terminal. Hiding it keeps the shell running.
* `Ctrl + X` `O`: switch focus between the editor and the visible terminal.
* `Ctrl + C` `T` `C`: run Clang-tidy.
* `Alt + V` / `Ctrl + V`: scroll terminal history up / down one page.
`Shift + PageUp` / `Shift + PageDown` also work. Up to 1000 history rows are kept.
These shortcuts apply while the terminal has focus; typing returns to the latest output.
In alternate-screen programs, these keys go to the program instead.
* Shell keys, including Ctrl-C and Ctrl-D, go to the terminal while it has focus.
Switch back with `Ctrl + X` `O` before using editor commands.

The terminal opens below the editor when the workspace has at least 28 rows;
otherwise it opens on the right. It starts in the current file's directory,
or the editor's working directory for an unnamed file. After the shell exits,
hide and reopen the terminal to start a new session.
16 changes: 16 additions & 0 deletions doc/shortcuts/shortcuts.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,19 @@
* **向前 / 向后查找**: `Ctrl + S` / `Ctrl + R`. (`Enter`结束,`Ctrl + G`回到起点)
* **逐个替换**: `Alt + %`. (`Y`/`空格`替换,`N`跳过,`!`全部替换,`.`替换后结束,`Q`结束)
* **跳转到行**: `Alt + G` `G` (或`Alt + G` `Alt + G`).

## 终端

* `Ctrl + C` `T` `T`:打开或隐藏终端。隐藏后 Shell 继续运行。
* `Ctrl + X` `O`:在编辑器和已显示的终端之间切换焦点。
* `Ctrl + C` `T` `C`:运行 Clang-tidy。
* `Alt + V` / `Ctrl + V`:向上 / 向下翻阅终端历史输出。
也支持 `Shift + PageUp` / `Shift + PageDown`,最多保留 1000 行历史。
这些快捷键在终端获得焦点时生效;输入时自动回到最新输出。
程序使用备用屏幕时,这些按键仍传给程序。
* 终端获得焦点时,Ctrl-C、Ctrl-D 等按键会传给 Shell。
使用编辑器命令前,请按 `Ctrl + X` `O` 切回编辑器。

工作区高度不少于 28 行时,终端显示在编辑器下方;否则显示在右侧。
Shell 在当前文件的目录启动;未命名文件则使用编辑器的工作目录。
Shell 退出后,隐藏并重新打开终端即可启动新会话。
14 changes: 11 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ use std::{
#[derive(Default)]
pub(crate) struct App {
pub(crate) buffer: Buffer,
pub(crate) terminal: crate::buffers::terminal::Terminal,
pub(crate) menu: crate::buffers::menu::Menu,
pub(crate) editor_area: Rect,
exit_flag: bool,
ctrl_x_wait_flag: bool,
pub(crate) ctrl_x_wait_flag: bool,
pub(crate) ctrl_c_wait_flag: bool,
// Set after C-c t, which starts terminal and tool commands.
pub(crate) ctrl_c_t_wait_flag: bool,
kill_ring: Option<String>,
pub(crate) overwrite_confirm: bool,
pub(crate) save_path_input: Option<String>,
Expand Down Expand Up @@ -62,7 +65,8 @@ impl App {

// Talk to the language server, then draw a new frame.
self.sync_lsp();
if !self.ctrl_x_wait_flag && !self.ctrl_c_wait_flag {
self.terminal.poll();
if !self.ctrl_x_wait_flag && !self.ctrl_c_wait_flag && !self.ctrl_c_t_wait_flag {
self.poll_cpp_check();
}

Expand All @@ -71,7 +75,8 @@ impl App {
// Wait for event; ignore key release to avoid handling a keystroke twice.
// Wake up sooner while a completion answer is expected.
let mut timeout = interval.saturating_sub(last_disk_check.elapsed());
if self.completion.is_waiting() || self.quick_fix.is_waiting() {
if self.terminal.visible || self.completion.is_waiting() || self.quick_fix.is_waiting()
{
timeout = timeout.min(Duration::from_millis(20));
}
if event::poll(timeout)?
Expand All @@ -87,6 +92,9 @@ impl App {
}

pub(crate) fn handle_key(&mut self, key: KeyEvent) {
if self.handle_terminal_key(key) {
return;
}
// Print key in buffer command section in bottom tool bar.
let prefix = match (self.ctrl_x_wait_flag, self.ctrl_c_wait_flag) {
(true, _) => "C-x ",
Expand Down
3 changes: 2 additions & 1 deletion src/buffers/completion/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ impl App {
use crate::buffers::cpp_checks::Tool;
match key.code {
KeyCode::Char('l') => self.run_cpp_check(Tool::Cpplint),
KeyCode::Char('t') => self.run_cpp_check(Tool::Tidy),
// C-c t is a prefix; handle_terminal_key reads the next key.
KeyCode::Char('t') => self.ctrl_c_t_wait_flag = true,
KeyCode::Char('a') => self.request_fix(),
_ => {}
}
Expand Down
3 changes: 3 additions & 0 deletions src/buffers/cpp_checks/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ fn cpp_only_toggles_and_shortcuts_do_not_edit() {
for key in ['t', 'l'] {
app.handle_key(KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL));
press(&mut app, KeyCode::Char(key));
if key == 't' {
press(&mut app, KeyCode::Char('c'));
}
assert!(app.status_bar_text.contains("disabled"));
}
assert_eq!(app.buffer.editor.get_content(), before);
Expand Down
2 changes: 1 addition & 1 deletion src/buffers/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn cpp_entries(settings: &Settings) -> Vec<(&'static str, &'static str, CppActio
];

if settings.tidy {
entries.push(("Run Clang-tidy", "C-c t", CppAction::Run(Tool::Tidy)));
entries.push(("Run Clang-tidy", "C-c t c", CppAction::Run(Tool::Tidy)));
}

if settings.cpplint_ready() {
Expand Down
1 change: 1 addition & 0 deletions src/buffers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ pub(crate) mod goto_line;
pub(crate) mod menu;
mod render;
pub(crate) mod search;
pub(crate) mod terminal;
Loading
Loading