mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-08-16 18:10:32 +03:00
Use RenderLines.InRectangle
This commit is contained in:
parent
51472e1e88
commit
e7ed5716a9
@ -32,6 +32,7 @@ type handler struct {
|
||||
err_mutex sync.Mutex
|
||||
err_in_worker_thread error
|
||||
mouse_state tui.MouseState
|
||||
render_lines tui.RenderLines
|
||||
|
||||
// Listing
|
||||
rl *readline.Readline
|
||||
@ -127,24 +128,24 @@ func (h *handler) draw_listing_screen() (err error) {
|
||||
num_rows := max(0, int(sz.HeightCells)-1)
|
||||
mw := h.family_list.max_width + 1
|
||||
green_fg, _, _ := strings.Cut(h.lp.SprintStyled("fg=green", "|"), "|")
|
||||
lines := make([]string, 0, num_rows)
|
||||
for _, l := range h.family_list.Lines(num_rows) {
|
||||
line := l.text
|
||||
if l.is_current {
|
||||
line = strings.ReplaceAll(line, MARK_AFTER, green_fg)
|
||||
h.lp.PrintStyled("fg=green", ">")
|
||||
h.lp.PrintStyled("fg=green bold", line)
|
||||
line = h.lp.SprintStyled("fg=green", ">") + h.lp.SprintStyled("fg=green bold", line)
|
||||
} else {
|
||||
h.lp.PrintStyled("fg=green", " ")
|
||||
h.lp.QueueWriteString(line)
|
||||
line = " " + line
|
||||
}
|
||||
h.lp.MoveCursorHorizontally(mw - l.width)
|
||||
h.lp.Println(SEPARATOR)
|
||||
num_rows--
|
||||
}
|
||||
for ; num_rows > 0; num_rows-- {
|
||||
h.lp.MoveCursorHorizontally(mw + 1)
|
||||
h.lp.Println(SEPARATOR)
|
||||
lines = append(lines, line)
|
||||
}
|
||||
_, _, str := h.render_lines.InRectangle(lines, 0, 0, 0, num_rows, &h.mouse_state)
|
||||
h.lp.QueueWriteString(str)
|
||||
seps := strings.Repeat(SEPARATOR, num_rows)
|
||||
seps = strings.TrimSpace(seps)
|
||||
_, _, str = h.render_lines.InRectangle(strings.Split(seps, ""), mw+1, 0, 0, num_rows, &h.mouse_state)
|
||||
h.lp.QueueWriteString(str)
|
||||
|
||||
if h.family_list.Len() > 0 {
|
||||
if err = h.draw_family_summary(mw+3, sz); err != nil {
|
||||
return err
|
||||
|
@ -235,6 +235,9 @@ type MouseState struct {
|
||||
func (m *MouseState) AddCellRegion(id string, start_x, start_y, end_x, end_y int, on_click ...func(id string) error) *CellRegion {
|
||||
cr := CellRegion{TopLeft: struct{ X, Y int }{start_x, start_y}, BottomRight: struct{ X, Y int }{end_x, end_y}, Id: id, OnClick: on_click}
|
||||
m.regions = append(m.regions, &cr)
|
||||
if m.region_id_map == nil {
|
||||
m.region_id_map = make(map[string][]*CellRegion)
|
||||
}
|
||||
m.region_id_map[id] = append(m.region_id_map[id], &cr)
|
||||
return &cr
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ var hyperlink_pat = sync.OnceValue(func() *regexp.Regexp {
|
||||
// MouseState.
|
||||
func (r RenderLines) InRectangle(
|
||||
lines []string, start_x, start_y, width, height int, mouse_state *MouseState,
|
||||
) (all_rendered bool, final_y int, ans string) {
|
||||
) (all_rendered bool, y_after_last_line int, ans string) {
|
||||
end_y := start_y + height - 1
|
||||
if end_y < start_y {
|
||||
return len(lines) == 0, start_y, ""
|
||||
return len(lines) == 0, start_y + 1, ""
|
||||
}
|
||||
x, y := start_x, start_y
|
||||
buf := strings.Builder{}
|
||||
@ -100,18 +100,18 @@ func (r RenderLines) InRectangle(
|
||||
|
||||
all_rendered = true
|
||||
for _, line := range lines {
|
||||
lines := []string{line}
|
||||
wrapped_lines := []string{line}
|
||||
if width > 0 {
|
||||
lines = style.WrapTextAsLines(line, width, r.WrapOptions)
|
||||
wrapped_lines = style.WrapTextAsLines(line, width, r.WrapOptions)
|
||||
}
|
||||
for _, line := range lines {
|
||||
for _, line := range wrapped_lines {
|
||||
move_cursor(start_x, y)
|
||||
add_line(line)
|
||||
y += 1
|
||||
if y > end_y {
|
||||
all_rendered = false
|
||||
goto end
|
||||
}
|
||||
move_cursor(start_x, y)
|
||||
add_line(line)
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
Loading…
Reference in New Issue
Block a user