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:
Storm Dragon committed 2026-10-27 20:30:55 -04:00
1 parent c018f5fd29
commit 0e50de4c76
1047 files changed
+58364 -63747

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
// Fenrir console screen reader.
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
package reader
import (
"slices"
"time"
"unicode"
"git.stormux.org/storm/fenrir/internal/screen"
)
// Progress is independent of automatic reading and speech mute.
func (r *Reader) Configure_progress(enabled bool) {
if r.progressEnabled != enabled {
r.progress.Reset()
}
r.progressEnabled = enabled
}
func (r *Reader) Next_progress(now time.Time) (float64, bool) { return r.progress.Next(now) }
func (r *Reader) Reset_progress() { r.progress.Reset() }
func (r *Reader) Progress_active() bool { return r.progress.Active() }
func (r *Reader) Note_deletion() { r.progressDeletionAt = time.Now() }
// A recent deletion key alone is insufficient: match the actual cursor-row
// deletion so background progress, including another row in the same snapshot,
// remains available to the detector. Automatic deletion speech is unchanged.
func (r *Reader) progress_deletion_row(previous, next screen.Snapshot) int {
if r.progressDeletionAt.IsZero() || time.Since(r.progressDeletionAt) > echoWindow || previous.Y != next.Y || next.X > previous.X {
return -1
}
before, after := previous.Line(next.Y), next.Line(next.Y)
count := previous.X - next.X
if count == 0 {
// Forward Delete leaves the cursor in place but shortens the line.
beforeEnd, afterEnd := len(before), len(after)
for beforeEnd > 0 && unicode.IsSpace(before[beforeEnd-1]) {
beforeEnd--
}
for afterEnd > 0 && unicode.IsSpace(after[afterEnd-1]) {
afterEnd--
}
count = beforeEnd - afterEnd
}
if count <= 0 || next.X+count > next.Cols || !slices.Equal(before[:next.X], after[:next.X]) ||
!slices.Equal(before[next.X+count:], after[next.X:next.Cols-count]) || !all_spaces(after[next.Cols-count:]) {
return -1
}
r.progressDeletionAt = time.Time{}
return next.Y
}