Skip to content

Commit 2adc245

Browse files
fixed panic on short tables and long filenames
1 parent 591ac53 commit 2adc245

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/extra.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::logs::*;
22
use crate::{DEFAULT_LOGFILE, DEFAULT_SOCKET};
33
use hyprland::Result;
4+
use std::cmp::max;
45
use std::fs::File;
56
use std::io::prelude::*;
67
use std::net::Shutdown;
@@ -81,17 +82,24 @@ pub fn get_config(socket: Option<&str>, raw: bool) -> Result<()> {
8182

8283
let get_centered_conf = || {
8384
let table_width = max_titles + max_commands + max_options + 6;
85+
86+
let c = if table_width <= conf.len() {
87+
conf.split("/").last().unwrap_log(file!(), line!())
88+
} else {
89+
conf
90+
};
91+
8492
let center_fix = if table_width % 2 == 0 {
85-
conf.len() + conf.len() % 2
93+
c.len() + c.len() % 2
8694
} else {
87-
conf.len() - 1
95+
c.len() - 1
8896
};
8997

9098
format!(
9199
"{}\x1b[0;35m{}\x1b[0;0m{}",
92-
" ".repeat(table_width / 2 - conf.len() / 2),
93-
conf,
94-
" ".repeat((table_width - center_fix) / 2)
100+
" ".repeat(max(table_width / 2 - c.len() / 2, 0)),
101+
c,
102+
" ".repeat(max((table_width - center_fix) / 2, 0))
95103
)
96104
};
97105

@@ -158,6 +166,7 @@ pub fn print_logs(raw: bool) -> Result<()> {
158166
}
159167

160168
pub fn print_full_raw(socket: Option<&str>) -> Result<()> {
169+
println!("Hyprscratch v{}", env!("CARGO_PKG_VERSION"));
161170
println!("### LOGS ###\n");
162171
print_logs(true)?;
163172
println!("\n### CONFIGURATION ###\n");

0 commit comments

Comments
 (0)