mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 17:52:02 +02:00
Add a new "file" mode to the ask kitten
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/kovidgoyal/kitty/kittens/choose_files"
|
||||
"github.com/kovidgoyal/kitty/tools/tui/loop"
|
||||
"github.com/kovidgoyal/kitty/tools/tui/readline"
|
||||
"github.com/kovidgoyal/kitty/tools/utils"
|
||||
@@ -16,13 +17,16 @@ import (
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func get_line(o *Options) (result string, err error) {
|
||||
func get_line(o *Options, complete_file_names bool) (result string, err error) {
|
||||
lp, err := loop.New(loop.NoAlternateScreen, loop.NoRestoreColors)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cwd, _ := os.Getwd()
|
||||
ropts := readline.RlInit{Prompt: o.Prompt}
|
||||
if complete_file_names {
|
||||
ropts.Completer = choose_files.FilePromptCompleter(nil)
|
||||
}
|
||||
if o.Name != "" {
|
||||
base := filepath.Join(utils.CacheDir(), "ask")
|
||||
ropts.HistoryPath = filepath.Join(base, o.Name+".history.json")
|
||||
|
||||
@@ -50,7 +50,13 @@ func main(_ *cli.Command, o *Options, args []string) (rc int, err error) {
|
||||
result.Response = pw
|
||||
case "line":
|
||||
show_message(o.Message)
|
||||
result.Response, err = get_line(o)
|
||||
result.Response, err = get_line(o, false)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
case "file":
|
||||
show_message(o.Message)
|
||||
result.Response, err = get_line(o, true)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ from ..tui.handler import result_handler
|
||||
def option_text() -> str:
|
||||
return '''\
|
||||
--type -t
|
||||
choices=line,yesno,choices,password
|
||||
choices=line,yesno,choices,password,file
|
||||
default=line
|
||||
Type of input. Defaults to asking for a line of text.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user