More work on porting icat
This commit is contained in:
parent
b520882b62
commit
d76e0850ae
@ -64,7 +64,7 @@ func parse_mirror() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parse_background() (err error) {
|
func parse_background() (err error) {
|
||||||
if opts.Background == "" {
|
if opts.Background == "" || opts.Background == "none" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
col, err := style.ParseColor(opts.Background)
|
col, err := style.ParseColor(opts.Background)
|
||||||
@ -219,9 +219,12 @@ func on_query_finished() (err error) {
|
|||||||
default:
|
default:
|
||||||
print_error("stream")
|
print_error("stream")
|
||||||
}
|
}
|
||||||
lp.Quit(0)
|
quit_loop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if num_of_items <= 0 {
|
||||||
|
quit_loop()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +277,34 @@ func on_finalize() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errors_occurred bool = false
|
||||||
|
|
||||||
|
func quit_loop() {
|
||||||
|
if errors_occurred {
|
||||||
|
lp.Quit(1)
|
||||||
|
} else {
|
||||||
|
lp.Quit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func on_wakeup() error {
|
func on_wakeup() error {
|
||||||
|
have_more := true
|
||||||
|
for have_more {
|
||||||
|
select {
|
||||||
|
case imgd := <-output_channel:
|
||||||
|
num_of_items--
|
||||||
|
if imgd.err != nil {
|
||||||
|
print_error("Failed to process \x1b[31m%s\x1b[39m: %v\r\n", imgd.source_name, imgd.err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lp.QueueWriteString("Processed " + imgd.source_name + "\r\n")
|
||||||
|
default:
|
||||||
|
have_more = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if num_of_items <= 0 && !query_in_flight {
|
||||||
|
quit_loop()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,7 @@ func is_http_url(arg string) bool {
|
|||||||
|
|
||||||
func process_dirs(args ...string) (results []input_arg, err error) {
|
func process_dirs(args ...string) (results []input_arg, err error) {
|
||||||
results = make([]input_arg, 0, 64)
|
results = make([]input_arg, 0, 64)
|
||||||
if opts.Stdin != "no" && (opts.Stdin == "yes" || tty.IsTerminal(os.Stdin.Fd())) {
|
if opts.Stdin != "no" && (opts.Stdin == "yes" || !tty.IsTerminal(os.Stdin.Fd())) {
|
||||||
results = append(results, input_arg{arg: "/dev/stdin"})
|
results = append(results, input_arg{arg: "/dev/stdin"})
|
||||||
}
|
}
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
@ -140,6 +140,13 @@ type image_data struct {
|
|||||||
format_uppercase string
|
format_uppercase string
|
||||||
available_width, available_height int
|
available_width, available_height int
|
||||||
needs_scaling, needs_conversion bool
|
needs_scaling, needs_conversion bool
|
||||||
|
filename string
|
||||||
|
in_memory_bytes []byte
|
||||||
|
filename_is_temporary bool
|
||||||
|
|
||||||
|
// for error reporting
|
||||||
|
err error
|
||||||
|
source_name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func set_basic_metadata(imgd *image_data) {
|
func set_basic_metadata(imgd *image_data) {
|
||||||
@ -159,6 +166,24 @@ func send_output(imgd *image_data) {
|
|||||||
lp.WakeupMainThread()
|
lp.WakeupMainThread()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func report_error(source_name, msg string, err error) {
|
||||||
|
imgd := image_data{source_name: source_name, err: fmt.Errorf("%s: %w", msg, err)}
|
||||||
|
send_output(&imgd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func make_output_from_input(imgd *image_data, f *opened_input) {
|
||||||
|
bb, ok := f.file.(*BytesBuf)
|
||||||
|
if ok {
|
||||||
|
imgd.in_memory_bytes = bb.data
|
||||||
|
} else {
|
||||||
|
imgd.filename = f.file.(*os.File).Name()
|
||||||
|
if f.name_to_unlink != "" {
|
||||||
|
imgd.filename_is_temporary = true
|
||||||
|
f.name_to_unlink = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func process_arg(arg input_arg) {
|
func process_arg(arg input_arg) {
|
||||||
var f opened_input
|
var f opened_input
|
||||||
if arg.is_http_url {
|
if arg.is_http_url {
|
||||||
@ -198,7 +223,7 @@ func process_arg(arg input_arg) {
|
|||||||
defer f.Release()
|
defer f.Release()
|
||||||
c, format, err := image.DecodeConfig(f.file)
|
c, format, err := image.DecodeConfig(f.file)
|
||||||
f.Rewind()
|
f.Rewind()
|
||||||
imgd := image_data{}
|
imgd := image_data{source_name: arg.value}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
report_error(arg.value, "Unknown image format", err)
|
report_error(arg.value, "Unknown image format", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"kitty/tools/tty"
|
"kitty/tools/tty"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
@ -171,6 +172,16 @@ func (self *Loop) KillIfSignalled() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Loop) Println(args ...any) {
|
||||||
|
self.QueueWriteString(fmt.Sprint(args...))
|
||||||
|
self.QueueWriteString("\r\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Loop) Printf(format string, args ...any) {
|
||||||
|
format = strings.ReplaceAll(format, "\n", "\r\n")
|
||||||
|
self.QueueWriteString(fmt.Sprintf(format, args...))
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Loop) DebugPrintln(args ...any) {
|
func (self *Loop) DebugPrintln(args ...any) {
|
||||||
if self.controlling_term != nil {
|
if self.controlling_term != nil {
|
||||||
const limit = 2048
|
const limit = 2048
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user