summaryrefslogtreecommitdiff
path: root/src/tui/light_unix.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-05-07 01:06:42 +0900
committerGitHub <noreply@github.com>2024-05-07 01:06:42 +0900
commite8405f40fe2eb3675f1cb4f69e825eff5f13f269 (patch)
treec917367f1f0098939f9cdf7376a2a135907024fc /src/tui/light_unix.go
parent065b9e6fb2ce3e6e50ff423c3786989afa04ee14 (diff)
downloadfzf-e8405f40fe2eb3675f1cb4f69e825eff5f13f269.tar.gz
Refactor the code so that fzf can be used as a library (#3769)
Diffstat (limited to 'src/tui/light_unix.go')
-rw-r--r--src/tui/light_unix.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/tui/light_unix.go b/src/tui/light_unix.go
index 55e2b246..a5499a00 100644
--- a/src/tui/light_unix.go
+++ b/src/tui/light_unix.go
@@ -3,7 +3,7 @@
package tui
import (
- "fmt"
+ "errors"
"os"
"os/exec"
"strings"
@@ -48,19 +48,18 @@ func (r *LightRenderer) closePlatform() {
// NOOP
}
-func openTtyIn() *os.File {
+func openTtyIn() (*os.File, error) {
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
+ return in, nil
}
}
- fmt.Fprintln(os.Stderr, "Failed to open "+consoleDevice)
- util.Exit(2)
+ return nil, errors.New("failed to open " + consoleDevice)
}
- return in
+ return in, nil
}
func (r *LightRenderer) setupTerminal() {
@@ -86,9 +85,14 @@ func (r *LightRenderer) updateTerminalSize() {
func (r *LightRenderer) findOffset() (row int, col int) {
r.csi("6n")
r.flush()
+ var err error
bytes := []byte{}
for tries := 0; tries < offsetPollTries; tries++ {
- bytes = r.getBytesInternal(bytes, tries > 0)
+ bytes, err = r.getBytesInternal(bytes, tries > 0)
+ if err != nil {
+ return -1, -1
+ }
+
offsets := offsetRegexp.FindSubmatch(bytes)
if len(offsets) > 3 {
// Add anything we skipped over to the input buffer