all_is_cubes/util/
status_text.rs

1use core::fmt;
2
3use manyfmt::Fmt;
4
5use all_is_cubes_base::util::ConciseDebug;
6
7/// Format type for [`manyfmt::Fmt`] which provides an highly condensed, ideally constant-width
8/// or constant-height, user-facing format for live-updating textual status messages.
9///
10/// This format does not follow Rust [`fmt::Debug`] syntax, and when implemented
11/// for standard Rust types may have quirks. Values may have multiple lines.
12#[expect(clippy::exhaustive_structs)]
13#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
14pub struct StatusText {
15    /// Types of information to include or exclude.
16    pub show: ShowStatus,
17}
18
19impl StatusText {
20    #[allow(missing_docs)]
21    pub const ALL: Self = Self {
22        show: ShowStatus::all(),
23    };
24}
25
26bitflags::bitflags! {
27    /// Different kinds of information which [`StatusText`] may include or exclude.
28    ///
29    ///  I apologize for this being so specific to All is Cubes internals.
30    #[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
31    // TODO: deserialization should be lenient and ignore unknown textual flags
32    #[cfg_attr(feature = "save", derive(serde::Serialize, serde::Deserialize))]
33    pub struct ShowStatus: u32 {
34        /// The “game world” universe (not the UI).
35        const WORLD = 1 << 0;
36        /// The UI universe (not the game world).
37        const UI = 1 << 1;
38
39        /// Simulation; advancing time.
40        const STEP = 1 << 2;
41        /// Drawing the current state.
42        const RENDER = 1 << 3;
43        /// Information about what the cursor is targeting.
44        const CURSOR = 1 << 4;
45
46        /// Things related to the processing of blocks.
47        const BLOCK = 1 << 5;
48        /// Things related to character control and physics.
49        const CHARACTER = 1 << 6;
50        /// Things related to [`Space`](crate::space::Space)s.
51        const SPACE = 1 << 7;
52    }
53}
54
55impl ShowStatus {
56    #[doc(hidden)] // just a substitute for const trait impl
57    pub const DEFAULT: Self = Self::WORLD.union(Self::STEP).union(Self::RENDER).union(Self::CURSOR);
58}
59
60impl Default for ShowStatus {
61    /// A partial set of flags which makes a reasonable default for introducing users to the
62    /// status text.
63    fn default() -> Self {
64        Self::DEFAULT
65    }
66}
67
68impl Fmt<StatusText> for core::time::Duration {
69    fn fmt(&self, fmt: &mut fmt::Formatter<'_>, _: &StatusText) -> fmt::Result {
70        <Self as Fmt<ConciseDebug>>::fmt(self, fmt, &ConciseDebug)
71    }
72}