Skip to content

Commit 994c2a1

Browse files
authored
feat:support osc52 sequence for ssh/tty (#8)
* Trying out osc 52 fallback * Better print * Bump version
1 parent 5df78fd commit 994c2a1

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "glimpse"
3-
version = "0.6.9"
3+
version = "0.6.10"
44
edition = "2021"
55
description = "A blazingly fast tool for peeking at codebases. Perfect for loading your codebase into an LLM's context."
66
license = "MIT"
@@ -9,6 +9,7 @@ build = "build.rs"
99
[dependencies]
1010
anyhow = "1.0.95"
1111
arboard = { version = "3.4.1", features = ["wayland-data-control"] }
12+
base64 = "0.22.1"
1213
clap = { version = "4.5.23", features = ["derive"] }
1314
colored = "2.2.0"
1415
crossterm = "0.28.1"

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
{
1919
packages.default = pkgs.rustPlatform.buildRustPackage {
2020
pname = "glimpse";
21-
version = "0.6.9";
22-
21+
version = "0.6.10";
22+
2323
src = ./.;
2424

2525
cargoLock = {

src/output.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{cli::Cli, tokenizer::TokenCounter};
22
use anyhow::Result;
3+
use base64::Engine;
34
use std::{fs, path::PathBuf};
45

56
#[derive(Debug, Clone)]
@@ -121,6 +122,15 @@ fn generate_files(entries: &[FileEntry]) -> Result<String> {
121122
Ok(output)
122123
}
123124

125+
fn try_copy_with_osc52(content: &str) -> Result<(), Box<dyn std::error::Error>> {
126+
// OSC 52 sequence to set clipboard for special cases (like SSH)
127+
print!(
128+
"\x1B]52;c;{}\x07",
129+
base64::engine::general_purpose::STANDARD.encode(content)
130+
);
131+
Ok(())
132+
}
133+
124134
pub fn handle_output(content: String, args: &Cli) -> Result<()> {
125135
// Print to stdout if no other output method is specified
126136
if args.print {
@@ -131,7 +141,12 @@ pub fn handle_output(content: String, args: &Cli) -> Result<()> {
131141
if !args.print {
132142
match arboard::Clipboard::new().and_then(|mut clipboard| clipboard.set_text(content.clone())) {
133143
Ok(_) => println!("Context prepared! Paste into your LLM of choice + Profit."),
134-
Err(e) => eprintln!("Warning: Failed to copy to clipboard: {}. Output will continue with other specified formats.", e),
144+
Err(_) => {
145+
match try_copy_with_osc52(&content) {
146+
Ok(_) => println!("Context prepared! (using terminal clipboard) Paste into your LLM of choice + Profit."),
147+
Err(e) => eprintln!("Warning: Failed to copy to clipboard: {}. Output will continue with other specified formats.", e)
148+
}
149+
},
135150
}
136151
}
137152

0 commit comments

Comments
 (0)