Skip to content

Commit

Permalink
Change the Screen module to improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Dec 16, 2023
1 parent 720ef3b commit 7d5e2de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/tty-screen.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require_relative 'tty/screen'
require_relative "tty/screen"
15 changes: 8 additions & 7 deletions lib/tty/screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,20 @@ def size_from_win_api(verbose: false)
require "fiddle" unless defined?(Fiddle)

kernel32 = Fiddle::Handle.new("kernel32")
get_std_handle = Fiddle::Function.new(kernel32["GetStdHandle"],
[-Fiddle::TYPE_INT], Fiddle::TYPE_INT)
get_std_handle = Fiddle::Function.new(
kernel32["GetStdHandle"], [-Fiddle::TYPE_INT], Fiddle::TYPE_INT)
get_console_buffer_info = Fiddle::Function.new(
kernel32["GetConsoleScreenBufferInfo"],
[Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT)

format = "SSSSSssssSS"
buffer = ([0] * format.size).pack(format)
format = "SSSSSssssSS"
buffer = ([0] * format.size).pack(format)
stdout_handle = get_std_handle.(STDOUT_HANDLE)

get_console_buffer_info.(stdout_handle, buffer)
_, _, _, _, _, left, top, right, bottom, = buffer.unpack(format)
size = [bottom - top + 1, right - left + 1]
return size if nonzero_column?(size[1] - 1)
size if nonzero_column?(size[1] - 1)
rescue LoadError
warn "no native fiddle module found" if verbose
rescue Fiddle::DLError
Expand All @@ -158,7 +158,7 @@ def size_from_java(verbose: false)
java_import "jline.TerminalFactory"
terminal = TerminalFactory.get
size = [terminal.get_height, terminal.get_width]
return size if nonzero_column?(size[1])
size if nonzero_column?(size[1])
rescue
warn "failed to import java terminal package" if verbose
end
Expand Down Expand Up @@ -332,7 +332,8 @@ def command_exist?(command)
exts = env.fetch("PATHEXT", "").split(::File::PATH_SEPARATOR)
env.fetch("PATH", "").split(::File::PATH_SEPARATOR).any? do |dir|
file = ::File.join(dir, command)
::File.exist?(file) || exts.any? { |ext| ::File.exist?("#{file}#{ext}") }
::File.exist?(file) ||
exts.any? { |ext| ::File.exist?("#{file}#{ext}") }
end
end
private_module_function :command_exist?
Expand Down
2 changes: 1 addition & 1 deletion lib/tty/screen/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# fronzen_string_literal: true
# frozen_string_literal: true

module TTY
module Screen
Expand Down

0 comments on commit 7d5e2de

Please sign in to comment.