After commit c018f5fd29 Fenrir is being switched over to go. If you do not want to be part of the testing process, please switch to master.
This commit is contained in:
1 parent
c018f5fd29
commit
0e50de4c76
1047 files changed
+58364
-63747
No files matched your search
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package screen
|
||||
|
||||
import "strings"
|
||||
|
||||
// Region uses inclusive screen-cell coordinates, independently of text width
|
||||
// in bytes. ToLineEnd follows the current right edge when the terminal resizes.
|
||||
// Other coordinates stay fixed and are clipped only while reading/filtering.
|
||||
type Region struct {
|
||||
Left, Top, Right, Bottom int
|
||||
ToLineEnd bool
|
||||
}
|
||||
|
||||
func (r Region) Right_edge(cols int) int {
|
||||
if r.ToLineEnd {
|
||||
return cols - 1
|
||||
}
|
||||
return min(r.Right, cols-1)
|
||||
}
|
||||
|
||||
func (r Region) Contains(x, y, cols int) bool {
|
||||
return x >= r.Left && x <= r.Right_edge(cols) && y >= r.Top && y <= r.Bottom
|
||||
}
|
||||
|
||||
func (r Region) Text(s Snapshot) string {
|
||||
right := r.Right_edge(s.Cols)
|
||||
if r.Left > right || r.Top >= s.Rows {
|
||||
return ""
|
||||
}
|
||||
var lines []string
|
||||
for row := r.Top; row <= min(r.Bottom, s.Rows-1); row++ {
|
||||
lines = append(lines, strings.TrimRight(string(s.Line(row)[r.Left:right+1]), " \x00"))
|
||||
}
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
Reference in new issue
Block a user