Allow lastdir/selection to be written to stdout (#1399)

* Allow lastdir/selection to be written to `stdout`

* Quick fix for runPagerOn
This commit is contained in:
Joe Lim authored and GitHub committed 2023-08-28 11:30:16 +10:00
1 parent e0abb29a00
commit 63d21b5a3e
4 files changed
+42 -37

No files matched your search

+3 -15
View File
@@ -33,6 +33,7 @@ type app struct {
menuCompActive bool
menuComps []string
menuCompInd int
selectionOut []string
}
func newApp(ui *ui, nav *nav) *app {
@@ -328,19 +329,6 @@ func (app *app) loop() {
log.Print("bye!")
if gLastDirPath != "" {
f, err := os.Create(gLastDirPath)
if err != nil {
log.Printf("opening last dir file: %s", err)
}
defer f.Close()
_, err = f.WriteString(app.nav.currDir().path)
if err != nil {
log.Printf("writing last dir file: %s", err)
}
}
return
case n := <-app.nav.copyBytesChan:
app.nav.copyBytes += n
@@ -519,7 +507,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
switch prefix {
case "$", "!":
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
app.runCmdSync(cmd, prefix == "!")
@@ -605,7 +593,7 @@ func (app *app) runPagerOn(stdin io.Reader) {
cmd := shellCommand(envPager, nil)
cmd.Stdin = stdin
cmd.Stdout = os.Stdout
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
app.runCmdSync(cmd, false)
+36
View File
@@ -61,6 +61,42 @@ func run() {
app.loop()
app.ui.screen.Fini()
if gLastDirPath != "" {
writeLastDir(gLastDirPath, app.nav.currDir().path)
}
if gSelectionPath != "" && len(app.selectionOut) > 0 {
writeSelection(gSelectionPath, app.selectionOut)
}
}
func writeLastDir(filename string, lastDir string) {
f, err := os.Create(filename)
if err != nil {
log.Printf("opening last dir file: %s", err)
return
}
defer f.Close()
_, err = f.WriteString(lastDir)
if err != nil {
log.Printf("writing last dir file: %s", err)
}
}
func writeSelection(filename string, selection []string) {
f, err := os.Create(filename)
if err != nil {
log.Printf("opening selection file: %s", err)
return
}
defer f.Close()
_, err = f.WriteString(strings.Join(selection, "\n"))
if err != nil {
log.Printf("writing selection file: %s", err)
}
}
func readExpr() <-chan expr {
+1 -20
View File
@@ -1447,27 +1447,8 @@ func (e *callExpr) eval(app *app, args []string) {
}
if gSelectionPath != "" {
out, err := os.Create(gSelectionPath)
if err != nil {
log.Printf("opening selection file: %s", err)
return
}
defer out.Close()
var path string
if list, err := app.nav.currFileOrSelections(); err == nil {
path = strings.Join(list, "\n")
} else {
return
}
_, err = out.WriteString(path)
if err != nil {
log.Printf("writing selection file: %s", err)
}
app.selectionOut, _ = app.nav.currFileOrSelections()
app.quitChan <- struct{}{}
return
}
+2 -2
View File
@@ -1446,8 +1446,8 @@ func (ui *ui) exportSizes() {
}
func anyKey() {
fmt.Print(gOpts.waitmsg)
defer fmt.Print("\n")
fmt.Fprint(os.Stderr, gOpts.waitmsg)
defer fmt.Fprint(os.Stderr, "\n")
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)