mirror of
https://github.com/EnumeratedDev/typer.git
synced 2026-09-16 05:36:10 +00:00
68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package main
|
|
|
|
import "github.com/gdamore/tcell/v2"
|
|
|
|
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
|
|
row := y1
|
|
col := x1
|
|
for _, r := range []rune(text) {
|
|
s.SetContent(col, row, r, nil, style)
|
|
col++
|
|
if col >= x2 {
|
|
row++
|
|
col = x1
|
|
}
|
|
if row > y2 {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style) {
|
|
if y2 < y1 {
|
|
y1, y2 = y2, y1
|
|
}
|
|
if x2 < x1 {
|
|
x1, x2 = x2, x1
|
|
}
|
|
|
|
// Fill background
|
|
for row := y1; row <= y2; row++ {
|
|
for col := x1; col <= x2; col++ {
|
|
s.SetContent(col, row, ' ', nil, style)
|
|
}
|
|
}
|
|
|
|
// Draw borders
|
|
for col := x1; col <= x2; col++ {
|
|
s.SetContent(col, y1, tcell.RuneHLine, nil, style)
|
|
s.SetContent(col, y2, tcell.RuneHLine, nil, style)
|
|
}
|
|
for row := y1 + 1; row < y2; row++ {
|
|
s.SetContent(x1, row, tcell.RuneVLine, nil, style)
|
|
s.SetContent(x2, row, tcell.RuneVLine, nil, style)
|
|
}
|
|
|
|
// Only draw corners if necessary
|
|
if y1 != y2 && x1 != x2 {
|
|
s.SetContent(x1, y1, tcell.RuneULCorner, nil, style)
|
|
s.SetContent(x2, y1, tcell.RuneURCorner, nil, style)
|
|
s.SetContent(x1, y2, tcell.RuneLLCorner, nil, style)
|
|
s.SetContent(x2, y2, tcell.RuneLRCorner, nil, style)
|
|
}
|
|
|
|
drawText(s, x1+1, y1+1, x2-1, y2-1, style, " ")
|
|
}
|
|
|
|
func DeleteFromSlice[T any](slice []T, i int) []T {
|
|
if i >= len(slice) {
|
|
return slice
|
|
} else if i < 0 {
|
|
return slice
|
|
} else if i == len(slice)-1 {
|
|
return slice[:len(slice)-1]
|
|
} else {
|
|
return append(slice[:i], slice[i+1:]...)
|
|
}
|
|
}
|