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



16
17
18
19
20
# File 'lib/sup/buffer.rb', line 16

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

.curxObject



22
23
24
25
26
# File 'lib/sup/buffer.rb', line 22

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

.mutexObject



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

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

.nonblocking_getchObject

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



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

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



10
11
12
13
14
# File 'lib/sup/buffer.rb', line 10

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

.safe_nonblocking_getchObject

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



50
51
52
53
54
# File 'lib/sup/buffer.rb', line 50

def safe_nonblocking_getch
  nonblocking_getch
rescue Interrupt
  KEY_CANCEL
end

.sync(&b) ⇒ Object



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

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