Module: Ncurses

Defined in:
lib/sup/buffer.rb

Constant Summary collapse

KEY_ENTER =
10
KEY_CANCEL =

ctrl-g

7
KEY_TAB =
9

Class Method Summary collapse

Class Method Details

.colsObject



14
15
16
17
18
# File 'lib/sup/buffer.rb', line 14

def cols
  lame, lamer = [], []
  stdscr.getmaxyx lame, lamer
  lamer.first
end

.curxObject



20
21
22
23
24
# File 'lib/sup/buffer.rb', line 20

def curx
  lame, lamer = [], []
  stdscr.getyx lame, lamer
  lamer.first
end

.mutexObject



26
# File 'lib/sup/buffer.rb', line 26

def mutex; @mutex ||= Mutex.new; end

.nonblocking_getchObject

magically, this stuff seems to work now. i could swear it didn’t before. hm.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sup/buffer.rb', line 31

def nonblocking_getch
  ## INSANTIY
  ## it is NECESSARY to wrap Ncurses.getch in a select() otherwise all
  ## background threads will be BLOCKED. (except in very modern versions
  ## of libncurses-ruby. the current one on ubuntu seems to work well.)
  if IO.select([$stdin], nil, nil, 0.5)
    if Redwood::BufferManager.shelled?
      # If we get input while we're shelled, we'll ignore it for the
      # moment and use Ncurses.sync to wait until the shell_out is done.
      Ncurses.sync { nil }
    else
      Ncurses.getch
    end
  end
end

.rowsObject



8
9
10
11
12
# File 'lib/sup/buffer.rb', line 8

def rows
  lame, lamer = [], []
  stdscr.getmaxyx lame, lamer
  lame.first
end

.safe_nonblocking_getchObject

pretends ctrl-c’s are ctrl-g’s



48
49
50
51
52
# File 'lib/sup/buffer.rb', line 48

def safe_nonblocking_getch
  nonblocking_getch
rescue Interrupt
  KEY_CANCEL
end

.sync(&b) ⇒ Object



27
# File 'lib/sup/buffer.rb', line 27

def sync &b; mutex.synchronize(&b); end