Bruhffer¶

Copyright 2023 Ethan Christensen Copied, Guided, and Adapted from Asciimatics <https://github.com/peterbrittain/asciimatics/blob/master/asciimatics/screen.py>

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class bruhanimate.bruhutil.bruhffer.Buffer(height, width)[source]¶

Bases: object

Class for creating and managing a buffer

__init__(height, width)[source]¶
get_buffer_changes(in_buf)[source]¶

Compare this buffer with the given buffer and yield differences.

Parameters:

in_buf (Buffer) – The buffer to compare with.

Yields:

Tuple[int, int, str] –

A tuple containing the row index, column index,

and the character from the input buffer that differs.

clear_buffer(x=0, y=0, w=None, h=None, val=' ')[source]¶

Clear a section of the buffer with a specific character.

Parameters:
  • x (int) – The starting x-coordinate for the clear operation (default is 0).

  • y (int) – The starting y-coordinate for the clear operation (default is 0).

  • w (int, optional) – The width of the section to be cleared. If not specified, clears to the end of the buffer’s width.

  • h (int, optional) – The height of the section to be cleared. If not specified, clears to the end of the buffer’s height.

  • val (str) – The character to fill the cleared area with (default is a space).

get_char(x, y)[source]¶

Get the character at the specified location.

Parameters:
  • x (int) – The column index.

  • y (int) – The row index.

Returns:

The character at the specified location, or None if out of bounds.

Return type:

str or None

put_char(x, y, val, transparent=False)[source]¶

Place a character at the specified location.

Parameters:
  • x (int) – The column index.

  • y (int) – The row index.

  • val (str) – The character to place.

  • transparent (bool) – If True, only place non-space characters.

put_at(x, y, text, transparent=False)[source]¶

Place text starting at the specified location.

Parameters:
  • x (int) – The starting column index.

  • y (int) – The row index.

  • text (str) – The text to place.

  • transparent (bool) – If True, only place non-space characters.

put_at_center(y, text, transparent=False)[source]¶

Place text centered on the specified row.

Parameters:
  • y (int) – The row index to place the text.

  • text (str) – The text to place.

  • transparent (bool) – If True, only place non-space characters.

scroll(shift)[source]¶

Scroll the buffer up or down by a specified number of lines.

Parameters:

shift (int) – The number of lines to scroll. Positive scrolls up, negative scrolls down.

shift_line(y, shift)[source]¶

Shift the specified line to the right by a given amount. :param y: The index of the row to shift. :type y: int :param shift: The amount by which to shift the row. :type shift: int

shift(shift)[source]¶

Shift the entire buffer to the right by a specified amount. :param shift: The amount by which to shift each row. :type shift: int

grab_slice(x, y, width)[source]¶

Grab a segment from a specific row in the buffer.

Parameters:
  • x (int) – The starting column index for the slice.

  • y (int) – The row index from which to grab the slice.

  • width (int) – Number of characters to include in the slice.

Returns:

A list containing the specified segment of the row.

Return type:

list

sync_with(in_buf)[source]¶

Synchronize this buffer with another buffer. :param in_buf: The buffer to synchronize with. :type in_buf: Buffer

sync_over_top(in_buf)[source]¶

Overlay non-None values from another buffer onto this buffer.

Parameters:

in_buf (Buffer) – The buffer containing values to overlay.

height()[source]¶

Get the height of the buffer. :returns: The height of the buffer. :rtype: int

width()[source]¶

Get the width of the buffer.

Returns:

The width of the buffer.

Return type:

int