-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of height option for Windows
Cleanup and minor fixes Addressing comments Linux fixes another Linux fix Workaround for an input issue if fzf is launched from a PSReadline handler fzf would only get the first character if run from PSReadline handler and with --height mode activated under Windows; minor cleanup Minor cleanup Bring back part of commit 70a92a8 Linux fix
- Loading branch information
1 parent
ff95134
commit 6d002c5
Showing
4 changed files
with
265 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// +build !windows | ||
|
||
package tui | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"syscall" | ||
|
||
"github.com/junegunn/fzf/src/util" | ||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
func IsLightRendererSupported() bool { | ||
return true | ||
} | ||
|
||
func (r *LightRenderer) fd() int { | ||
return int(r.ttyin.Fd()) | ||
} | ||
|
||
func (r *LightRenderer) initPlatform() error { | ||
fd := r.fd() | ||
origState, err := terminal.GetState(fd) | ||
if err != nil { | ||
errorExit(err.Error()) | ||
} | ||
r.origState = origState | ||
|
||
terminal.MakeRaw(r.fd()) | ||
return nil | ||
} | ||
|
||
func (r *LightRenderer) closePlatform() { | ||
// NOOP | ||
} | ||
|
||
func openTtyIn() *os.File { | ||
in, err := os.OpenFile(consoleDevice, syscall.O_RDONLY, 0) | ||
if err != nil { | ||
tty := ttyname() | ||
if len(tty) > 0 { | ||
if in, err := os.OpenFile(tty, syscall.O_RDONLY, 0); err == nil { | ||
return in | ||
} | ||
} | ||
fmt.Fprintln(os.Stderr, "Failed to open "+consoleDevice) | ||
os.Exit(2) | ||
} | ||
return in | ||
} | ||
|
||
func (r *LightRenderer) setupTerminal() { | ||
terminal.MakeRaw(r.fd()) | ||
} | ||
|
||
func (r *LightRenderer) restoreTerminal() { | ||
terminal.Restore(r.fd(), r.origState) | ||
} | ||
|
||
func (r *LightRenderer) updateTerminalSize() { | ||
width, height, err := terminal.GetSize(r.fd()) | ||
|
||
if err == nil { | ||
r.width = width | ||
r.height = r.maxHeightFunc(height) | ||
} else { | ||
r.width = getEnv("COLUMNS", defaultWidth) | ||
r.height = r.maxHeightFunc(getEnv("LINES", defaultHeight)) | ||
} | ||
} | ||
|
||
func (r *LightRenderer) findOffset() (row int, col int) { | ||
r.csi("6n") | ||
r.flush() | ||
bytes := []byte{} | ||
for tries := 0; tries < offsetPollTries; tries++ { | ||
bytes = r.getBytesInternal(bytes, tries > 0) | ||
offsets := offsetRegexp.FindSubmatch(bytes) | ||
if len(offsets) > 3 { | ||
// add anything we skipped over to the input buffer | ||
r.buffer = append(r.buffer, offsets[1]...) | ||
return atoi(string(offsets[2]), 0) - 1, atoi(string(offsets[3]), 0) - 1 | ||
} | ||
} | ||
return -1, -1 | ||
} | ||
|
||
func (r *LightRenderer) getch(nonblock bool) (int, bool) { | ||
b := make([]byte, 1) | ||
fd := r.fd() | ||
util.SetNonblock(r.ttyin, nonblock) | ||
|
||
_, err := util.Read(fd, b) | ||
|
||
if err != nil { | ||
return 0, false | ||
} | ||
return int(b[0]), true | ||
} |
Oops, something went wrong.