Skip to content

Commit

Permalink
Fix backspace on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemnos committed Dec 31, 2020
1 parent a22a902 commit dd8ab1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 8 additions & 5 deletions typer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"io/ioutil"
"os"
"runtime"
"strconv"
"time"

Expand Down Expand Up @@ -226,6 +227,11 @@ func (t *typer) start(s string, timeLimit time.Duration, startImmediately bool)
rc = TyperResize
return
case *tcell.EventKey:
if runtime.GOOS != "windows" && ev.Key() == tcell.KeyBackspace { //Control+backspace on unix terms
deleteWord()
continue
}

if startTime.IsZero() {
startTime = time.Now()
}
Expand All @@ -241,10 +247,8 @@ func (t *typer) start(s string, timeLimit time.Duration, startImmediately bool)
return
case tcell.KeyCtrlL:
t.Scr.Sync()
case tcell.KeyCtrlH:
deleteWord()
case tcell.KeyBackspace2:
if ev.Modifiers() == tcell.ModAlt {
case tcell.KeyBackspace, tcell.KeyBackspace2:
if ev.Modifiers() == tcell.ModAlt || ev.Modifiers() == tcell.ModCtrl {
deleteWord()
} else {
t.highlight(text, idx, t.backgroundStyle, t.backgroundStyle)
Expand Down Expand Up @@ -312,6 +316,5 @@ func (t *typer) start(s string, timeLimit time.Duration, startImmediately bool)

redraw()
}

}
}
9 changes: 9 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type cell struct {
style tcell.Style
}

func dbgPrintf(scr tcell.Screen, format string, args ...interface{}) {
for i := 0; i < 80; i++ {
for j := 0; j < 80; j++ {
scr.SetContent(i, j, ' ', nil, tcell.StyleDefault)
}
}
drawString(scr, 0, 0, fmt.Sprintf(format, args...), -1, tcell.StyleDefault)
}

func wordWrapBytes(s []byte, n int) {
sp := 0
sz := 0
Expand Down

0 comments on commit dd8ab1d

Please sign in to comment.