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

Using cossterm for windows support. #99

Merged
merged 2 commits into from Dec 24, 2019

Conversation

TimonPost
Copy link
Contributor

@TimonPost TimonPost commented Oct 22, 2019

Fixes: #69

This app can support windows very easily. TUI has the crossterm backend which is made to support cross-platform.

I tried to move this library over to crossterm just to experiment to how easy it was to swap termion. It was very easy. Please have a look at this fork.

Although...

Their implementation uses crossterm 0.9 and 0.12 is already out and they didn't even release my latest patch - done a few months ago - with 0.10 yet. This old version of crossterm has some problems and ideally it should use 0.12 it's way better performance-wise as well.

However, I encountered problems:

-. KeyEvent (replacement for Key) does not implement Copy however, this is going to be fixed in 0.12.2.

  • TUI uses crossterm ^0.9, therefore, use crossterm ^12 because TUI requires types from ^0.9
  • You probably don't want to have a dependency to git branch of TUI

The real blocker here was that crossterm::KeyEvent did not implement Copy and therefore it has to be wrapped in order for it to be used.

Introduced:

  1. Key enum, this enum is used in the library and should be used instead of the termion::Key or crossterm::KeyEvent or others toughtout the crates. You probably don't want to depend on a certain library restricted to linux but have a small abstraction so that crossterm, for example, can be implemented with more ease.
  2. CrosstermBackend this uses crossterm for its implementation and is crossplatform.

Qustions:

This is just an experiment because I wanted to listen to Spotify on windows, however, there are some concerns with git dependencies and old versions of crossterm. Do you think crossterm should be behind a feature flag, the only supported implementation, or not used at all?

@TimonPost
Copy link
Contributor Author

I tried this app out, however something went wrong with my authentication URL redirect. Not sure if anything went wrong with this implementation or authentication.

@Rigellute
Copy link
Owner

Thanks for looking into this @TimonPost! This is great work, I'd love for spotify-tui to support Windows natively.

I think your Key abstraction is a good idea.

To respond to your questions above,

  1. I would certainly prefer to use crate releases and not use git as the dependancy manager here.
  2. If Crossterm delivers that same experience for all platforms as what we have already for macOS and Linux then it should be the only supported implementation, just to keep things simple.

I'm now thinking that we should wait for/push tui-rs to upgrade their crossterm dependancy to 0.12. And/or also wait for crossterm to support Copy (if that's still an issue).

But sounds like we're pretty close to supporting Windows, so once again thank you for this investigation!

@TimonPost
Copy link
Contributor Author

left an issue here: fdehau/tui-rs#192

@TimonPost TimonPost changed the title [wip] windows support [wip] Crossterm 0.14 and TUI 0.8 Dec 13, 2019
@TimonPost
Copy link
Contributor Author

I updated to the newest version of crossterm 0.14. We will have to wait for TUI to merge and release this branch. Then this PR can finally be merged.

@TimonPost
Copy link
Contributor Author

TimonPost commented Dec 13, 2019

Windows Powershell
image

@TimonPost TimonPost changed the title [wip] Crossterm 0.14 and TUI 0.8 Implemented windows support with crossterm. Dec 16, 2019
@TimonPost TimonPost changed the title Implemented windows support with crossterm. Using cossterm for windows support. Dec 16, 2019
@TimonPost
Copy link
Contributor Author

LINUX MINT
image

@TimonPost
Copy link
Contributor Author

  • Remove /src/utils.rs, moved logic to /events/*
  • Created Key enum to be decoupled from external libraries.
  • Implemented crossterm for UI driver.
  • Upgraded to TUI 0.8 needed for crossterm 0.14 support.

@TimonPost
Copy link
Contributor Author

Debian:
image

Copy link
Owner

@Rigellute Rigellute left a comment

Choose a reason for hiding this comment

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

Incredible work @TimonPost!

Looking forward to trying this out!

.idea/vcs.xml Outdated
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Owner

Choose a reason for hiding this comment

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

Are you able to remove the .idea directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly.

Copy link
Owner

@Rigellute Rigellute left a comment

Choose a reason for hiding this comment

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

Just tested this PR on macOS and all looks good!

Perhaps we could merge your other PR merging the imports first?

We can then finally rebase this PR and it should be ready to merge to master!

@TimonPost
Copy link
Contributor Author

TimonPost commented Dec 23, 2019

Nice, merging #190 sounds like a good idea. I made that one because this one accidentally included those changes as well. By merging that one, we can reduce the number of changes, which will make it a bit easier to see what the actual changes are. I will do a rebase once that one is merged.

@TimonPost TimonPost force-pushed the crossterm_impl branch 2 times, most recently from ea351ca to 57170ad Compare December 24, 2019 14:07
- Remove Termion dependency
- Use crossterm feature flag TUI
- Added event module, for event handling behaviour.
- Implemented crossterm 0.14.
@TimonPost
Copy link
Contributor Author

I rebased and removed the idea files. It should be ready to be merged.

@TimonPost TimonPost closed this Dec 24, 2019
@TimonPost TimonPost reopened this Dec 24, 2019
Copy link
Owner

@Rigellute Rigellute left a comment

Choose a reason for hiding this comment

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

Incredible work @TimonPost!

Thank you 👍.

It is so awesome that spotify-tui will now work on Windows!

@Rigellute Rigellute merged commit a9db66b into Rigellute:master Dec 24, 2019
@Rigellute
Copy link
Owner

Rigellute commented Dec 24, 2019

@TimonPost have run into a problem after merging - pressing ctrl-c to quit, causes an error

Error: RecvError

Which then crashes that terminal session.

Any ideas?

Will revert until this is ironed out.

@TimonPost
Copy link
Contributor Author

TimonPost commented Dec 24, 2019

ctrl-c stops the event reading loop. When this happens, the thread will finish, and the sender's side will be disposed of. If there is no sender, then the receiving side will error.

First, this wasn't the case, because the ticking thread also had a clone of the sender: https://github.com/Rigellute/spotify-tui/blob/master/src/util.rs#L55. However, crossterm can do both ticking and event reading in one thread. This sender can probably be kept as a local field in Events. That would keep the sender around even if the input reading threads stop.

This isn't a huge deal, I can look at this tomorrow.

@TimonPost
Copy link
Contributor Author

TimonPost commented Dec 24, 2019

Can you try this commit: TimonPost@ca32947

It did not work at my PC yet, going look into this a bit more tomorrow. However, you might give it a try.

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.

Windows Installation
2 participants