feat: experimental menu (#8071)

This will automatically render any `Stage::Beta` features.

The change only gets applied to the *next session*. This started as a
bug but actually this is a good thing to prevent out of distribution
push

<img width="986" height="288" alt="Screenshot 2025-12-15 at 15 38 35"
src="https://github.com/user-attachments/assets/78b7a71d-0e43-4828-a118-91c5237909c7"
/>


<img width="509" height="109" alt="Screenshot 2025-12-15 at 17 35 44"
src="https://github.com/user-attachments/assets/6933de52-9b66-4abf-b58b-a5f26d5747e2"
/>
This commit is contained in:
jif-oai
2025-12-17 17:08:03 +00:00
committed by GitHub
parent 9352c6b235
commit ac6ba286aa
15 changed files with 577 additions and 38 deletions

View File

@@ -1,14 +1,28 @@
use codex_core::features::FEATURES;
use lazy_static::lazy_static;
use rand::Rng;
const RAW_TOOLTIPS: &str = include_str!("../tooltips.txt");
fn beta_tooltips() -> Vec<&'static str> {
FEATURES
.iter()
.filter_map(|spec| spec.stage.beta_announcement())
.collect()
}
lazy_static! {
static ref TOOLTIPS: Vec<&'static str> = RAW_TOOLTIPS
.lines()
.map(str::trim)
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.collect();
static ref ALL_TOOLTIPS: Vec<&'static str> = {
let mut tips = Vec::new();
tips.extend(TOOLTIPS.iter().copied());
tips.extend(beta_tooltips());
tips
};
}
pub(crate) fn random_tooltip() -> Option<&'static str> {
@@ -17,10 +31,12 @@ pub(crate) fn random_tooltip() -> Option<&'static str> {
}
fn pick_tooltip<R: Rng + ?Sized>(rng: &mut R) -> Option<&'static str> {
if TOOLTIPS.is_empty() {
if ALL_TOOLTIPS.is_empty() {
None
} else {
TOOLTIPS.get(rng.random_range(0..TOOLTIPS.len())).copied()
ALL_TOOLTIPS
.get(rng.random_range(0..ALL_TOOLTIPS.len()))
.copied()
}
}