-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement --graph-width option * Add tests * Update README * Update README
- Loading branch information
1 parent
132c12e
commit 4225309
Showing
10 changed files
with
173 additions
and
40 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 +1,53 @@ | ||
use ratatui::crossterm::terminal; | ||
|
||
use crate::graph::Graph; | ||
use crate::graph::{CellWidthType, Graph}; | ||
|
||
pub fn term_size(graph: &Graph) -> std::io::Result<()> { | ||
pub fn decide_cell_width_type( | ||
graph: &Graph, | ||
cell_width_type: Option<CellWidthType>, | ||
) -> std::io::Result<CellWidthType> { | ||
let (w, h) = terminal::size()?; | ||
let image_cell_width = (graph.max_pos_x + 1) * 2; | ||
let required_width = image_cell_width + 2; | ||
if required_width > w as usize { | ||
panic!("Terminal size {w}x{h} is too small. Required width is {required_width}."); | ||
let cell_width_type = | ||
decide_cell_width_type_from(graph.max_pos_x, w as usize, h as usize, cell_width_type); | ||
Ok(cell_width_type) | ||
} | ||
|
||
fn decide_cell_width_type_from( | ||
max_pos_x: usize, | ||
term_width: usize, | ||
term_height: usize, | ||
cell_width_type: Option<CellWidthType>, | ||
) -> CellWidthType { | ||
let single_image_cell_width = max_pos_x + 1; | ||
let double_image_cell_width = single_image_cell_width * 2; | ||
|
||
match cell_width_type { | ||
Some(CellWidthType::Double) => { | ||
let required_width = double_image_cell_width + 2; | ||
if required_width > term_width { | ||
panic!("Terminal size {term_width}x{term_height} is too small. Required width is {required_width} (graph_width = double)."); | ||
} | ||
CellWidthType::Double | ||
} | ||
Some(CellWidthType::Single) => { | ||
let required_width = single_image_cell_width + 2; | ||
if required_width > term_width { | ||
panic!("Terminal size {term_width}x{term_height} is too small. Required width is {required_width} (graph_width = single)."); | ||
} | ||
CellWidthType::Single | ||
} | ||
None => { | ||
let double_required_width = double_image_cell_width + 2; | ||
if double_required_width <= term_width { | ||
return CellWidthType::Double; | ||
} | ||
let single_required_width = single_image_cell_width + 2; | ||
if single_required_width <= term_width { | ||
return CellWidthType::Single; | ||
} | ||
panic!( | ||
"Terminal size {term_width}x{term_height} is too small. Required width is {single_required_width} (graph_width = single) or {double_required_width} (graph_width = double)." | ||
); | ||
} | ||
} | ||
Ok(()) | ||
} |
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
Oops, something went wrong.