Skip to content

Commit

Permalink
Merge pull request #74 from reeflective/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
maxlandon authored Nov 17, 2024
2 parents 107a972 + 2f3e92f commit af875b5
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 55 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4

# windows:
# runs-on: windows-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Set up Go
# uses: actions/setup-go@v3
# with:
# go-version: 1.20.4
#
# - name: Build
# run: go build -v ./...
# shell: powershell
#
# - name: Run coverage
# run: go test -v ./...
# shell: powershell
windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.6

- name: Build
run: go build -v ./...
shell: powershell

- name: Run coverage
run: go test -v ./...
shell: powershell
89 changes: 52 additions & 37 deletions internal/display/display_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,59 @@

package display

import (
"fmt"

"github.com/reeflective/readline/internal/completion"
"github.com/reeflective/readline/internal/core"
"github.com/reeflective/readline/internal/term"
"github.com/reeflective/readline/internal/ui"
)

// WatchResize redisplays the interface on terminal resize events on Windows.
// Currently not implemented, see related issue in repo: too buggy right now.
func WatchResize(eng *Engine) chan<- bool {
return make(chan<- bool)
// resizeChannel := core.GetTerminalResize(eng.keys)

// for {
// select {
// case <-resizeChannel:
// // Weird behavior on Windows: when there is no autosuggested line,
// // the cursor moves at the end of the completions area, if non-empty.
// // We must manually go back to the input cursor position first.
// line, _ := eng.completer.Line()
// if eng.completer.IsInserting() {
// eng.suggested = *eng.line
// } else {
// eng.suggested = eng.histories.Suggest(eng.line)
// }
//
// if eng.suggested.Len() <= line.Len() {
// fmt.Println(term.HideCursor)
//
// compRows := completion.Coordinates(eng.completer)
// if compRows <= eng.AvailableHelperLines() {
// compRows++
// }
//
// term.MoveCursorBackwards(term.GetWidth())
// term.MoveCursorUp(compRows)
// term.MoveCursorUp(ui.CoordinatesHint(eng.hint))
// eng.cursorHintToLineStart()
// eng.lineStartToCursorPos()
// fmt.Println(term.ShowCursor)
// }
//
// eng.Refresh()
// case <-done:
// return
// }
// }
resizeChannel := core.GetTerminalResize(eng.keys)
done := make(chan bool, 1)

go func() {
for {
select {
case <-resizeChannel:
// Weird behavior on Windows: when there is no autosuggested line,
// the cursor moves at the end of the completions area, if non-empty.
// We must manually go back to the input cursor position first.
// LAST UPDATE: 17/11/24: On Windows 10 terminal, this seems to have
// disappeared.
line, _ := eng.completer.Line()
if eng.completer.IsInserting() {
eng.suggested = *eng.line
} else {
eng.suggested = eng.histories.Suggest(eng.line)
}

if eng.suggested.Len() <= line.Len() {
fmt.Println(term.HideCursor)

compRows := completion.Coordinates(eng.completer)
if compRows <= eng.AvailableHelperLines() {
compRows++
}

term.MoveCursorBackwards(term.GetWidth())
term.MoveCursorUp(compRows)
term.MoveCursorUp(ui.CoordinatesHint(eng.hint))
eng.cursorHintToLineStart()
eng.lineStartToCursorPos()
fmt.Println(term.ShowCursor)
}

eng.Refresh()
case <-done:
return
}
}
}()

return done
}

0 comments on commit af875b5

Please sign in to comment.