Skip to content

Commit

Permalink
ui: fill in default term width globally and return as usize
Browse files Browse the repository at this point in the history
I'm going to add more ui.term_width() callers, and it's unlikely we'll have to
set different defaults or error out.
  • Loading branch information
yuja committed Jul 31, 2024
1 parent b2b8682 commit 1977748
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,7 @@ pub enum LogContentFormat {
impl LogContentFormat {
pub fn new(ui: &Ui, settings: &UserSettings) -> Result<Self, config::ConfigError> {
if settings.config().get_bool("ui.log-word-wrap")? {
let term_width = usize::from(ui.term_width().unwrap_or(80));
let term_width = ui.term_width();
Ok(LogContentFormat::Wrap { term_width })
} else {
Ok(LogContentFormat::NoWrap)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/diff_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<'a> DiffRenderer<'a> {
DiffFormat::Stat => {
let tree_diff = from_tree.diff_stream(to_tree, matcher);
// TODO: In graph log, graph width should be subtracted
let width = usize::from(ui.term_width().unwrap_or(80));
let width = ui.term_width();
show_diff_stat(formatter, store, tree_diff, path_converter, width)?;
}
DiffFormat::Types => {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ impl Ui {
rpassword::prompt_password(format!("{prompt}: "))
}

pub fn term_width(&self) -> Option<u16> {
term_width()
pub fn term_width(&self) -> usize {
term_width().unwrap_or(80).into()
}
}

Expand Down

0 comments on commit 1977748

Please sign in to comment.