-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e6d070
commit ba42e88
Showing
3 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
#!/usr/bin/env ruby | ||
require_relative "../lib/firew0rks.rb" | ||
require 'reline' | ||
require_relative "../lib/firew0rks" | ||
require_relative "../lib/firew0rks/terminal" | ||
|
||
terminal = Reline::ANSI.new | ||
terminal.hide_cursor | ||
def setup | ||
Terminal.open_buffer | ||
Terminal.hide_cursor | ||
Terminal.clear_screen | ||
end | ||
|
||
def clean_up | ||
Terminal.close_buffer | ||
Terminal.clear_screen | ||
Terminal.show_cursor | ||
end | ||
|
||
trap("INT") { | ||
terminal.show_cursor | ||
clean_up | ||
puts "" | ||
puts "Bye." | ||
exit 0 | ||
} | ||
|
||
|
||
begin | ||
setup | ||
Fireworks.new.run | ||
rescue => error | ||
puts error | ||
ensure | ||
terminal.show_cursor | ||
clean_up | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ANSI_escape_code | ||
# Ref: https://xn--rpa.cc/irl/term.html | ||
# https://en.wikipedia.org/wiki/ANSI_escape_code#CSIsection | ||
|
||
class Terminal | ||
class << self | ||
|
||
def clear_buffer | ||
print "\x1b[3J" | ||
end | ||
|
||
def clear_screen | ||
print "\x1b[2J" | ||
end | ||
|
||
def hide_cursor | ||
print "\x1b[?25l" | ||
end | ||
|
||
def show_cursor | ||
print "\x1b[?25h" | ||
end | ||
|
||
def open_buffer | ||
# 打开特殊缓存 | ||
print "\x1b[?1049h" | ||
end | ||
|
||
def close_buffer | ||
# 关闭特殊缓存 | ||
print "\x1b[?1049l" | ||
end | ||
end | ||
end |