Giter VIP home page Giter VIP logo

Comments (4)

defiori avatar defiori commented on July 24, 2024

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.

TimonPost avatar TimonPost commented on July 24, 2024
  1. 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.
  2. 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 call disable_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.

defiori avatar defiori commented on July 24, 2024

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.

TimonPost avatar TimonPost commented on July 24, 2024

closing this, because it is answered if you have any more question feel free to reopen.

from crossterm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.