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
19 changes: 19 additions & 0 deletions crates/pidgin-napi/schema/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,25 @@
"name": "parseGitUrl"
}
}
},
{
"name": "stripAnsi",
"doc": "`stripAnsi` (utils/ansi.ts): remove ANSI escape sequences (OSC + CSI). The\nshim keeps pi's non-string `TypeError` guard, so only strings reach here.",
"shape": "unary",
"infallible": true,
"readonly": true,
"params": [
{
"name": "value",
"type": "string"
}
],
"returns": "string",
"bindings": {
"node": {
"name": "stripAnsi"
}
}
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions crates/pidgin-napi/src/core_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ impl crate::generated::PidginCore for PidginImpl {
obj.insert("pinned".to_string(), serde_json::json!(parsed.pinned));
Some(serde_json::Value::Object(obj).to_string())
}

fn strip_ansi(value: String) -> String {
pidgin_coding::utils::ansi::strip_ansi(&value)
}
}

// --- tui keybindings layer (packages/tui/src/keybindings.ts) ----------------
Expand Down
8 changes: 8 additions & 0 deletions crates/pidgin-napi/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub trait PidginCore: Sized + Send + Sync + 'static {
fn find_word_backward(text: String, cursor: i32) -> i32;
fn find_word_forward(text: String, cursor: i32) -> i32;
fn parse_git_url(source: String) -> Option<String>;
fn strip_ansi(value: String) -> String;
}

/// The `KeybindingsManagerCore` contract — implement over the engine in `crate::core_impl`.
Expand Down Expand Up @@ -264,6 +265,13 @@ pub fn parse_git_url(source: String) -> Option<String> {
<crate::core_impl::PidginImpl as PidginCore>::parse_git_url(source)
}

/// `stripAnsi` (utils/ansi.ts): remove ANSI escape sequences (OSC + CSI). The
/// shim keeps pi's non-string `TypeError` guard, so only strings reach here.
#[napi(js_name = "stripAnsi")]
pub fn strip_ansi(value: String) -> String {
<crate::core_impl::PidginImpl as PidginCore>::strip_ansi(value)
}

/// The Rust-backed keybindings core, exposed to JavaScript as
/// `KeybindingsManagerCore`.
#[napi]
Expand Down
7 changes: 0 additions & 7 deletions crates/pidgin-napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,6 @@ pub fn anthropic_parse_sse_stream(
// the pi export it replaces; the shims re-export the un-ported surface from the
// preserved pi original and override only these symbols.

/// `stripAnsi` (utils/ansi.ts): remove ANSI escape sequences (OSC + CSI). The
/// shim keeps pi's non-string `TypeError` guard, so only strings reach here.
#[napi(js_name = "stripAnsi")]
pub fn strip_ansi(value: String) -> String {
pidgin_coding::utils::ansi::strip_ansi(&value)
}

/// `detectSupportedImageMimeType` (utils/mime.ts): sniff a supported image MIME
/// type from magic bytes, or `null`.
#[napi(js_name = "detectSupportedImageMimeType")]
Expand Down