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][crate::poem::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][crate::poem::Verse] in the [Poem][super::super::Poem]. #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum Rune { /// A shell command with no additional actions (the end of a poem) None, /// The space character, to dilineate words (`' '`) Pause, /// The backslash character, to escape special character (`\`) Special, /// The forward slash character, to dilineate paths (`/`) Path, /// Indicates a single line comment (`#`) Remark, /// Interpret all characters as one large [Word][super::word::Word] /// (`'` or `"`) String, /// A subcommand to run first (`\``) Poem, /// Read files into STDIN (`<`) Read, /// Write STDOUT to a file (`>`) Write, /// Write STDERR to a file (`2>`) Write2, /// Write both STDOUT and STDERR to a file (`&>`) WriteAll, /// Append STDOUT to a file (`>>`) Addendum, /// Append STDERR to a file (`2>>`) Addendum2, /// Append both STDOUT and STDERR to a file (`&>>`) AddendumAll, /// Pipe the output of this command into the next (`|`) Couplet, /// Fork the called process into the background (`&`) Quiet, /// Run the next command, only if this one succeeds (`&&`) And, /// Run the next command, regardless of whether or not this command /// succeeds (`;` or a newline in a file) Continue, /// Interpret `~` as `$HOME` Home, /// Any other character Else, } 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::Special => "\\", 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) } }