Class: Rfd::CommandLineWindow

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

Instance Method Summary collapse

Methods inherited from Window

draw_borders, #writeln

Constructor Details

#initializeCommandLineWindow

Returns a new instance of CommandLineWindow.



140
141
142
# File 'lib/rfd/windows.rb', line 140

def initialize
  super maxy: 1, maxx: Curses.cols, begy: Curses.lines - 1, begx: 0
end

Instance Method Details

#get_command(prompt: nil, default: nil) ⇒ Object



181
182
183
184
185
186
# File 'lib/rfd/windows.rb', line 181

def get_command(prompt: nil, default: nil)
  startx = prompt ? prompt.size : 1
  setpos 0, startx
  s = getstr_with_echo default
  "#{prompt[1..-1] if prompt}#{s.strip}"
end

#getstr_with_echo(default = nil) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/rfd/windows.rb', line 150

def getstr_with_echo(default = nil)
  str = default || ''.dup

  unless str.empty?
    self << str
    refresh
  end

  loop do
    case (c = Curses.getch)
    when 27, 3  # ESC, C-c
      raise Interrupt
    when 10, 13
      break
    when 127, 263  # delete
      raise Interrupt if curx == 1

      setpos cury, curx - 1
      delch
      refresh
      str.chop!
    else
      Rfd.log "#{__method__}: #{c}"
      self << c
      refresh
      str << c
    end
  end
  str
end

#set_prompt(str) ⇒ Object



144
145
146
147
148
# File 'lib/rfd/windows.rb', line 144

def set_prompt(str)
  attron(Curses.color_pair(Curses::COLOR_WHITE) | Curses::A_BOLD) do
    writeln 0, str
  end
end

#show_error(str) ⇒ Object



188
189
190
191
192
193
# File 'lib/rfd/windows.rb', line 188

def show_error(str)
  attron(Curses.color_pair(Curses::COLOR_RED) | Curses::A_BOLD) do
    writeln 0, str
  end
  noutrefresh
end