Add a new "file" mode to the ask kitten

This commit is contained in:
Kovid Goyal
2025-08-15 21:18:25 +05:30
parent 7b1647a5f7
commit 23d8648f5d
5 changed files with 67 additions and 46 deletions

View File

@@ -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")

View File

@@ -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
}

View File

@@ -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.