Skip to content

Commit

Permalink
Rust FMT
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-schnur committed Feb 23, 2024
1 parent b4600f9 commit c552726
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/.rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Rust

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
profile: minimal
override: true

- name: Check formatting
run: cargo fmt -- --check

- name: Run tests
run: cargo test
42 changes: 30 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ impl<'a> Table<'a> {
}

fn create_line(&self, filler: char) -> String {
self
.column_widths
self.column_widths
.iter()
.map(|&len| filler.to_string().repeat(len + 2))
.collect::<Vec<_>>()
Expand All @@ -144,20 +143,39 @@ impl<'a> Table<'a> {

// Print headers
let header_str = self
.headers.iter().enumerate()
.headers
.iter()
.enumerate()
.map(|(i, header)| {
format!(" {}{}{} ", ConsoleColor::Green.to_fg_ansi_code(), header, " ".repeat(self.column_widths[i].saturating_sub(header.len())))
format!(
" {}{}{} ",
ConsoleColor::Green.to_fg_ansi_code(),
header,
" ".repeat(self.column_widths[i].saturating_sub(header.len()))
)
})
.collect::<Vec<_>>().join(" ") + CLEAR_COLOR;
.collect::<Vec<_>>()
.join(" ")
+ CLEAR_COLOR;
println!("{}", header_str);

println!("{}", border_line);

// Print rows
for row in &self.rows {
let row_str = row.iter().enumerate().map(|(i, cell)| {
format!(" {}{} ", cell, " ".repeat(self.column_widths[i].saturating_sub(cell.len())))
}).collect::<Vec<_>>().join(" ") + CLEAR_COLOR;
let row_str = row
.iter()
.enumerate()
.map(|(i, cell)| {
format!(
" {}{} ",
cell,
" ".repeat(self.column_widths[i].saturating_sub(cell.len()))
)
})
.collect::<Vec<_>>()
.join(" ")
+ CLEAR_COLOR;
println!("{}", row_str);
}

Expand Down Expand Up @@ -201,7 +219,7 @@ impl RusticPrint {
"{}{}{}{}{}\r\n",
foreground, background, prefix, padding_line, CLEAR_COLOR
)
.as_str(),
.as_str(),
);
}

Expand Down Expand Up @@ -236,7 +254,7 @@ impl RusticPrint {
"{}{}{}{}{}\r\n",
foreground, background, pushed_line, finish_block, CLEAR_COLOR
)
.as_str(),
.as_str(),
);

current_line.clear();
Expand All @@ -263,7 +281,7 @@ impl RusticPrint {
"{}{}{}{}{}\r\n",
foreground, background, pushed_line, finish_block, CLEAR_COLOR
)
.as_str(),
.as_str(),
);
}

Expand All @@ -273,7 +291,7 @@ impl RusticPrint {
"{}{}{}{}{}\r\n",
foreground, background, prefix, padding_line, CLEAR_COLOR
)
.as_str(),
.as_str(),
);
}

Expand Down

0 comments on commit c552726

Please sign in to comment.