feat: add portable terminal output feature
This commit is contained in:
parent
3e18ddb870
commit
36757dca57
|
|
@ -65,7 +65,7 @@ acceptance gates on 2026-09-20. Phase 3 is the next active milestone.
|
|||
missing organisation surface) with aliases/deprecation where compatibility
|
||||
warrants it.
|
||||
- [ ] Improve all command help with examples and valid-value guidance.
|
||||
- [ ] Replace ambiguous success output and Nerd-Font-only semantics with clear,
|
||||
- [x] Replace ambiguous success output and Nerd-Font-only semantics with clear,
|
||||
attractive Unicode output that degrades safely without colour.
|
||||
- [ ] Ensure entity editing validates type-specific fields and reports useful
|
||||
recovery advice.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,13 @@ cd epoch_forge
|
|||
cargo install --locked --path bin_efo
|
||||
```
|
||||
|
||||
Nerd Font icons are enabled by default. Build a portable-Unicode variant for
|
||||
terminals without a Nerd Font with:
|
||||
|
||||
```bash
|
||||
cargo install --locked --path bin_efo --no-default-features
|
||||
```
|
||||
|
||||
## Quick start
|
||||
|
||||
Start in an empty directory. Epoch Forge stores `.epoch` and `epoch/` in the
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/epoch_forge"
|
||||
|
||||
[features]
|
||||
default = ["nerd-fonts"]
|
||||
nerd-fonts = ["lib_efo/nerd-fonts"]
|
||||
|
||||
[package.metadata.binstall]
|
||||
pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.tgz"
|
||||
pkg-fmt = "tgz"
|
||||
bin-dir = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }"
|
||||
[dependencies]
|
||||
lib_efo = { path = "../lib_efo" }
|
||||
lib_efo = { path = "../lib_efo", default-features = false }
|
||||
serde = {workspace = true}
|
||||
clap = {workspace = true}
|
||||
thiserror = {workspace = true}
|
||||
|
|
|
|||
|
|
@ -103,9 +103,11 @@ fn main() -> miette::Result<()> {
|
|||
env_logger::init();
|
||||
|
||||
log::trace!(
|
||||
"System version: {} ({}{}) {} {}",
|
||||
"System version: {} ({}{}{}{}) {} {}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
lib_efo::output::symbol("", "branch:"),
|
||||
env!("GIT_BRANCH"),
|
||||
lib_efo::output::symbol("", "@"),
|
||||
env!("GIT_HASH"),
|
||||
env!("TOOLCHAIN"),
|
||||
env!("RUSTC_VERSION"),
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@ pub enum SuccessMessages {
|
|||
#[display("Successfully computed the new epoch. The current epoch is now {_1} (was {_0})")]
|
||||
EpochNextSuccess(EpochId, EpochId),
|
||||
|
||||
#[display("Successfully deleted the entity {_0} ({_1} [{_2}])")]
|
||||
#[display("Successfully deleted entity {_0} ({_1} @[{_2}])")]
|
||||
DeletedEntity(String, String, String),
|
||||
|
||||
#[display("Successfully created the entity {_0} ({_1} [{_2}])")]
|
||||
#[display("Successfully created entity {_0} ({_1} @[{_2}])")]
|
||||
CreatedEntity(String, String, String),
|
||||
|
||||
#[display("Successfully edited the entity {_0} ({_1} [{_2}])")]
|
||||
#[display("Successfully edited entity {_0} ({_1} @[{_2}])")]
|
||||
EditedEntity(String, String, String),
|
||||
#[display("Showing delta between Epoch ({_0} & {_1})")]
|
||||
DiffBetweenEpoch(lib_efo::epoch::EpochId, EpochId),
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ collection. Use `<noun> show IDENTIFIER` for full details of one entity.
|
|||
`efo gen character|town|event|exotic|calamity|blocker` prints generated content
|
||||
without creating or changing repository files.
|
||||
|
||||
Output is human-readable Unicode. Some 0.1.0 renderers emit ANSI colour when
|
||||
redirected and use optional Nerd Font glyphs; these are known accessibility
|
||||
issues. Stable JSON output is planned. A panic is always a bug.
|
||||
Output is human-readable Unicode, with Nerd Font icons enabled by default. A
|
||||
portable build replaces those icons with textual/standard-Unicode labels; use
|
||||
`cargo install --path bin_efo --no-default-features`. Stable JSON output is
|
||||
planned. A panic is always a bug.
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@ name = "lib_efo"
|
|||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = ["nerd-fonts"]
|
||||
nerd-fonts = []
|
||||
|
||||
[dependencies]
|
||||
serde_json = {workspace = true}
|
||||
serde = {workspace = true}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
mod from_impl;
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::output::symbol;
|
||||
use crate::{
|
||||
Displayable,
|
||||
entity::Entity,
|
||||
|
|
@ -30,18 +31,22 @@ impl Displayable for Entity {
|
|||
.metadata
|
||||
.capital
|
||||
.as_ref()
|
||||
.map(|c| format!("Capital: {} ", c.to_symbol().blue()))
|
||||
.map(|c| format!("Capital: {}{} ", symbol(" ", ""), c.to_symbol().blue()))
|
||||
.unwrap_or_default();
|
||||
|
||||
let governor = self
|
||||
.metadata
|
||||
.governor
|
||||
.as_ref()
|
||||
.map(|g| format!("Governor: {}", g.to_symbol().blue()))
|
||||
.map(|g| format!("Governor: {}{}", symbol(" ", ""), g.to_symbol().blue()))
|
||||
.unwrap_or_default();
|
||||
|
||||
let prestige = if *self.metadata.prestige > 0 {
|
||||
format!(" {:2}{}", self.metadata.prestige, " ".yellow())
|
||||
format!(
|
||||
" {:2}{}",
|
||||
self.metadata.prestige,
|
||||
symbol(" ", " prestige").yellow()
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
|
@ -82,7 +87,7 @@ fn uuid_to_symbol(id: Uuid, epoch_info: &EpochInfo, e_type: &stats::EntityType)
|
|||
.map(|e| e.to_symbol())
|
||||
.unwrap_or(format!(
|
||||
"{}{} is missing {}",
|
||||
" ".red(),
|
||||
symbol(" ", "missing ").red(),
|
||||
id.to_symbol().red(),
|
||||
e_type.clone().to_shortest().blue()
|
||||
))
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
//! 4. **Entity creation** – deterministic or RNG‑based.
|
||||
//! 5. **Utility helpers** – position handling, identifier matching.
|
||||
|
||||
use crate::output::symbol;
|
||||
use cli_table::{Style, WithTitle};
|
||||
use colored::*;
|
||||
use rand::distr::Distribution;
|
||||
|
|
@ -135,9 +136,10 @@ impl Entity {
|
|||
let mut out = String::new();
|
||||
|
||||
out.push_str(&format!(
|
||||
"[{} {} [{}]]\n",
|
||||
"[{} {} {}[{}]]\n",
|
||||
self.entity_type.to_symbol().blue().bold(),
|
||||
self.name.cyan().bold(),
|
||||
symbol("", "@"),
|
||||
self.id.to_string().blue().bold()
|
||||
));
|
||||
|
||||
|
|
@ -159,7 +161,7 @@ impl Entity {
|
|||
&format!(
|
||||
"├─ {} : {}{}\n",
|
||||
"faction".bright_green(),
|
||||
" ".yellow(),
|
||||
symbol(" ", "faction ").yellow(),
|
||||
faction.to_string().yellow(),
|
||||
),
|
||||
));
|
||||
|
|
@ -181,7 +183,7 @@ impl Entity {
|
|||
"├─ {}: {}{}\n",
|
||||
"prestige".bright_green(),
|
||||
self.metadata.prestige.to_string().yellow(),
|
||||
" ".yellow()
|
||||
symbol(" ", " prestige").yellow()
|
||||
),
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -281,6 +281,7 @@ fn effect_bound_testing() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "nerd-fonts")]
|
||||
fn snapshot_full_oneline_display() {
|
||||
init_snapshot_env();
|
||||
let e = full_entity();
|
||||
|
|
@ -302,6 +303,7 @@ fn snapshot_full_oneline_display() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "nerd-fonts")]
|
||||
fn snapshot_minimal_oneline_display() {
|
||||
init_snapshot_env();
|
||||
let e = Entity::default();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
//! The world data and all event logs belong to the individual epoch
|
||||
//! directories and are **not** part of this file.
|
||||
|
||||
use crate::output::symbol;
|
||||
use crate::{
|
||||
epoch::{
|
||||
EpochId, EpochIdentifier, EpochInfo, MAIN_NAME, SUBFOLDER_NAMING, SaveMode, TagList,
|
||||
|
|
@ -427,7 +428,7 @@ impl EpochConfig {
|
|||
// TODO: Make a method for this
|
||||
for elt in items_to_log.iter().rev() {
|
||||
let star = if elt.epoch_id == self.epoch_id {
|
||||
" "
|
||||
symbol(" ", "→ ")
|
||||
} else {
|
||||
" "
|
||||
};
|
||||
|
|
@ -435,7 +436,7 @@ impl EpochConfig {
|
|||
"{} {:>4} - {}{}{:10} {:50}",
|
||||
star.green(),
|
||||
elt.epoch_id.to_symbol().blue(),
|
||||
" ".yellow(),
|
||||
symbol(" ", "entities: ").yellow(),
|
||||
(elt.events.len()
|
||||
+ elt.characters.len()
|
||||
+ elt.towns.len()
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ pub mod error;
|
|||
pub mod entity;
|
||||
pub mod epoch;
|
||||
pub mod naming;
|
||||
pub mod output;
|
||||
pub mod stats;
|
||||
pub mod utils;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
//! Compile-time selection of decorative terminal symbols.
|
||||
|
||||
/// Select a Nerd Font icon in default builds and a portable Unicode fallback
|
||||
/// when the `nerd-fonts` feature is disabled.
|
||||
#[must_use]
|
||||
pub const fn symbol(nerd_font: &'static str, portable: &'static str) -> &'static str {
|
||||
if cfg!(feature = "nerd-fonts") {
|
||||
nerd_font
|
||||
} else {
|
||||
portable
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
//! All symbol implementations
|
||||
//!
|
||||
use crate::output::symbol;
|
||||
use crate::{
|
||||
entity::{EffectApplication, EffectBounds, EntityDuration},
|
||||
stats::{
|
||||
|
|
@ -12,9 +13,9 @@ use colored::Colorize;
|
|||
impl Symbols for Role {
|
||||
fn to_symbol(&self) -> String {
|
||||
match self {
|
||||
Role::Govern => " ".to_string(),
|
||||
Role::Capital => " ".to_string(),
|
||||
Role::Undefined => "".to_string(),
|
||||
Role::Govern => symbol(" ", "governs ").to_string(),
|
||||
Role::Capital => symbol(" ", "capital ").to_string(),
|
||||
Role::Undefined => symbol("", "link").to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,12 +33,12 @@ impl Symbols for EntityType {
|
|||
}
|
||||
fn to_symbol(&self) -> String {
|
||||
match self {
|
||||
EntityType::Character => "".to_string(),
|
||||
EntityType::Player => " ".to_string(),
|
||||
EntityType::Town => " ".to_string(),
|
||||
EntityType::Monster => " ".to_string(),
|
||||
EntityType::Blocker => " ".to_string(),
|
||||
EntityType::Event => "".to_string(),
|
||||
EntityType::Character => symbol("", "person").to_string(),
|
||||
EntityType::Player => symbol(" ", "player ").to_string(),
|
||||
EntityType::Town => symbol(" ", "town ").to_string(),
|
||||
EntityType::Monster => symbol(" ", "calamity ").to_string(),
|
||||
EntityType::Blocker => symbol(" ", "blocker ").to_string(),
|
||||
EntityType::Event => symbol("", "event").to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -83,13 +84,13 @@ impl Symbols for OverallStats {
|
|||
format!(
|
||||
"{:2}{} {:2}{} {:2}{} {:2}{}",
|
||||
self.demographics,
|
||||
" ".green(),
|
||||
symbol(" ", "dem ").green(),
|
||||
self.economy,
|
||||
"💰".yellow(),
|
||||
self.military,
|
||||
" ".red(),
|
||||
symbol(" ", "mil ").red(),
|
||||
self.infrastructure,
|
||||
"".cyan(),
|
||||
symbol("", "inf").cyan(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -127,31 +128,31 @@ impl Symbols for ListStats {
|
|||
}
|
||||
fn to_symbol(&self) -> String {
|
||||
match self {
|
||||
ListStats::Demographics => " ".blue(),
|
||||
ListStats::Population => " ".green(),
|
||||
ListStats::Growthrate => " ".green(),
|
||||
ListStats::Crime => "".green(),
|
||||
ListStats::Happiness => " ".green(),
|
||||
ListStats::Demographics => symbol(" ", "DEM ").blue(),
|
||||
ListStats::Population => symbol(" ", "POP ").green(),
|
||||
ListStats::Growthrate => symbol(" ", "GRW ").green(),
|
||||
ListStats::Crime => symbol("", "CRM").green(),
|
||||
ListStats::Happiness => symbol(" ", "HPY ").green(),
|
||||
ListStats::Economy => "💰".blue(),
|
||||
ListStats::Food => "".yellow(),
|
||||
ListStats::Food => symbol("", "FOD").yellow(),
|
||||
ListStats::Industry => "🏭".yellow(),
|
||||
ListStats::Science => " ".yellow(),
|
||||
ListStats::Trade => " ".yellow(),
|
||||
ListStats::Social => " ".blue(),
|
||||
ListStats::Science => symbol(" ", "SCI ").yellow(),
|
||||
ListStats::Trade => symbol(" ", "TRD ").yellow(),
|
||||
ListStats::Social => symbol(" ", "SOC ").blue(),
|
||||
ListStats::Culture => "🎭".purple(),
|
||||
ListStats::Education => "📚".purple(),
|
||||
ListStats::Tourism => "🏖️".purple(),
|
||||
ListStats::Influence => "🌍".purple(),
|
||||
ListStats::Military => "🪖".blue(),
|
||||
ListStats::Army => " ".red(),
|
||||
ListStats::Strength => " ".red(),
|
||||
ListStats::Army => symbol(" ", "ARM ").red(),
|
||||
ListStats::Strength => symbol(" ", "STR ").red(),
|
||||
ListStats::Fortification => "🔒".red(),
|
||||
ListStats::Threat => "⚡".red(),
|
||||
ListStats::Infrastructure => "🏗️ ".blue(),
|
||||
ListStats::Bureaucracy => "🏛️ ".cyan(),
|
||||
ListStats::Transportation => " ".cyan(),
|
||||
ListStats::Transportation => symbol(" ", "TRP ").cyan(),
|
||||
ListStats::Sprawl => "🏙️".cyan(),
|
||||
ListStats::Health => "".cyan(),
|
||||
ListStats::Health => symbol("", "HLT").cyan(),
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ fn position_invalid_format_errors_are_detected() {
|
|||
assert!(matches!(err, EpochError::ParsePositionError(_)));
|
||||
}
|
||||
#[test]
|
||||
#[cfg(feature = "nerd-fonts")]
|
||||
fn test_liststats_aliases() {
|
||||
// Each tuple: (alias, expected enum variant)
|
||||
let cases = vec![
|
||||
|
|
@ -270,6 +271,7 @@ fn test_liststats_unknown_alias() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "nerd-fonts")]
|
||||
fn test_entity_type_to_shortest() {
|
||||
let out = [
|
||||
stats::EntityType::Character,
|
||||
|
|
|
|||
Loading…
Reference in New Issue