Skip to content

Support QR code for session links (#158) - #159

Open
Ian729 wants to merge 1 commit into
ekzhang:mainfrom
Ian729:support-qr-code
Open

Ian729 wants to merge 1 commit into
ekzhang:mainfrom
Ian729:support-qr-code

Conversation

@Ian729

@Ian729 Ian729 commented Oct 12, 2026

Copy link
Copy Markdown

Summary

Closes #158.

This PR adds an optional --qr CLI flag to sshx that renders an ASCII/ANSI QR code for the session link directly in the terminal output.

Motivation

  • Headless / Remote Machines: When running sshx on a remote server, cloud instance, or Raspberry Pi via SSH, copying the long URL containing the high-entropy encryption key to a mobile device is cumbersome without shared clipboards.
  • Fast In-Person Sharing: In a workshop, presentation, or co-located pair programming session, collaborators can simply scan the screen with their phone camera to instantly join the session.

Implementation Details

  • Lightweight Dependency: Uses the qrcode crate with default-features = false to avoid pulling in the heavy image crate (and image decoders/encoders). Keeps compile times fast and binary size small without introducing any non-Rust C dependencies.
  • Compact Unicode Half-Block Rendering: Utilizes Dense1x2 (half-block characters ▀ and ▄) to pack two vertical pixels per character line. This keeps the height under 20 lines (typically 19 lines tall for standard session URLs), ensuring the QR code fits cleanly within standard 80x24 terminal windows without wrapping or truncation.
  • Cross-Theme High-Contrast ANSI Colors: Explicitly applies White foreground on Black background to ensure the QR code has a solid white quiet zone and black modules regardless of whether the user is running a dark, light, or custom terminal theme.
  • Security & Read-Only Separation:
    • If --enable-readers is active, --qr defaults to rendering the Read-only link for security against accidental write-access exposure.
    • An additional --qr-write flag is provided to render the writable link's QR code when needed.
  • Quiet Mode Consistency: In -q / --quiet mode, QR code output is suppressed, preserving script pipeability (URL=$(sshx -q)).

Verification

  • Added unit tests in crates/sshx/src/qr.rs testing standard, long, and read/write URLs.
  • Ran full workspace tests (cargo test --workspace) and clippy (cargo clippy -p sshx --all-targets).
  • Formatted with cargo fmt adhering to rustfmt.toml.
  • Tested end-to-end against local sshx-server verifying phone scanner compatibility.

- Add `--qr` CLI flag to print an ASCII/ANSI QR code for the session link
- Add `--qr-write` flag to print QR code for the writable link when `--enable-readers` is active
- Use Unicode half-block characters (`Dense1x2`) for a compact representation (<20 lines) that fits standard terminals
- Use explicit black-on-white ANSI styling for maximum contrast across dark and light terminal color themes
- Add unit tests for QR rendering in `crates/sshx/src/qr.rs`
@Ian729

Ian729 commented Oct 13, 2026

Copy link
Copy Markdown
Author

Hi @ekzhang, I've implemented the --qr feature for #158. All workspace CI checks are passing green. Whenever you have some free time, feedback or review is warmly welcomed! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support QR code for session links

1 participant