Module: SnippetCli::CursorHelper

Defined in:
lib/snippet_cli/cursor_helper.rb

Overview

Utility for TTY cursor manipulation.

Class Method Summary collapse

Class Method Details

.build_erase_lambda(line_count) ⇒ Object

Returns a lambda that erases ‘line_count` lines upward when called. Returns a no-op lambda when stdout is not a TTY.



10
11
12
13
14
15
16
17
18
# File 'lib/snippet_cli/cursor_helper.rb', line 10

def self.build_erase_lambda(line_count)
  return -> {} unless $stdout.tty?

  lambda {
    $stdout.print TTY::Cursor.up(line_count)
    $stdout.print "\r"
    $stdout.print TTY::Cursor.clear_screen_down
  }
end