GithubHelp home page GithubHelp logo

Shutdown CTRL+C about text-io HOT 5 CLOSED

beryx avatar beryx commented on August 25, 2024
Shutdown CTRL+C

from text-io.

Comments (5)

siordache avatar siordache commented on August 25, 2024

Currently, text-io expects only regular text as input. For key combinations such as Ctrl+C the behavior is unspecified and it depends on the underlying TextTerminal implementation.
For Swing, Ctrl+C is by default associated with "copy".
Using Ctrl+C with a SystemTextTerminal or a ConsoleTextTerminal will shut down the JVM.
Note however, that (since version 1.5.0) TextIoFactory usually returns a JLineTextTerminal if System.console() is not null. JLineTextTerminal currently ignores the Ctrl+C, but this behavior can be easily changed by executing: reader.setHandleUserInterrupt(true); I should probably insert this statement in the JLineTextTerminal constructor.

from text-io.

kirpi4ik avatar kirpi4ik commented on August 25, 2024

Thanks for explanation, make sense. Although maybe would be nice to have some generic key listener I know that it would be hard for non-GUI console without jna.
For SwingTextTerminal instance for now probably I can just add custom event dispatcher

from text-io.

kirpi4ik avatar kirpi4ik commented on August 25, 2024

btw, why the console would forbid closing the window, I would expect that terminal should have common or similar behavior for all implementations ?
https://github.com/beryx/text-io/blob/master/text-io/src/main/java/org/beryx/textio/swing/SwingTextTerminal.java#L139

from text-io.

siordache avatar siordache commented on August 25, 2024

I added support for handling user interrupts. For the Swing and the Web text terminal, Ctrl+Q is used by default to trigger a user interrupt. (I didn't use Ctrl+C, because it is usually associated with copy in these environments.) The key combination that triggers a user interrupt can be changed programmatically.
Closing the Swing window will also trigger a user interrupt.

The default user interrupt handler shuts down the JVM. A different handler can be configured by calling registerUserInterruptHandler(). See the commented lines in TextIoDemo for examples.

from text-io.

siordache avatar siordache commented on August 25, 2024

Implemented in 1.9.0.
Configuration improvements (using terminal properties) in 2.0.0.

from text-io.

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.