Module: AsciinemaWin::Win32Screen
- Extended by:
- Fiddle::Importer
- Defined in:
- lib/asciinema_win/win32_screen.rb
Overview
Reads the live contents (characters + attributes) of the Windows console screen buffer, for the recorder’s frame-capture loop.
This intentionally lives in asciinema_win rather than in the vendored Rich library: it is a recording concern, not a text-formatting one, and keeping it here means re-vendoring an updated Rich can never silently drop it (which is exactly how recording broke before). For the handle and buffer geometry it reuses the public Rich::Win32Console helpers; it only binds the two cell-reading functions Rich does not expose.
Class Method Summary collapse
-
.capture ⇒ Hash?
Capture the visible region of the console screen buffer.
Class Method Details
.capture ⇒ Hash?
Capture the visible region of the console screen buffer.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/asciinema_win/win32_screen.rb', line 44 def capture return nil unless Gem.win_platform? handle = Rich::Win32Console.stdout_handle return nil unless handle info = Rich::Win32Console.get_screen_buffer_info(handle) return nil unless info win = info[:window] left = win[:left] top = win[:top] width = win[:right] - left + 1 height = win[:bottom] - top + 1 return nil if width <= 0 || height <= 0 lines = Array.new(height) do |row| read_line(handle, left, top + row, width) end cursor = info[:cursor_position] { width: width, height: height, cursor_x: [cursor[:x] - left, 0].max, cursor_y: [cursor[:y] - top, 0].max, lines: lines } end |