FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(forge_select): enter alternate screen to keep prompt visible by amitksingh1490 · Pull Request #3492 · tailcallhq/forgecode · GitHub

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

Filter by extension

Filter by extension .rs  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 4 additions & 3 deletions crates/forge_main/src/ui.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3251,9 +3251,10 @@ impl<A: API + ConsoleWriter + 'static, F: Fn(ForgeConfig) -> A + Send + Sync> UI
server.wait_for_code().await?
} else {
// Prompt user to paste authorization code
let code = ForgeWidget::input("Paste the authorization code")
.prompt()?
.ok_or_else(|| anyhow::anyhow!("Authorization code input cancelled"))?;
let code =
ForgeWidget::input(format!("Paste the authorization code for {provider_id}"))
.prompt()?
.ok_or_else(|| anyhow::anyhow!("Authorization code input cancelled"))?;

if code.trim().is_empty() {
anyhow::bail!("Authorization code cannot be empty");
Expand Down
29 changes: 28 additions & 1 deletion crates/forge_select/src/input.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::io::IsTerminal;
use std::io::{self, IsTerminal};

use anyhow::Result;
use colored::Colorize;
use crossterm::execute;
use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen};
use rustyline::DefaultEditor;
use tracing::debug;

Expand Down Expand Up @@ -63,6 +65,13 @@ impl InputBuilder {
return Ok(None);
}

// Enter the alternate screen so that the prompt is always visible and
// cannot be scrolled out of the viewport. This fixes an issue in
// terminals like VS Code (xterm.js) where rustyline's per-keystroke
// redraw causes the viewport to jump back to the cursor position,
// scrolling the prompt out of view.
let _guard = AlternateScreenGuard::enter();

let mut rl = DefaultEditor::new()?;

// On Windows, rustyline miscounts ANSI escape bytes as visible characters,
Expand Down Expand Up @@ -103,6 +112,24 @@ impl InputBuilder {
}
}

/// Guard that enters the terminal alternate screen on creation and exits it on
/// drop. Failures are silently ignored — the alternate screen is a cosmetic
/// best-effort fix for terminal viewport issues.
struct AlternateScreenGuard;

impl AlternateScreenGuard {
fn enter() -> Option<Self> {
execute!(io::stdout(), EnterAlternateScreen).ok()?;
Some(Self)
}
}

impl Drop for AlternateScreenGuard {
fn drop(&mut self) {
let _ = execute!(io::stdout(), LeaveAlternateScreen);
}
}

#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
Expand Down
Loading

Back | FazBrowse Home | New Git URL