Skip to content
Draft
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ impl FileScratchpadContextManager {
}

fn load_file(&self, path: &Path) -> String {
fs::read_to_string(&path).unwrap_or_default()
fs::read_to_string(path).unwrap_or_default()
}

fn resolve_path(&self, base_path: &Path, session_id: Option<Uuid>) -> PathBuf {
if let Some(session_id) = session_id {
if let Some(parent) = base_path.parent() {
// If there's a session ID, put files in a subdirectory named after the session ID
// e.g. .stakpak/session/scratchpad.md -> .stakpak/session/<uuid>/scratchpad.md
let session_dir = parent.join(session_id.to_string());
return session_dir.join(base_path.file_name().unwrap_or_default());
}
if let Some(session_id) = session_id
&& let Some(parent) = base_path.parent()
{
// If there's a session ID, put files in a subdirectory named after the session ID
// e.g. .stakpak/session/scratchpad.md -> .stakpak/session/<uuid>/scratchpad.md
let session_dir = parent.join(session_id.to_string());
return session_dir.join(base_path.file_name().unwrap_or_default());
}
base_path.to_path_buf()
}
Expand Down Expand Up @@ -197,17 +197,16 @@ impl FileScratchpadContextManager {
if let (Some(old_str), Some(new_str)) = (
args.get("old_str").and_then(|s| s.as_str()),
args.get("new_str").and_then(|s| s.as_str()),
) {
if let Some(content) = current_content {
let replace_all = args
.get("replace_all")
.and_then(|b| b.as_bool())
.unwrap_or(false);
if replace_all {
*content = content.replace(old_str, new_str);
} else {
*content = content.replacen(old_str, new_str, 1);
}
) && let Some(content) = current_content
{
let replace_all = args
.get("replace_all")
.and_then(|b| b.as_bool())
.unwrap_or(false);
if replace_all {
*content = content.replace(old_str, new_str);
} else {
*content = content.replacen(old_str, new_str, 1);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion tui/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ pub fn map_crossterm_event_to_input_event(event: Event) -> Option<InputEvent> {
Some(InputEvent::InputBackspace)
}
}
KeyCode::Enter => Some(InputEvent::InputSubmitted),
KeyCode::Enter => {
if key.modifiers.contains(KeyModifiers::SHIFT) {
Some(InputEvent::InputChangedNewline)
} else {
Some(InputEvent::InputSubmitted)
}
}
KeyCode::Esc => Some(InputEvent::HandleEsc),
KeyCode::Up => Some(InputEvent::Up),
KeyCode::Down => Some(InputEvent::Down),
Expand Down
18 changes: 16 additions & 2 deletions tui/src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::services::message::Message;
use crate::view::view;
use crossterm::event::{
DisableBracketedPaste, DisableMouseCapture, EnableBracketedPaste, EnableMouseCapture,
KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
};
use crossterm::{execute, terminal::EnterAlternateScreen};
use ratatui::{Terminal, backend::CrosstermBackend};
Expand Down Expand Up @@ -61,7 +62,17 @@ pub async fn run_tui(
execute!(
std::io::stdout(),
EnterAlternateScreen,
EnableBracketedPaste
EnableBracketedPaste,
)?;

#[cfg(unix)]
execute!(
std::io::stdout(),
PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_EVENT_TYPES
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
)
)?;

#[cfg(unix)]
Expand Down Expand Up @@ -276,8 +287,11 @@ pub async fn run_tui(
std::io::stdout(),
crossterm::terminal::LeaveAlternateScreen,
DisableBracketedPaste,
DisableMouseCapture
DisableMouseCapture,
)?;

#[cfg(unix)]
execute!(std::io::stdout(), PopKeyboardEnhancementFlags)?;
Ok(())
}

Expand Down
9 changes: 7 additions & 2 deletions tui/src/services/hint_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,13 @@ pub fn render_hint_or_shortcuts(f: &mut Frame, state: &AppState, area: Rect) {
// detect if terminal is vscode
let terminal_info = detect_terminal();
let terminal_name = terminal_info.emulator;
let is_iterm2 = terminal_name == "iTerm2";
let new_line_hint = if !is_iterm2 { "ctrl+j" } else { "shift+enter" };
let is_terminal_app_or_vscode =
terminal_name == "VS Code Terminal" || terminal_name == "Terminal.app";
let new_line_hint = if is_terminal_app_or_vscode {
"ctrl+j"
} else {
"shift+enter"
};
let hint = Paragraph::new(Span::styled(
format!(
"{} new line | {} | ctrl+o toggle auto-approve",
Expand Down