Skip to content

Commit

Permalink
Adding some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Sep 2, 2024
1 parent 431c6ea commit 2c569e0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/colors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
//! Colors for use in logging and testing
/// Reset color formatting
pub const RESET: &str = "\x1b[00m\x1b[0m";

/// Bright red
pub const RED: &str = "\x1b[31m\x1b[1m";

/// Bright green
pub const GREEN: &str = "\x1b[32m\x1b[1m";

/// Bright yellow
pub const YELLOW: &str = "\x1b[33m\x1b[1m";

/// Bright purple
pub const PURPLE: &str = "\x1b[34m\x1b[1m";

/// Bright pink
pub const PINK: &str = "\x1b[35m\x1b[1m";

/// Bright cyan
pub const CYAN: &str = "\x1b[36m\x1b[1m";

/// Bright white
pub const WHITE: &str = "\x1b[37m\x1b[1m";
5 changes: 5 additions & 0 deletions src/comments.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Utilities for finding, extracting and removing LaTeX comments
/// Find the location where a comment begins in a line
pub fn find_comment_index(line: &str) -> Option<usize> {
// no percent means no comment
if !line.contains('%') {
Expand Down Expand Up @@ -33,10 +36,12 @@ pub fn find_comment_index(line: &str) -> Option<usize> {
None
}

/// Remove a comment from the end of a line
pub fn remove_comment(line: &str, comment: Option<usize>) -> String {
comment.map_or_else(|| line.to_string(), |c| line.chars().take(c).collect())
}

/// Extract a comment from the end of a line
pub fn get_comment(line: &str, comment: Option<usize>) -> String {
comment.map_or_else(String::new, |c| line.chars().skip(c).collect())
}
9 changes: 9 additions & 0 deletions src/format.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Core methodology for formatting a file
use crate::ignore::*;
use crate::indent::*;
use crate::leave::*;
Expand All @@ -8,6 +10,7 @@ use crate::wrap::*;
use crate::LINE_END;
use log::Level::{Info, Warn};

/// Central function to format a file
pub fn format_file(
text: &str,
file: &str,
Expand Down Expand Up @@ -64,12 +67,18 @@ pub fn format_file(
new_text
}

/// Information on the current state during formatting
#[derive(Clone, Debug)]
pub struct State {
/// Corresponding line number in the original file
pub linum_old: usize,
/// Corresponding line number in the formatted file
pub linum_new: usize,
/// Ignored status of the current line
pub ignore: Ignore,
/// Indentation status of the current line
pub indent: Indent,
/// Verbatim status of the current line
pub leave: Leave,
}

Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! tex-fmt
//! An extremely fast LaTeX formatter written in Rust
#![warn(missing_docs)]
#![warn(clippy::nursery)]
#![warn(clippy::cargo)]
Expand Down

0 comments on commit 2c569e0

Please sign in to comment.