<commit_before>package termboxUI

import (
	"bufio"
	"io"
	"strings"

	"github.com/nsf/termbox-go"
)

//======================================================//
// Useful Functions
//======================================================//

// This fills all of the cells of the terminal within a given rectangle to the specified attributes.
func FillArea(x, y, w, h int, fg, bg termbox.Attribute) {
	for row := 0; row < h; row++ {
		for column := 0; column < w; column++ {
			termbox.SetCell(x+column, y+row, ' ', fg, bg)
		}
	}
	return
}

// Draws a line to the terminal starting with the cell located at 'x' and continuing to the cell at 'w'
// Cells 'x' and 'w' are included.
func DrawHorizontalLine(x, y, w int, fg, bg termbox.Attribute) {
	for i := 0; i <= w; i++ {
		termbox.SetCell(x+i, y, '─', fg, bg)
	}
	return
}

// Draws a line to the terminal starting with the cell located at 'y' and continuing to the cell at 'h'
// Cells 'y' and 'h' are included.
func DrawVerticalLine(x, y, h int, fg, bg termbox.Attribute) {
	for i := 0; i <= h; i++ {
		termbox.SetCell(x, y+i, '│', fg, bg)
	}
	return
}

// Like FillArea, but it also draws a border around the area using the 'fg' attribute as the color.
func DrawRectangle(x, y, h, w int, fg, bg termbox.Attribute) {
	FillArea(x, y, w, h, fg, bg)
	DrawHorizontalLine(x, y, w, fg, bg)   // top
	DrawHorizontalLine(x, h+y, w, fg, bg) // bottom
	DrawVerticalLine(x, y, h, fg, bg)     // left
	DrawVerticalLine(w, y, h, fg, bg)     // right
	termbox.SetCell(x, y, '┌', fg, bg)    // top-left corner
	termbox.SetCell(w, y, '┐', fg, bg)    // top-right corner
	termbox.SetCell(x, h+y, '└', fg, bg)  // bottom-left corner
	termbox.SetCell(w, h+y, '┘', fg, bg)  // bottom-right corner
}

//======================================================//
// Basic Text
//======================================================//

// This is the most basic text drawing function.
// It writes a single line of text to the terminal with the specified settings.
func DrawText(x, y int, line string, fg, bg termbox.Attribute) (int, int) {
	for i, ch := range line {
		termbox.SetCell(x+i, y, ch, fg, bg)
	}
	return x + len(line), y
}

// This returns the termbox x coordinate to center the given string within the described area.
// That coordinate value returned should be referenced before drawing the text.
// Note that this doesn't actually draw the text string to the terminal.
func HorizontalCenterString(text string, dimension, offset int) int {
	return (dimension-len(text))/2 + offset
}

//======================================================//
// Text Box
//======================================================//

// Values for passing in text alignment for text boxes.
// TexAlignmentDefault can be used in both vertical and horizontal cases when drawing the text box to the terminal.<commit_msg>Issue #7: small bug in rectangle right border<commit_after>package termboxUI

import (
	"bufio"
	"io"
	"strings"

	"github.com/nsf/termbox-go"
)

//======================================================//
// Useful Functions
//======================================================//

// This fills all of the cells of the terminal within a given rectangle to the specified attributes.
func FillArea(x, y, w, h int, fg, bg termbox.Attribute) {
	for row := 0; row < h; row++ {
		for column := 0; column < w; column++ {
			termbox.SetCell(x+column, y+row, ' ', fg, bg)
		}
	}
	return
}

// Draws a line to the terminal starting with the cell located at 'x' and continuing to the cell at 'w'
// Cells 'x' and 'w' are included.
func DrawHorizontalLine(x, y, w int, fg, bg termbox.Attribute) {
	for i := 0; i <= w; i++ {
		termbox.SetCell(x+i, y, '─', fg, bg)
	}
	return
}

// Draws a line to the terminal starting with the cell located at 'y' and continuing to the cell at 'h'
// Cells 'y' and 'h' are included.
func DrawVerticalLine(x, y, h int, fg, bg termbox.Attribute) {
	for i := 0; i <= h; i++ {
		termbox.SetCell(x, y+i, '│', fg, bg)
	}
	return
}

// Like FillArea, but it also draws a border around the area using the 'fg' attribute as the color.
func DrawRectangle(x, y, h, w int, fg, bg termbox.Attribute) {
	FillArea(x, y, w, h, fg, bg)
	DrawHorizontalLine(x, y, w, fg, bg)    // top
	DrawHorizontalLine(x, h+y, w, fg, bg)  // bottom
	DrawVerticalLine(x, y, h, fg, bg)      // left
	DrawVerticalLine(x+w, y, h, fg, bg)    // right
	termbox.SetCell(x, y, '┌', fg, bg)     // top-left corner
	termbox.SetCell(x+w, y, '┐', fg, bg)   // top-right corner
	termbox.SetCell(x, h+y, '└', fg, bg)   // bottom-left corner
	termbox.SetCell(x+w, h+y, '┘', fg, bg) // bottom-right corner
}

//======================================================//
// Basic Text
//======================================================//

// This is the most basic text drawing function.
// It writes a single line of text to the terminal with the specified settings.
func DrawText(x, y int, line string, fg, bg termbox.Attribute) (int, int) {
	for i, ch := range line {
		termbox.SetCell(x+i, y, ch, fg, bg)
	}
	return x + len(line), y
}

// This returns the termbox x coordinate to center the given string within the described area.
// That coordinate value returned should be referenced before drawing the text.
// Note that this doesn't actually draw the text string to the terminal.
func HorizontalCenterString(text string, dimension, offset int) int {
	return (dimension-len(text))/2 + offset
}

//======================================================//
// Text Box
//======================================================//

// Values for passing in text alignment for text boxes.
// TexAlignmentDefault can be used in both vertical and horizontal cases when drawing the text box to the terminal.
{'fraction_non_alphanumeric': 0.23594132029339854, 'fraction_numerical': 0.0019210618232623122, 'mean_word_length': 3.764559068219634, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '577195', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1820, 'n_words': 716}