Skip to content

Commit

Permalink
update: use Terminal proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark24Code committed Jan 3, 2025
1 parent 5e6d070 commit ba42e88
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
23 changes: 16 additions & 7 deletions exe/firew0rks
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
5 changes: 3 additions & 2 deletions lib/firew0rks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative "firew0rks/version"
require_relative "firew0rks/frame"
require_relative "firew0rks/error"
require_relative "firew0rks/terminal"


class Fireworks
Expand All @@ -14,7 +15,7 @@ def initialize


def clear_screen
$stdout.clear_screen
Terminal.clear_buffer
end

def init_screen
Expand All @@ -27,7 +28,7 @@ def render
if !@first_frame
$stdout.print @backspace_adjust
end

clear_screen
$stdout.print content
@first_frame = false
sleep(0.05)
Expand Down
34 changes: 34 additions & 0 deletions lib/firew0rks/terminal.rb
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

0 comments on commit ba42e88

Please sign in to comment.