Skip to content
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

Add network interface to UI #112

Closed
wants to merge 15 commits into from
Closed

Add network interface to UI #112

wants to merge 15 commits into from

Conversation

captain-yossarian
Copy link
Contributor

@captain-yossarian captain-yossarian commented Jan 12, 2020

Regarding this #37 issue

@imsnif imsnif self-assigned this Jan 14, 2020
Copy link
Owner

@imsnif imsnif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry it took me a short while to get to this!

This is a good start. I left some comments on the direction. Let's make this happen. :)

@@ -20,10 +20,12 @@ impl<'a> TotalBandwidth<'a> {
} else {
Color::Green
};
let interface = datalink::interfaces().into_iter().map(|interface|interface.name).collect::<Vec<String>>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we actually already do something similar on the OS layer. Since we have this information already, I think it would be best if we pass it to the UI in order not to have to do the query a second time (and possibly get different results if something has changed on the system while the app was running, for example).

I think the place to pass this information to the UI would be here: https://github.com/imsnif/bandwhich/blob/master/src/main.rs#L117


[Text::styled(
format!(
" Total Rate Up / Down: {} / {} {}",
" Interfaces {:?} / Total Rate Up / Down: {} / {} {}",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned that with a lot of interfaces, this line might become rather long.
Since we can only listen on one interface or on all of them, what do you think about specifying either the one interface name, or something like "*" (or ALL?) if there is more than one?

Copy link
Contributor Author

@captain-yossarian captain-yossarian Jan 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imsnif It was my mistake to import network interface. Variable interface_name is Option<String> not vector.
So, there is no need to to use "*"
Could you please take a look again?

Copy link
Owner

@imsnif imsnif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, left some comments.

src/main.rs Outdated
@@ -122,7 +122,7 @@ where
let raw_mode = opts.raw;

let network_utilization = Arc::new(Mutex::new(Utilization::new()));
let ui = Arc::new(Mutex::new(Ui::new(terminal_backend, opts.render_opts)));
let ui = Arc::new(Mutex::new(Ui::new(terminal_backend, opts.render_opts, opts.interface)));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we already have a render_opts, maybe we can make the interface name part of it?

[Text::styled(
format!(
" Total Rate Up / Down: {} / {} {}",
" Interfaces {} / Total Rate Up / Down: {} / {} {}",
DisplayString(interface),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand... why do we need DisplayString here? Why not input the interface name directly?

Also, could we make the display:

  • if there is a specific interface passed in the options, we will display <interface_name>: Total Rate Up / Down: {} / {} {}
  • if there is no interface (meaning we're listening on all interfaces), we'll just display the previous string without the interfaces

What do you say?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imsnif Sure. I've made all changes.
Travic CI build failing every time. Do you know the reason?
Also, I don't know why, but on my machine all tests are failing every time, even on master branch.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for travis: you can see the output of the snapshot tests (these are essentially tests that run the app under certain situations take a "snapshot" of the terminal screen and see that the output is what they expect - these should be quite readable, so you can look at the travis output linked in this PR and check them out).

As for your local tests: if you tell me more about why they are failing, maybe we can try and debug it?

Copy link
Contributor Author

@captain-yossarian captain-yossarian Jan 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imsnif After cargo test command, insta package creates new files.
tests1
tests2

Complete log
Part of the log with color for readability
tests3

P.S. What do you think about my last changes ? Is it ok?
P.S.S. Sorry for taking your time, I'm really want to help, but I have not a lot experience in Rust. I'm only learning.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries friend! We all have to start sometime, right? Thanks for taking the time to work on this. :) The snapshots should be part of the repository, so it's odd that the tests are creating them instead. I'd try to look in that direction.
I'll take a look at your changes here and in the other PR in the next few days.

@captain-yossarian
Copy link
Contributor Author

@imsnif Travis CI tests failed bacause snapshots are incompatible
tests4
I dont understand why there is interface_name in snapshot. According to my changes there should be either nothing or interface name

@imsnif
Copy link
Owner

imsnif commented Jan 21, 2020

Hey @SerhiiBilyk - I think it will be a lot easier for you if you get the tests running locally. I find that they make development easier for me by quickly showing me the effects of my changes in various situations in the app (without having to push to the branch and waiting for travis).

It's very odd that they create new snapshots for you (as you wrote above). Could you maybe try to re-clone the repository somewhere else and just running cargo test? Do they also create the snapshots that way?

@captain-yossarian
Copy link
Contributor Author

captain-yossarian commented Jan 24, 2020

@imsnif Hi, sorry for delay.
I've cloned the project to other folder.
Same problem. All tests has been failed and new snapshot created.
tests_failed
tests_failed2
Btw, I have Ubuntu 18 and rust 1.40.0

Could you please checkout on my branch and run the tests?
P.S. I've tried cargo insta accept && cargo insta review it partialy helps, but it anyway creates new snapshots

@imsnif
Copy link
Owner

imsnif commented Feb 11, 2020

The snapshots are created by the tests only if they are missing in the snapshots folder.

If this happens to you on a fresh clone of the repository, I cannot explain it. This is not reproduced for me (or for our CI) - to the best of my knowledge this only happens to you. I don't have any ideas more clever than "clone the repository and look in the snapshots folder", sorry :/

@captain-yossarian
Copy link
Contributor Author

If somebody is interested to finish this PR, feel free to pick it up, because I have an issues with testing framework on my local machine

@imsnif imsnif closed this Sep 13, 2020
@imsnif
Copy link
Owner

imsnif commented Sep 13, 2020

Hey, this was closed by mistake and I don't seem to be able to re-open it. Please feel free to re-open or make another PR with this if you wish. My apologies!

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