Comments (4)
It turns out it is possible to stay in raw mode by calling disable_drop()
on AlternateScreen
's Screen
like so:
...
{
let mut alternate_screen = screen.enable_alternate_modes(raw_mode).unwrap();
alternate_screen.screen.disable_drop();
crossterm = Crossterm::from_screen(&alternate_screen.screen);
}
// <-- Dropping alternate_screen here
...
However this feels like a bit of a hack. Alternate screen mode still breaks after the drop.
from crossterm.
- It is 'normal' behavior for an
AlternateScreen
to be switched back to mainscreen when it is dropped.AlternateScreen
is meant for quickly doing something and not have it open for a long time. So, for now, you are bounded to the scope in which you are allowed to use the alternate screen. - When
Screen
drops it will turn off the raw modes. There are usecases you don't want that from automatically happening so, therefore, you can calldisable_drop()
.
In the future, this might be more flexible and I will build in the functionality to have multiple screen buffers who have their own settings. You can be using lazy_static
this allows you to have your crossterm type living longer.
I get your argument that the user might be misled and I take a look to see if I can improve the docs here. Are there any problems you are encountering with otherwise I'll close this issue.
from crossterm.
Thanks for the quick reply. I think AlternateScreen
's behavior make sense and isn't the issue here. What threw me off is that if I create a Crossterm
instance from an AlternateScreen
's screen, the Crossterm
instance 's behavior depends on whether the AlternateScreen
has been dropped or not. I'm not very familiar with your code, but it looks like AlternateScreen
and Crossterm
share ownership of the TerminalOutput
via Arc
's, so they can both mutate it at will. In the worst case scenario you could create a Crossterm
instance from an AlternateScreen
's screen, send the AlternateScreen
to whatever thread you like and use it to manipulate the screen, until you eventually drop it. The Crossterm
could be doing the same in a completely different part of your code and work as expected, until the AlternateScreen
drops and the behavior suddenly changes. It would be extremely difficult to figure out where this change comes from without going through the source, because it has nothing to do with what you do to the Crossterm
locally.
Given that Crossterm
seems to be a convenience wrapper, could it consume an AlternateScreen
so that there's only one place to change behavior? Alternatively, could Crossterm
retain a reference to AlternateScreen
, making sure they're used in the same place?
Edit: Consuming the AlternateScreen
seems preferable because the lack of self-referential structs means the AlternateScreen
and Crossterm
couldn't be held in the same struct.
from crossterm.
closing this, because it is answered if you have any more question feel free to reopen.
from crossterm.
Related Issues (20)
- Support OSC 52 for clipboard interraction HOT 1
- Support win32-input-mode
- `crossterm::event::poll` function fails on macOS with a timeout larger than 100 million seconds
- serde support for Attributes
- add support for win32-input-mode
- Synchronized Update doesn't work on Windows
- Support Pixel Coordinates in Mouse Events HOT 1
- Macros to reduce the syntactic burden of parsing events HOT 4
- Mouse down event isn't registered when it happened shortly after another click (double click)
- Document buffering behavior for events
- inconsistent and incorrect touch behaviour HOT 1
- available_color_count is wrong on Windows HOT 1
- Build break from #862
- Build error with use-dev-tty HOT 5
- * `use-dev-tty` is useless without `events`
- crossterm::terminal::size() returns Ok((0, 0)) in eshell
- Capture additional keys (Media keys, caps lock, etc.)
- Feature request: uefi support
- Can not capture `MediaKeyCode`s
- Color names
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crossterm.