25 lines
446 B
Go
25 lines
446 B
Go
package input
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/steipete/gogcli/internal/ui"
|
|
)
|
|
|
|
func PromptLine(ctx context.Context, prompt string) (string, error) {
|
|
return PromptLineFrom(ctx, prompt, os.Stdin)
|
|
}
|
|
|
|
func PromptLineFrom(ctx context.Context, prompt string, r io.Reader) (string, error) {
|
|
if u := ui.FromContext(ctx); u != nil {
|
|
u.Err().Print(prompt)
|
|
} else {
|
|
_, _ = fmt.Fprint(os.Stderr, prompt)
|
|
}
|
|
|
|
return ReadLine(r)
|
|
}
|