-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command Line Resize #1728
Comments
I could take a crack at this. 🙂 |
@duncandean contributions are welcome :) |
redo this function then tari/applications/tari_base_node/src/cli.rs Line 106 in 4039de1
|
you want to fingerprint stdout then , which is different libc functions on different sys https://github.com/eminence/terminal-size/blob/master/src/unix.rs here is one with unsafe rust |
cat src/main.rs root@burk0:/tmp/asd# cat src/main.rs
use libc::ioctl;
use libc::isatty;
use libc::{winsize as WinSize, TIOCGWINSZ};
fn main() {
let fd = libc::STDOUT_FILENO;
let is_tty: bool = unsafe { isatty(fd) == 1 };
if !is_tty {
panic!("no tty");
}
let mut winsize = WinSize {
ws_row: 0,
ws_col: 0,
ws_xpixel: 0,
ws_ypixel: 0,
};
if unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut winsize) } == -1 {
panic!("nope");
}
let rows = winsize.ws_row as usize;
let cols = winsize.ws_col as usize;
if rows > 0 && cols > 0 {
println!("fluff: {} {}",cols, rows)
}
let fluff = "h".repeat(cols);
println!("{}", fluff);
} |
working code: use libc::ioctl;
use libc::isatty;
use libc::{winsize as WinSize, TIOCGWINSZ};
fn box_line(length: usize, is_top: bool) -> String {
if length < 2 {
return format!("");
}
if is_top {
format!("{}{}{}", "┌", "─".repeat(length - 2), "┐")
} else {
format!("{}{}{}", "└", "─".repeat(length - 2), "┘")
}
}
fn box_data(data: String, target_length: usize) -> String {
let padding = if ((target_length - 2) / 2) > (data.chars().count() / 2) {
((target_length - 2) / 2) - (data.chars().count() / 2)
} else {
0
};
let mut s = format!("{}{}{}{}", " ".repeat(padding), data, " ".repeat(padding), "│");
// for integer rounding error, usually only 1 char, to ensure border lines up
while s.chars().count() < target_length - 1 {
s = format!("{}{}", " ", s);
}
format!("{}{}", "│", s)
}
fn main() {
let fd = libc::STDOUT_FILENO;
let is_tty: bool = unsafe { isatty(fd) == 1 };
if !is_tty {
panic!("no tty");
}
let mut winsize = WinSize {
ws_row: 0,
ws_col: 0,
ws_xpixel: 0,
ws_ypixel: 0,
};
if unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut winsize) } == -1 {
panic!("nope");
}
let rows = winsize.ws_row as usize;
let cols = winsize.ws_col as usize;
if rows > 0 && cols > 0 {
println!("fluff: {} {}",cols, rows)
}
let fluff = "h".repeat(cols);
println!("{}",box_line(cols, true));
let rows = rows-3;
for tari in 0..rows{
println!("{}", box_data("test".to_string(),cols))
}
println!("{}",box_line(cols, false));
// println!("{}", fluff);
} |
lets give find terminal size in to a function: //give me the width and height of your terminal size
fn gimmesize() -> (usize, usize) {
let fd = libc::STDOUT_FILENO;
let is_tty: bool = unsafe { isatty(fd) == 1 };
if !is_tty {
panic!("no tty");
}
let mut winsize = WinSize {
ws_row: 0,
ws_col: 0,
ws_xpixel: 0,
ws_ypixel: 0,
};
if unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut winsize) } == -1 {
panic!("nope");
}
let height = winsize.ws_row as usize;
let width = winsize.ws_col as usize;
return (width, height);
}
|
@flipchan Looks good, mind submitting a PR for this and then we can review it? |
Description --- Use [crossterm](https://github.com/crossterm-rs/crossterm) crate to resize cli properly. Motivation and Context --- My very first `good first issue` to work on tari codebase. ;-) How Has This Been Tested? --- Tested on macOS Monterey (12.1). Works for system Terminal app. Doesn't work for iTerm2.
Description --- Use [crossterm](https://github.com/crossterm-rs/crossterm) crate to resize cli properly. Motivation and Context --- My very first `good first issue` to work on tari codebase. ;-) How Has This Been Tested? --- Tested on macOS Monterey (12.1). Works for system Terminal app. Doesn't work for iTerm2.
feat(cli): resolves (#1728) Command Line Resize. Description --- Use [crossterm](https://github.com/crossterm-rs/crossterm) crate to resize cli properly. Motivation and Context --- My very first `good first issue` to work on tari codebase. ;-) How Has This Been Tested? --- Tested on macOS Monterey (12.1). Works for system Terminal app. Doesn't work for iTerm2.
Description --- To resolve tari-project#1728 better Motivation and Context --- As a follow-up of tari-project#3827. How Has This Been Tested? --- Tested on macOS Monterey (12.1). Works for system Terminal app. Doesn't work for iTerm2.
The Tari Base Node, does not automatically resize the terminal window on startup, leading to text being wrapped onto subsequent lines and breaking up the intended UI
To Reproduce
In a new un-resized terminal window, run
cargo run --bin tari_base_node
Expected behavior
The terminal should resize to fit the longest string on startup when displaying the UI
Screenshots
Current:
Expected
The text was updated successfully, but these errors were encountered: