Giter VIP home page Giter VIP logo

Comments (3)

mcormier avatar mcormier commented on August 24, 2024

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.

shugo avatar shugo commented on August 24, 2024

@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.

shugo avatar shugo commented on August 24, 2024

@mcormier

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)

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.