跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

uiutil.go

59 行 · 1.7 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package uiutil
5
6import (
7 "io"
8 "os"
9
10 "github.com/AlecAivazis/survey/v2"
11 "github.com/AlecAivazis/survey/v2/terminal"
12 "github.com/mattn/go-isatty"
13)
14
15var InterruptErr = terminal.InterruptErr
16
17// Confirm is a regular text input that accept yes/no answers.
18func Confirm(message string, defaultParam bool) (bool, error) {
19 var ans bool
20 prompt := &survey.Confirm{
21 Message: message,
22 Default: defaultParam,
23 }
24 if err := survey.AskOne(prompt, &ans); err != nil {
25 return false, err
26 }
27 return ans, nil
28}
29
30// Select is a prompt that presents a list of various options
31// to the user for them to select using the arrow keys and enter.
32func Select(message string, options []string) (int, error) {
33 var ans int
34 prompt := &survey.Select{
35 Message: message,
36 Options: options,
37 }
38 if err := survey.AskOne(prompt, &ans); err != nil {
39 return -1, err
40 }
41 return ans, nil
42}
43
44// InputIsTTY returns true if reader is coming from stdin, and stdin is a terminal device,
45// not a regular file, stream, or pipe etc.
46func InputIsTTY(reader io.Reader) bool {
47 return reader == os.Stdin && (isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd()))
48}
49
50// OutputIsTTY returns true if writer is going to stdout, and stdout is a terminal device,
51// not a regular file, stream, or pipe etc.
52func OutputIsTTY(writer io.Writer) bool {
53 // This setting is needed so we can write integration tests for the TTY output.
54 // It is probably not useful otherwise.
55 if os.Getenv("_LIMA_OUTPUT_IS_TTY") != "" {
56 return true
57 }
58 return writer == os.Stdout && (isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()))
59}