use core::fmt; /// Describes one or two characters from the input /// /// [Rune]s are a way to mark special characters from the input string (i.e. /// poetry). Some [Rune]s are special--as they denote the end of a [Verse]-- /// and are refered to as a Meter. For instance, `Addendum`, `Couplet`, /// `Quiet`, and `And`, are all meters. Meters also determine how the /// [Stanza][super::stanza::Stanza] should be interpreted. For instance, a /// [Stanza][super::stanza::Stanza] that is piped needs to have /// its `STDOUT` captured (rather than printing out to the terminal), and /// subsequently sent to the next [Verse] in the [Poem][super::super::Poem]. /// /// # Values /// * `None` - A shell command with no additional actions (the end of a poem) /// * `Pause` - The space character, to dilineate words (` `) /// * `Path` - The forward slash character, to dilineate paths (`/`) /// * `Remark` - Indicates a single line comment (`#`) /// * `String` - Interpret all character as one large /// [Word][super::word::Word] (`'` or `"`) /// * `Poem` - A subcommand to run first (`\``) /// * `Read` - Read files into STDIN (`<`) /// * `Write` - Write STDOUT to a file (`>`) /// * `Write2` - Write STDERR to a file (`2>`) /// * `WriteAll` - Write both STDOUT and STDERR to a file (`&>`) /// * `Addendum` - Append STDOUT to a file (`>>`) /// * `Addendum2` - Append STDERR to a file (`2>>`) /// * `AddendumAll` - Append both STDOUT and STDERR to a file (`&>>`) /// * `Couplet` - Pipe the output of this command into the next (`|`) /// * `Quiet` - Fork the called process into the background (`&`) /// * `And` - Run the next command only if this one succeeds (`&&`) /// * `Continue` - String commands together on a single line (`;`) /// * `Home` - Interpret `~` as `$HOME` /// * `Else` - Any other character #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum Rune { None, // No meter (the end of a poem) Pause, // A space Path, // A forward slash Remark, // A comment String, // Interpret the following as one large [Word] Poem, // Run a sub-poem before the main one Read, // Read files into STDIN Write, // Send STDOUT to a file Write2, // Send STDERR to a file WriteAll, // Send STDOUT and STDERR to a file Addendum, // Append STDOUT to a file Addendum2, // Append STDERR to a file AddendumAll, // Append STDOUT and STDERR to a file Couplet, // Pipe the output of this command into the next Quiet, // Fork the command into the background And, // Run the next command only if this succeeds Continue, // Run the next command, even if this doesn't succeed Home, // Interpret '~' as $HOME Else, // Any other character } impl fmt::Display for Rune { /// Determine how to print out a [Rune] /// /// Each [Rune]'s symbol corresponds to its input. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let rune = match self { Rune::None => "", Rune::Pause => " ", Rune::Path => "/", Rune::Remark => "#", Rune::String => "\"", Rune::Poem => "`", Rune::Read => "<", Rune::Write => ">", Rune::Write2 => "2>", Rune::WriteAll => "&>", Rune::Addendum => ">>", Rune::Addendum2 => "2>>", Rune::AddendumAll => "&>>", Rune::Couplet => "|", Rune::Quiet => "&", Rune::And => "&&", Rune::Continue => ";", Rune::Home => "~", Rune::Else => "_", }; write!(f, "{}", rune) } }