Class: RuVim::Terminal
- Inherits:
-
Object
- Object
- RuVim::Terminal
- Defined in:
- lib/ruvim/terminal.rb
Instance Method Summary collapse
-
#initialize(stdin: STDIN, stdout: STDOUT) ⇒ Terminal
constructor
A new instance of Terminal.
- #suspend_for_shell(command) ⇒ Object
- #suspend_for_tstp ⇒ Object
- #winsize ⇒ Object
- #with_ui ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(stdin: STDIN, stdout: STDOUT) ⇒ Terminal
Returns a new instance of Terminal.
7 8 9 10 |
# File 'lib/ruvim/terminal.rb', line 7 def initialize(stdin: STDIN, stdout: STDOUT) @stdin = stdin @stdout = stdout end |
Instance Method Details
#suspend_for_shell(command) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruvim/terminal.rb', line 32 def suspend_for_shell(command) shell = ENV["SHELL"].to_s shell = "/bin/sh" if shell.empty? @stdin.cooked do write("\e[0 q\e[?25h\e[?1049l") system(shell, "-c", command) status = $? write("\r\nPress ENTER or type command to continue") @stdin.raw { @stdin.getc } write("\e[2 q\e[?1049h\e[?25l") status end end |
#suspend_for_tstp ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruvim/terminal.rb', line 46 def suspend_for_tstp prev_tstp = Signal.trap("TSTP", "DEFAULT") @stdin.cooked do write("\e[0 q\e[?25h\e[?1049l") Process.kill("TSTP", 0) end ensure begin Signal.trap("TSTP", prev_tstp) if defined?(prev_tstp) rescue StandardError nil end write("\e[2 q\e[?1049h\e[?25l") end |
#winsize ⇒ Object
12 13 14 15 16 |
# File 'lib/ruvim/terminal.rb', line 12 def winsize IO.console.winsize rescue StandardError [24, 80] end |
#with_ui ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/ruvim/terminal.rb', line 23 def with_ui @stdin.raw do write("\e]112\a\e[2 q\e[?1049h\e[?25l") yield ensure write("\e[0 q\e[?25h\e[?1049l") end end |
#write(str) ⇒ Object
18 19 20 21 |
# File 'lib/ruvim/terminal.rb', line 18 def write(str) @stdout.write(str) @stdout.flush end |