mirror of
https://github.com/openai/codex.git
synced 2026-05-05 05:42:33 +03:00
feat: codex tool tips (#7440)
<img width="551" height="316" alt="Screenshot 2025-12-01 at 12 22 26" src="https://github.com/user-attachments/assets/6ca3deff-8ef8-4f74-a8e1-e5ea13fd6740" />
This commit is contained in:
49
codex-rs/tui/src/tooltips.rs
Normal file
49
codex-rs/tui/src/tooltips.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use lazy_static::lazy_static;
|
||||
use rand::Rng;
|
||||
|
||||
const RAW_TOOLTIPS: &str = include_str!("../tooltips.txt");
|
||||
|
||||
lazy_static! {
|
||||
static ref TOOLTIPS: Vec<&'static str> = RAW_TOOLTIPS
|
||||
.lines()
|
||||
.map(str::trim)
|
||||
.filter(|line| !line.is_empty() && !line.starts_with('#'))
|
||||
.collect();
|
||||
}
|
||||
|
||||
pub(crate) fn random_tooltip() -> Option<&'static str> {
|
||||
let mut rng = rand::rng();
|
||||
pick_tooltip(&mut rng)
|
||||
}
|
||||
|
||||
fn pick_tooltip<R: Rng + ?Sized>(rng: &mut R) -> Option<&'static str> {
|
||||
if TOOLTIPS.is_empty() {
|
||||
None
|
||||
} else {
|
||||
TOOLTIPS.get(rng.random_range(0..TOOLTIPS.len())).copied()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rand::SeedableRng;
|
||||
use rand::rngs::StdRng;
|
||||
|
||||
#[test]
|
||||
fn random_tooltip_returns_some_tip_when_available() {
|
||||
let mut rng = StdRng::seed_from_u64(42);
|
||||
assert!(pick_tooltip(&mut rng).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn random_tooltip_is_reproducible_with_seed() {
|
||||
let expected = {
|
||||
let mut rng = StdRng::seed_from_u64(7);
|
||||
pick_tooltip(&mut rng)
|
||||
};
|
||||
|
||||
let mut rng = StdRng::seed_from_u64(7);
|
||||
assert_eq!(expected, pick_tooltip(&mut rng));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user