Skip to content

Commit

Permalink
Hide cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
ceritium committed Mar 15, 2024
1 parent 47775ab commit b309519
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/flatito/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def call
end
end
end

ensure
renderer.ending
end

Expand Down
30 changes: 23 additions & 7 deletions lib/flatito/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def print_item(item, line_number_padding)
""
end

puts "#{line_number} #{matched_string(item.key)} #{value}\n"
puts "#{line_number} #{matched_string(item.key)} #{value}"
end

private
Expand Down Expand Up @@ -100,35 +100,51 @@ def ending
end

class Renderer::TTY < Base
CSI = "\e["
CLEAR_LINE = "#{CSI}K\e[0G".freeze
HIDE_CURSOR = "#{CSI}?25l".freeze
SHOW_CURSOR = "#{CSI}?25h".freeze

def initialize(options)
super
require "io/console"
end

def prepare
listen_for_stdout_width_change
hide_cursor
end

def print_file_progress(pathname)
print "\r #{truncate(pathname.to_s, stdout_width - 4)}#{erase_line}"
print truncate(pathname.to_s, stdout_width - 4)
clear_line
end

def print_pathname(pathname)
print erase_line
clear_line
super
end

def ending
print erase_line
clear_line
show_cursor
puts
end

private
def hide_cursor
print HIDE_CURSOR
end

def erase_line
"\e[K\e[0G"
def show_cursor
print SHOW_CURSOR
end

def clear_line
print CLEAR_LINE
end

private

def stdout_width
@stdout_width ||= stdout.winsize[1]
rescue StandardError
Expand Down

0 comments on commit b309519

Please sign in to comment.