Class: PPCurses::Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/ppcurses/Screen.rb

Overview

Screen initializes the Curses screen Pass a code block to the run method to start things

noinspection RubyResolve

Instance Method Summary collapse

Instance Method Details

#addstr(string) ⇒ Object



117
118
119
# File 'lib/ppcurses/Screen.rb', line 117

def addstr(string)
  Curses.stdscr.addstr(string)
end

#attroff(attributes) ⇒ Object



113
114
115
# File 'lib/ppcurses/Screen.rb', line 113

def attroff(attributes)
  Curses.stdscr.attroff(attributes)
end

#attron(attributes) ⇒ Object



109
110
111
# File 'lib/ppcurses/Screen.rb', line 109

def attron(attributes)
  Curses.stdscr.attron(attributes)
end

#clrtoeolObject



105
106
107
# File 'lib/ppcurses/Screen.rb', line 105

def clrtoeol
  Curses.stdscr.clrtoeol
end

#cur_pointObject



125
126
127
# File 'lib/ppcurses/Screen.rb', line 125

def cur_point
  PPCurses::Point.new(Curses.stdscr.curx, Curses.stdscr.cury)
end

#curs_set(value) ⇒ Object



129
130
131
# File 'lib/ppcurses/Screen.rb', line 129

def curs_set(value)
  Curses.curs_set(value)
end

#get_chObject



85
86
87
# File 'lib/ppcurses/Screen.rb', line 85

def get_ch
  Curses.stdscr.getch
end

#getchObject



121
122
123
# File 'lib/ppcurses/Screen.rb', line 121

def getch
  Curses.stdscr.getch
end

#heightObject



93
94
95
# File 'lib/ppcurses/Screen.rb', line 93

def height
  Curses.lines
end


79
80
81
82
83
# File 'lib/ppcurses/Screen.rb', line 79

def print_with_attribute( toPrint, attribute )
  Curses.stdscr.attron( attribute )
  Curses.stdscr.addstr( toPrint )
  Curses.stdscr.attroff( attribute )
end

#runObject

Creates a curses session

Example:

>> myScreen.run { displayMenu() }


143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ppcurses/Screen.rb', line 143

def run
  begin
    setup_curses

    return yield
    
  rescue SystemExit, Interrupt
    # Empty Catch block so ruby doesn't puke out
    # a stack trace when CTRL-C is used
  ensure
     shutdown_curses
  end
end

#set_pos_by_point(p) ⇒ Object



97
98
99
# File 'lib/ppcurses/Screen.rb', line 97

def set_pos_by_point( p )
  setpos(p.y, p.x)
end

#setpos(y, x) ⇒ Object



101
102
103
# File 'lib/ppcurses/Screen.rb', line 101

def setpos(y, x)
  Curses.stdscr.setpos(y, x)
end

#setup_cursesObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ppcurses/Screen.rb', line 57

def setup_curses
  Curses.init_screen
  Curses.raw

  # Can't implement regardless as this can cause an unsupportedOperationException on some configurations
  #  like cygwin.
  if OS.unix?
    Curses.ESCDELAY=0
  end


  #  Otherwise arrow keys, etc can't be read from the main screen and cause the
  #  program to stop.
  Curses.stdscr.keypad(true)

  Curses.clear
  Curses.curs_set(INVISIBLE)
  Curses.noecho
  Curses.cbreak
  Curses.start_color
end

#shutdown_cursesObject



134
135
136
# File 'lib/ppcurses/Screen.rb', line 134

def shutdown_curses
  Curses.close_screen
end

#widthObject



89
90
91
# File 'lib/ppcurses/Screen.rb', line 89

def width
  Curses.cols
end