Class: EverydayCurses::MyCurses

Inherits:
Object
  • Object
show all
Includes:
CursesUtils
Defined in:
lib/everyday-curses/mycurses.rb

Constant Summary

Constants included from CursesUtils

CursesUtils::COLOR_TO_CURSES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CursesUtils

#add_color, #find_color

Constructor Details

#initialize(use_curses, linesh, linesf) ⇒ MyCurses

region External



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/everyday-curses/mycurses.rb', line 8

def initialize(use_curses, linesh, linesf)
  @use_curses = use_curses
  @linesh     = linesh
  @linesf     = linesf
  @colors     = []
  @headers    = []
  @bodies     = []
  @footers    = []
  @cur_l      = 0
  @max_l      = 0
  @ch         = nil
  setup_curses(linesf, linesh) if @use_curses
end

Instance Attribute Details

#bodiesObject

Returns the value of attribute bodies.



195
196
197
# File 'lib/everyday-curses/mycurses.rb', line 195

def bodies
  @bodies
end

#chObject (readonly)

endregion



194
195
196
# File 'lib/everyday-curses/mycurses.rb', line 194

def ch
  @ch
end

#footersObject

Returns the value of attribute footers.



195
196
197
# File 'lib/everyday-curses/mycurses.rb', line 195

def footers
  @footers
end

#headersObject

Returns the value of attribute headers.



195
196
197
# File 'lib/everyday-curses/mycurses.rb', line 195

def headers
  @headers
end

Instance Method Details

#body_live_append(str) ⇒ Object



113
114
115
116
# File 'lib/everyday-curses/mycurses.rb', line 113

def body_live_append(str)
  @padb << str
  padb_refresh
end

#clearObject



48
49
50
51
52
# File 'lib/everyday-curses/mycurses.rb', line 48

def clear
  @headers = []
  @bodies  = []
  @footers = []
end

#clear_chObject



92
93
94
95
96
97
# File 'lib/everyday-curses/mycurses.rb', line 92

def clear_ch
  read_ch
  while @ch == 10 || @ch == Curses::Key::ENTER || @ch == Curses::Key::UP || @ch == Curses::Key::DOWN
    read_ch
  end
end

#configure_cursesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/everyday-curses/mycurses.rb', line 33

def configure_curses
  @padh.keypad(true)
  @padh.clear
  @padh.nodelay = true
  @padb.keypad(true)
  @padb.clear
  @padb.nodelay = true
  @padf.keypad(true)
  @padf.clear
  @padf.nodelay = true
  Curses::cbreak
  Curses::start_color
  Curses::use_default_colors
end

#disposeObject



123
124
125
# File 'lib/everyday-curses/mycurses.rb', line 123

def dispose
  Curses::close_screen if @use_curses
end


118
119
120
121
# File 'lib/everyday-curses/mycurses.rb', line 118

def footer_live_append(str)
  @padf << str
  padf_refresh
end

#header_live_append(str) ⇒ Object



108
109
110
111
# File 'lib/everyday-curses/mycurses.rb', line 108

def header_live_append(str)
  @padh << str
  padh_refresh
end

#myprintsObject



54
55
56
# File 'lib/everyday-curses/mycurses.rb', line 54

def myprints
  @use_curses ? print_curses : print_normal
end


64
65
66
67
68
69
70
71
72
73
74
# File 'lib/everyday-curses/mycurses.rb', line 64

def print_curses
  resize_curses
  myprint(@headers.join("\n"), @padh)
  myprint(@bodies.join("\n"), @padb)
  myprint(@footers.join("\n"), @padf)
  update_max_l
  @cur_l = [@cur_l, @max_l].min
  padh_refresh
  padb_refresh
  padf_refresh
end


58
59
60
61
62
# File 'lib/everyday-curses/mycurses.rb', line 58

def print_normal
  @headers.each { |v| puts v }
  @bodies.each { |v| puts v }
  @footers.each { |v| puts v }
end

#read_chObject



88
89
90
# File 'lib/everyday-curses/mycurses.rb', line 88

def read_ch
  @ch = @padf.getch
end

#resize_cursesObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/everyday-curses/mycurses.rb', line 76

def resize_curses
  @padh.resize(@headers.count, Curses::cols)
  @padb.resize(@bodies.count, Curses::cols)
  @padf.resize(@footers.count, Curses::cols)
  @padh.clear
  @padb.clear
  @padf.clear
  @padh.setpos(0, 0)
  @padb.setpos(0, 0)
  @padf.setpos(0, 0)
end

#scroll_iterationObject



99
100
101
102
103
104
105
106
# File 'lib/everyday-curses/mycurses.rb', line 99

def scroll_iteration
  old_subpad_size = @subpad_size
  update_subpad_size
  update_max_l
  update_scroll(@subpad_size != old_subpad_size)
  sleep(0.05)
  read_ch
end

#setup_curses(linesf, linesh) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/everyday-curses/mycurses.rb', line 22

def setup_curses(linesf, linesh)
  Curses::noecho
  Curses::init_screen
  @subpad_start = linesh
  update_subpad_size
  @padh = Curses::Pad.new(linesh, Curses::cols)
  @padb = Curses::Pad.new(Curses::lines - linesh - linesf, Curses::cols)
  @padf = Curses::Pad.new(linesf, Curses::cols)
  configure_curses
end