Class: Rfd::Window

Inherits:
Curses::Window
  • Object
show all
Defined in:
lib/rfd/windows.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(maxy: nil, maxx: nil, begy: nil, begx: nil, window: nil) ⇒ Window

Returns a new instance of Window.



46
47
48
# File 'lib/rfd/windows.rb', line 46

def initialize(maxy: nil, maxx: nil, begy: nil, begx: nil, window: nil)
  super window || Curses.stdscr.subwin(maxy, maxx, begy, begx)
end

Class Method Details

.draw_bordersObject



6
7
8
9
10
11
12
13
# File 'lib/rfd/windows.rb', line 6

def self.draw_borders
  [[5, Curses.stdscr.maxx, 0, 0], [5, Curses.cols - 30, 0, 0], [Curses.stdscr.maxy - 5, Curses.stdscr.maxx, 4, 0]].each do |height, width, top, left|
    w = Curses.stdscr.subwin height, width, top, left
    w.bkgdset Curses.color_pair(Curses::COLOR_CYAN)
    draw_ncursesw_border(w, height, width)
    w.close
  end
end

.draw_ncursesw_border(window, height, width) ⇒ Object

Draw borders using ncursesw box drawing characters



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rfd/windows.rb', line 24

def self.draw_ncursesw_border(window, height, width)
  if ncursesw?
    # Use Unicode box drawing characters with ncursesw
    h_line = '' * (width - 2)
    window.setpos(0, 0)
    window.addstr("#{h_line}")

    (1..(height - 2)).each do |y|
      window.setpos(y, 0)
      window.addstr('')
      window.setpos(y, width - 1)
      window.addstr('')
    end

    window.setpos(height - 1, 0)
    window.addstr("#{h_line}")
  else
    # Fallback to standard box drawing for system ncurses
    window.box(0, 0)
  end
end

.ncursesw?Boolean

Detect if linked against ncursesw (not ncurses)

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/rfd/windows.rb', line 16

def self.ncursesw?
  return @ncursesw if defined?(@ncursesw)

  bundle = $LOADED_FEATURES.find { |f| f =~ /curses\.bundle|curses\.so/ }
  @ncursesw = bundle && `otool -L "#{bundle}" 2>/dev/null`.include?('libncursesw')
end

Instance Method Details

#writeln(row, str) ⇒ Object



50
51
52
53
54
55
# File 'lib/rfd/windows.rb', line 50

def writeln(row, str)
  setpos row, 0
  clrtoeol
  self << str
  refresh
end