Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Terminal Character Bugs. #60

Merged
merged 12 commits into from
Jan 12, 2024
13 changes: 12 additions & 1 deletion output.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type parseState struct {
vt100 rune
}

func (t *Terminal) handleOutput(buf []byte) {
func (t *Terminal) handleOutput(buf []byte) []byte {
if t.hasSelectedText() {
t.clearSelectedText()
}
Expand All @@ -100,14 +100,24 @@ func (t *Terminal) handleOutput(buf []byte) {
size int
r rune
i = -1
cols = t.config.Columns
rows = t.config.Rows
)
for {
// check if terminal size has changed
if t.config.Columns != cols || t.config.Rows != rows {
break
figuerom16 marked this conversation as resolved.
Show resolved Hide resolved
}

i++
buf = buf[size:]
r, size = utf8.DecodeRune(buf)
if size == 0 {
break
}
if r == utf8.RuneError && size == 1 {
return buf
}

if r == asciiEscape {
t.state.esc = i
Expand Down Expand Up @@ -152,6 +162,7 @@ func (t *Terminal) handleOutput(buf []byte) {
if t.state.esc != noEscape {
t.state.esc = -1
}
return buf
}

func (t *Terminal) parseEscState(r rune) (shouldContinue bool) {
Expand Down
11 changes: 8 additions & 3 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ func (t *Terminal) guessCellSize() fyne.Size {
}

func (t *Terminal) run() {
bufLen := 4069
bufLen := 4096
buf := make([]byte, bufLen)
var leftOver []byte
for {
num, err := t.out.Read(buf)
if err != nil {
Expand All @@ -286,8 +287,12 @@ func (t *Terminal) run() {
fyne.LogError("pty read error", err)
}

t.handleOutput(buf[:num])
if num < bufLen {
if len(leftOver) > 0 {
buf = append(leftOver, buf[:num]...)
num += len(leftOver)
}
leftOver = t.handleOutput(buf[:num])
if num < bufLen+len(leftOver) {
t.Refresh()
}
}
Expand Down
Loading