如何处理命令行应用程序用户输入中的冒号?
How to handle colons in command-line application user inputs?
var name: String?
print("What is the name?")
if let input = readLine() {
name = input
}
if let name = name {
print("You input: \(name)")
}
我有一个命令行应用程序,要求用户输入一个可能包含冒号的名称。在 macOS zsh 终端中,当用户输入冒号时,它会自动完成看起来像字典的内容:
acidgate % What is the name? // prompt user for input
acidgate % [Acid Gate: 2020] // the user's input is autocompleted with brackets
这就是我想要的样子:
acidgate % What is the name?
acidgate % Acid Gate: 2020 // no autocomplete
如果我可以在我的应用程序中禁用此自动完成功能,那就太理想了。如果没有,我该如何处理响应?因为如果用户在为他自动完成后手动删除括号,则该字符串会出现奇怪的伪影:
You input: Acid Gate: 2020� // printing the user's input
但是,如果用户不删除方括号并输入 [Acid Gate: 2020]
,打印控制台似乎显示一个干净的字符串:
You input: Acid Gate: 2020
似乎正在调用 oh-my-zsh
的 _swift
完成方案。
您应该能够使用不识别冒号的更简单版本来覆盖 omz 补全,例如:
compdef '_files -g "*"' swift
更多信息:https://superuser.com/questions/686267/disabling-oh-my-zsh-svn-completion
var name: String?
print("What is the name?")
if let input = readLine() {
name = input
}
if let name = name {
print("You input: \(name)")
}
我有一个命令行应用程序,要求用户输入一个可能包含冒号的名称。在 macOS zsh 终端中,当用户输入冒号时,它会自动完成看起来像字典的内容:
acidgate % What is the name? // prompt user for input
acidgate % [Acid Gate: 2020] // the user's input is autocompleted with brackets
这就是我想要的样子:
acidgate % What is the name?
acidgate % Acid Gate: 2020 // no autocomplete
如果我可以在我的应用程序中禁用此自动完成功能,那就太理想了。如果没有,我该如何处理响应?因为如果用户在为他自动完成后手动删除括号,则该字符串会出现奇怪的伪影:
You input: Acid Gate: 2020� // printing the user's input
但是,如果用户不删除方括号并输入 [Acid Gate: 2020]
,打印控制台似乎显示一个干净的字符串:
You input: Acid Gate: 2020
似乎正在调用 oh-my-zsh
的 _swift
完成方案。
您应该能够使用不识别冒号的更简单版本来覆盖 omz 补全,例如:
compdef '_files -g "*"' swift
更多信息:https://superuser.com/questions/686267/disabling-oh-my-zsh-svn-completion