Skip to content

Commit

Permalink
Extract Ansi module
Browse files Browse the repository at this point in the history
  • Loading branch information
maneatingape committed Sep 2, 2023
1 parent bf8480f commit e59ba42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

/// # Utility modules to handle common recurring Advent of Code patterns.
pub mod util {
pub mod ansi;
pub mod grid;
pub mod hash;
pub mod iter;
Expand Down
8 changes: 1 addition & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use aoc::util::ansi::*;
use aoc::util::parse::*;
use aoc::*;
use std::env::args;
use std::time::Instant;

fn main() {
// ANSI escape codes
const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
const RED: &str = "\x1b[31m";
const GREEN: &str = "\x1b[32m";
const YELLOW: &str = "\x1b[33m";

// Parse command line options
let (year, day) = match args().nth(1) {
Some(arg) => {
Expand Down
14 changes: 14 additions & 0 deletions src/util/ansi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
//!
//! These codes allow command line applications to show colored or styled text in most terminals.
//! Advanced commands can move the cursor or clear the screen.

pub const RESET: &str = "\x1b[0m";
pub const BOLD: &str = "\x1b[1m";
pub const RED: &str = "\x1b[31m";
pub const GREEN: &str = "\x1b[32m";
pub const YELLOW: &str = "\x1b[33m";
pub const BLUE: &str = "\x1b[94m";
pub const WHITE: &str = "\x1b[97m";
pub const HOME: &str = "\x1b[H";
pub const CLEAR: &str = "\x1b[J";

0 comments on commit e59ba42

Please sign in to comment.