As stated in `codex-rs/README.md`: Today, Codex CLI is written in TypeScript and requires Node.js 22+ to run it. For a number of users, this runtime requirement inhibits adoption: they would be better served by a standalone executable. As maintainers, we want Codex to run efficiently in a wide range of environments with minimal overhead. We also want to take advantage of operating system-specific APIs to provide better sandboxing, where possible. To that end, we are moving forward with a Rust implementation of Codex CLI contained in this folder, which has the following benefits: - The CLI compiles to small, standalone, platform-specific binaries. - Can make direct, native calls to [seccomp](https://man7.org/linux/man-pages/man2/seccomp.2.html) and [landlock](https://man7.org/linux/man-pages/man7/landlock.7.html) in order to support sandboxing on Linux. - No runtime garbage collection, resulting in lower memory consumption and better, more predictable performance. Currently, the Rust implementation is materially behind the TypeScript implementation in functionality, so continue to use the TypeScript implmentation for the time being. We will publish native executables via GitHub Releases as soon as we feel the Rust version is usable.
40 lines
1.3 KiB
Rust
40 lines
1.3 KiB
Rust
use ansi_to_tui::Error;
|
|
use ansi_to_tui::IntoText;
|
|
use ratatui::text::Line;
|
|
use ratatui::text::Text;
|
|
|
|
/// This function should be used when the contents of `s` are expected to match
|
|
/// a single line. If multiple lines are found, a warning is logged and only the
|
|
/// first line is returned.
|
|
pub fn ansi_escape_line(s: &str) -> Line<'static> {
|
|
let text = ansi_escape(s);
|
|
match text.lines.as_slice() {
|
|
[] => Line::from(""),
|
|
[only] => only.clone(),
|
|
[first, rest @ ..] => {
|
|
tracing::warn!("ansi_escape_line: expected a single line, got {first:?} and {rest:?}");
|
|
first.clone()
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn ansi_escape(s: &str) -> Text<'static> {
|
|
// to_text() claims to be faster, but introduces complex lifetime issues
|
|
// such that it's not worth it.
|
|
match s.into_text() {
|
|
Ok(text) => text,
|
|
Err(err) => match err {
|
|
Error::NomError(message) => {
|
|
tracing::error!(
|
|
"ansi_to_tui NomError docs claim should never happen when parsing `{s}`: {message}"
|
|
);
|
|
panic!();
|
|
}
|
|
Error::Utf8Error(utf8error) => {
|
|
tracing::error!("Utf8Error: {utf8error}");
|
|
panic!();
|
|
}
|
|
},
|
|
}
|
|
}
|