Comments (3)
I ported the code from William Morgan's 2009 blog post. The following code proves that yes, getch is blocking.
require 'curses'
require 'thread'
Thread.new do
sleep 0.1
Curses.stdscr.setpos(0, 0)
Curses.stdscr.addstr('library is GOOD')
end
Curses.init_screen
Curses.raw
Curses.clear
Curses.curs_set(0)
Curses.noecho
Curses.cbreak
Curses.start_color
Curses.stdscr.setpos(0, 0)
Curses.stdscr.addstr('library is BAD')
Curses.stdscr.getch
Curses.close_screen
from curses.
@mcormier You need to refresh the screen as follows:
Thread.new do
sleep 0.1
Curses.stdscr.setpos(0, 0)
Curses.stdscr.addstr('library is GOOD')
Curses.stdscr.refresh
end
You don't need to handle SIGWINCH on you own because getch returns
Curses::KEY_RESIZE when SIGWINCH is detected.
from curses.
def size_changed # TODO -- notify all size changed listeners @listeners.each { |listener| #listener.screen_size_changed } end begin Signal.trap('SIGWINCH', size_changed )
The code doesn't work because size_changed is called at the time when Signal.trap is called,
not when the signal is received.
Try the following code:
def size_changed(sig)
# TODO -- notify all size changed listeners
@listeners.each { |listener|
#listener.screen_size_changed
}
end
begin
Signal.trap('SIGWINCH', method(:size_changed))
Or more simply:
begin
Signal.trap('SIGWINCH') do
...
end
from curses.
Related Issues (20)
- Pass ansi color codes straight through to a curses window? HOT 2
- Compatibility with Ruby 2.7 on Windows HOT 3
- Documentation is incomplete
- Curses::addch doesn't support attributes HOT 2
- Support for chgat?
- Not Displaying Wide Characters HOT 2
- Curses versus Ncurses confusion HOT 2
- Are some files missing on the .gem release? HOT 2
- Encoding issues HOT 1
- Curses.get_char fails on multibyte characters HOT 2
- sample/color.rb error HOT 15
- error: unknown warning option '-Wno-cast-function-type'; did you mean '-Wno-bad-function-cast'? [-Werror,-Wunknown-warning-option]
- Gem document is incomplete and lack of examples.
- Use NUM2CHTYPE()/CHTYPE2NUM() in window_attron/attroff/attrset/color_pair?
- gem installation warning: "Couldn't find file to include xyz" HOT 1
- 256 colours support in ncurses?
- I think there is an error in https://github.com/ruby/curses/blob/master/sample/form.rb HOT 1
- NCURSES_EXT_COLORS - see python HOT 2
- uninitialized constant Curses::Menu (NameError) HOT 3
- Does not compile and cannot be installed on macOS (Apple Silicon) HOT 17
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 curses.