Repository: peterheesterman/chit (language: rust)

Issue:
Table border alignment
![image](https://user-images.githubusercontent.com/308347/55666559-6fa61600-5859-11e9-8cd5-1df6015ccc85.png)

Gnome Terminal on Arch Linux


Discussion / hints:

Fix patch:
diff --git a/src/format.rs b/src/format.rs
index b907f9e..26a56e2 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -1,61 +1,34 @@
 use colored::*;
 
-const TOP_LEFT: &str = "┌";
-const TOP_RIGHT: &str = "┐";
-const BOTTOM_LEFT: &str = "└";
-const BOTTOM_RIGHT: &str = "┘";
 const HORIZONTAL: &str = "─";
-const SPACE: &str = " ";
-const VERTICAL: &str = "│";
 
 pub fn title_bar(width: usize, title: &str) -> String {
     let fill = (width - title.len()) - 2;
     format!(
         "{}{}{}{}",
-        TOP_LEFT.magenta(),
+        HORIZONTAL.magenta(),
         title.blue().bold(),
         n_character(fill, HORIZONTAL).magenta(),
-        TOP_RIGHT.magenta()
+        HORIZONTAL.magenta()
     )
 }
 
-pub fn padded_print(width: usize, message: String) {
-    println!("{}", pad(width, &message));
-}
-
-pub fn pad(width: usize, content: &str) -> String {
-    let fill = if width < content.len() + 10 {
-        0
-    } else {
-        (width - content.len()) - 2
-    };
-
-    format!(
-        "{}{}{}{}",
-        VERTICAL.magenta(),
-        content.blue(),
-        n_character(fill, SPACE),
-        VERTICAL.magenta()
-    )
+pub fn print(message: String) {
+    println!("{}",  &message);
 }
 
 pub fn end_bar(width: usize) -> String {
     let fill = width - 2;
     format!(
         "{}{}{}",
-        BOTTOM_LEFT.magenta(),
+        HORIZONTAL.magenta(),
         n_character(fill, HORIZONTAL).magenta(),
-        BOTTOM_RIGHT.magenta()
+        HORIZONTAL.magenta()
     )
 }
 
-pub fn get_width(crate_name: &str) -> usize {
-    let width = 45;
-    if crate_name.len() > width - 2 {
-        10 + crate_name.len()
-    } else {
-        width
-    }
+pub fn get_width() -> usize {
+    45
 }
 
 pub fn remove_quotes(value: String) -> String {
@@ -65,12 +38,12 @@ pub fn remove_quotes(value: String) -> String {
     string
 }
 
-pub fn print_rating(width: usize, rating: usize) {
+pub fn print_rating(rating: usize) {
     let stars = n_character(rating, "🌟 ");
     let star_rating = format!("Rating: {}", stars);
 
     if rating > 0 && rating < 6 {
-        println!("{}", pad(width + rating * 3, &star_rating))
+        println!("{}", &star_rating)
     }
 }
 
diff --git a/src/main.rs b/src/main.rs
index 4350274..66d8294 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -83,7 +83,7 @@ fn main() {
 }
 
 fn chit(crate_name: String) {
-    let width = format::get_width(&crate_name);
+    let width = format::get_width();
     println!("{} {}...", "Searching for".magenta(), &crate_name.blue());
 
     match crates::get(crates::url(&crate_name)) {
@@ -92,19 +92,19 @@ fn chit(crate_name: String) {
                 println!("{}", format::title_bar(width, &crate_name));
 
                 let rating = extract::calculate_rating(fields.clone());
-                format::print_rating(width, rating);
+                format::print_rating(rating);
 
                 // Download count
                 if let Some(download_count) = fields.downloads {
-                    format::padded_print(width, format!("Total downloads: {}", download_count));
+                    format::print(format!("Total downloads: {}", download_count));
                 }
 
                 if let Some(recent_downloads) = fields.recent_downloads {
-                    format::padded_print(width, format!("Recent downloads: {}", recent_downloads));
+                    format::print(format!("Recent downloads: {}", recent_downloads));
                 }
 
                 let recent_version = fields.versions[0].clone();
-                format::padded_print(width, 
+                format::print(
                     format!("Latest version: {} ({})",
                         format::remove_quotes(recent_version.semver),
                         recent_version.date
@@ -112,7 +112,7 @@ fn chit(crate_name: String) {
                 );
 
                 if let Some(size) = recent_version.size_in_bytes {
-                    format::padded_print(width, format!("Crate size: {} kB", (size as f64 / 1000_f64).round()));
+                    format::print(format!("Crate size: {} kB", (size as f64 / 1000_f64).round()));
                 }
             }
         }
@@ -136,8 +136,7 @@ fn chit(crate_name: String) {
             let owners_names = owners_names.join(", ");
 
             // Owners
-            format::padded_print(
-                width,
+            format::print(
                 format!("Owner{}: {}", if multiple { "s" } else { "" }, owners_names),
             );
         }
@@ -148,7 +147,7 @@ fn chit(crate_name: String) {
 }
 
 fn chit_owners(crate_name: String) {
-    let width = format::get_width(&crate_name);
+    let width = format::get_width();
     println!("{} {}...", "Searching for".magenta(), &crate_name.blue());
 
     match crates::get(crates::owners_url(&crate_name)) {
@@ -162,8 +161,7 @@ fn chit_owners(crate_name: String) {
                 .filter(|json| json["kind"] == "user")
             {
                 // Owner
-                format::padded_print(
-                    width,
+                format::print(
                     format!(
                         "Crates by {}:",
                             format::remove_quotes(user_json["name"].to_string())
@@ -175,8 +173,7 @@ fn chit_owners(crate_name: String) {
                     if let Some(user_json) = crates::get(crates::user_url(user_id)) {
                         if let Some(array) = user_json["crates"].as_array() {
                             for thing in array {
-                                format::padded_print(
-                                    width,
+                                format::print(
                                     format!(
                                         "    {}",
                                         format::remove_quotes(thing["id"].to_string())
@@ -195,7 +192,7 @@ fn chit_owners(crate_name: String) {
 }
 
 fn chit_versions(crate_name: String) {
-    let width = format::get_width(&crate_name);
+    let width = format::get_width();
     println!("{} {}...", "Searching for".magenta(), &crate_name.blue());
 
     match crates::get(crates::url(&crate_name)) {
@@ -203,11 +200,10 @@ fn chit_versions(crate_name: String) {
             if let Some(fields) = extract::crate_fields(crate_json) {
                 println!("{}", format::title_bar(width, &crate_name));
 
-                format::padded_print(width, String::from("Versions:"));
+                format::print(String::from("Versions:"));
                 for version in fields.versions {
                     if let Some(size) = version.size_in_bytes {
-                        format::padded_print(
-                            width,
+                        format::print(
                             format!(
                                 "    {} | {} | {} kB",
                                 format::remove_quotes(version.semver),
@@ -216,8 +212,7 @@ fn chit_versions(crate_name: String) {
                             )
                         );
                     } else {
-                        format::padded_print(
-                            width,
+                        format::print(
                             format!(
                                 "    {} | {}",
                                 format::remove_quotes(version.semver),


Test patch: