-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96ca8cb
commit a409a54
Showing
6 changed files
with
73 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,6 @@ | ||
use prettytable::{Cell, Row, Table}; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Clone)] | ||
pub struct GQLObject { | ||
pub attributes: HashMap<String, String>, | ||
} | ||
|
||
pub fn render_objects(groups: &Vec<Vec<GQLObject>>) { | ||
if groups.is_empty() || groups[0].is_empty() { | ||
return; | ||
} | ||
|
||
let mut titles: Vec<&str> = groups[0][0].attributes.keys().map(|k| k.as_ref()).collect(); | ||
titles.sort(); | ||
|
||
let mut table = Table::new(); | ||
let mut table_titles: Vec<Cell> = Vec::new(); | ||
for key in titles { | ||
table_titles.push(Cell::new(key)); | ||
} | ||
|
||
table.add_row(Row::new(table_titles)); | ||
|
||
let table_field_max_len = 40; | ||
for group in groups { | ||
for object in group { | ||
let mut keys: Vec<&str> = object.attributes.keys().map(|k| k.as_ref()).collect(); | ||
keys.sort(); | ||
|
||
let mut table_row = Row::new(Vec::new()); | ||
for key in keys { | ||
let value = &object.attributes[key]; | ||
if value.len() > table_field_max_len { | ||
let wrapped = textwrap::wrap(value, table_field_max_len); | ||
let formatted = wrapped.join("\n"); | ||
table_row.add_cell(Cell::new(&formatted)); | ||
} else { | ||
table_row.add_cell(Cell::new(value)); | ||
} | ||
} | ||
table.add_row(table_row); | ||
} | ||
} | ||
|
||
table.printstd(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use prettytable::{Cell, Row, Table}; | ||
|
||
use crate::object::GQLObject; | ||
|
||
pub fn render_objects(groups: &Vec<Vec<GQLObject>>, hidden_selections: &Vec<String>) { | ||
if groups.is_empty() || groups[0].is_empty() { | ||
return; | ||
} | ||
|
||
let titles: Vec<&str> = groups[0][0] | ||
.attributes | ||
.keys() | ||
.filter(|s| !hidden_selections.contains(s)) | ||
.map(|k| k.as_ref()) | ||
.collect(); | ||
|
||
let mut table = Table::new(); | ||
let mut table_titles: Vec<Cell> = Vec::new(); | ||
|
||
for key in &titles { | ||
table_titles.push(Cell::new(key)); | ||
} | ||
|
||
table.add_row(Row::new(table_titles)); | ||
|
||
let table_field_max_len = 40; | ||
for group in groups { | ||
for object in group { | ||
let mut table_row = Row::new(Vec::new()); | ||
for key in &titles { | ||
let value = &object.attributes.get(&key as &str).unwrap(); | ||
if value.len() > table_field_max_len { | ||
let wrapped = textwrap::wrap(value, table_field_max_len); | ||
let formatted = wrapped.join("\n"); | ||
table_row.add_cell(Cell::new(&formatted)); | ||
} else { | ||
table_row.add_cell(Cell::new(value)); | ||
} | ||
} | ||
table.add_row(table_row); | ||
} | ||
} | ||
|
||
table.printstd(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters