mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 10:41:58 +02:00
DRYer
This commit is contained in:
@@ -113,23 +113,19 @@ func decode_hint(x string, alphabet string) (ans int) {
|
|||||||
func main(_ *cli.Command, o *Options, args []string) (rc int, err error) {
|
func main(_ *cli.Command, o *Options, args []string) (rc int, err error) {
|
||||||
output := tui.KittenOutputSerializer()
|
output := tui.KittenOutputSerializer()
|
||||||
if tty.IsTerminal(os.Stdin.Fd()) {
|
if tty.IsTerminal(os.Stdin.Fd()) {
|
||||||
tui.ReportError(fmt.Errorf("You must pass the text to be hinted on STDIN"))
|
return 1, fmt.Errorf("You must pass the text to be hinted on STDIN")
|
||||||
return 1, nil
|
|
||||||
}
|
}
|
||||||
stdin, err := io.ReadAll(os.Stdin)
|
stdin, err := io.ReadAll(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tui.ReportError(fmt.Errorf("Failed to read from STDIN with error: %w", err))
|
return 1, fmt.Errorf("Failed to read from STDIN with error: %w", err)
|
||||||
return 1, nil
|
|
||||||
}
|
}
|
||||||
if len(args) > 0 && o.CustomizeProcessing == "" && o.Type != "linenum" {
|
if len(args) > 0 && o.CustomizeProcessing == "" && o.Type != "linenum" {
|
||||||
tui.ReportError(fmt.Errorf("Extra command line arguments present: %s", strings.Join(args, " ")))
|
return 1, fmt.Errorf("Extra command line arguments present: %s", strings.Join(args, " "))
|
||||||
return 1, nil
|
|
||||||
}
|
}
|
||||||
input_text := parse_input(utils.UnsafeBytesToString(stdin))
|
input_text := parse_input(utils.UnsafeBytesToString(stdin))
|
||||||
text, all_marks, index_map, err := find_marks(input_text, o, os.Args[2:]...)
|
text, all_marks, index_map, err := find_marks(input_text, o, os.Args[2:]...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tui.ReportError(err)
|
return 1, err
|
||||||
return 1, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result := Result{
|
result := Result{
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ var RunningAsUI = utils.Once(func() bool {
|
|||||||
func PrepareRootCmd(root *cli.Command) {
|
func PrepareRootCmd(root *cli.Command) {
|
||||||
if RunningAsUI() {
|
if RunningAsUI() {
|
||||||
root.CallbackOnError = func(cmd *cli.Command, err error, during_parsing bool, exit_code int) int {
|
root.CallbackOnError = func(cmd *cli.Command, err error, during_parsing bool, exit_code int) int {
|
||||||
ReportError(err)
|
cli.ShowError(err)
|
||||||
|
os.Stdout.WriteString("\x1bP@kitty-overlay-ready|\x1b\\")
|
||||||
|
HoldTillEnter(true)
|
||||||
return exit_code
|
return exit_code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,9 +53,3 @@ func KittenOutputSerializer() func(any) (string, error) {
|
|||||||
return utils.UnsafeBytesToString(data), nil
|
return utils.UnsafeBytesToString(data), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReportError(err error) {
|
|
||||||
cli.ShowError(err)
|
|
||||||
os.Stdout.WriteString("\x1bP@kitty-overlay-ready|\x1b\\")
|
|
||||||
HoldTillEnter(false)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user