-
Notifications
You must be signed in to change notification settings - Fork 14
Added ability to center output with a flag. #26
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall not bad, but there are some sore spots. I'm not entirely sure how popular this feature would even be, which is why if it is to be implemented then it has to be more extensible. Thanks for contributing nonetheless :)
rand = "0.8.5" | ||
rust-embed = { version = "8.5.0" } | ||
showie = "1.0.1" | ||
termion = "4.0.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Termion is a pretty big crate just to use one function, are you sure it isn't possible to just re-implement a simple terminal size function? I haven't looked into it myself, but I assume it isn't too bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a look. I think there's also a package called terminal-size. This was originally a quick and dirty hack I put together for personal use, so I freely admit that the code could probably be better. I'll look into it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would switching to terminal_size be adequate? It's much smaller.
eprintln!("{}", names.join(", ")); | ||
let output = &names.join(", "); | ||
if args.center { | ||
let (width, _) = termion::terminal_size().expect("Must be run in terminal"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're getting width twice, for not much reason. I'd say maybe split off a function to get padding, and pass in a terminal width as well as a content width. The code would be a lot cleaner that way.
let image = showie::to_ascii(&combined); | ||
if args.center { | ||
let (width, _) = termion::terminal_size().expect("Must be run in terminal"); | ||
for line in image.lines() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, this assumes that each line will be a different length for some reason. You don't need to compute the line padding every single line, just do it once and then apply it to each line.
Added the ability to center the output with a simple
--center
flag. This meant I added a few dependencies, specifically termion and ansi-width, to assist.