Skip to content

Conversation

Chapien
Copy link

@Chapien Chapien commented Jul 12, 2025

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.

Copy link
Owner

@talwat talwat left a 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"
Copy link
Owner

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.

Copy link
Author

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!

Copy link
Author

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");
Copy link
Owner

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() {
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants