Only send graphics protocol commands if there are actual images to diff
This commit is contained in:
parent
9919767aef
commit
e73282ceb0
@ -55,6 +55,7 @@ type screen_size struct{ rows, columns, num_lines, cell_width, cell_height int }
|
|||||||
type Handler struct {
|
type Handler struct {
|
||||||
async_results chan AsyncResult
|
async_results chan AsyncResult
|
||||||
mouse_selection tui.MouseSelection
|
mouse_selection tui.MouseSelection
|
||||||
|
image_count int
|
||||||
shortcut_tracker config.ShortcutTracker
|
shortcut_tracker config.ShortcutTracker
|
||||||
left, right string
|
left, right string
|
||||||
collection *Collection
|
collection *Collection
|
||||||
@ -114,7 +115,6 @@ func (self *Handler) initialize() {
|
|||||||
self.rl = readline.New(self.lp, readline.RlInit{DontMarkPrompts: true, Prompt: "/"})
|
self.rl = readline.New(self.lp, readline.RlInit{DontMarkPrompts: true, Prompt: "/"})
|
||||||
self.lp.OnEscapeCode = self.on_escape_code
|
self.lp.OnEscapeCode = self.on_escape_code
|
||||||
image_collection = graphics.NewImageCollection()
|
image_collection = graphics.NewImageCollection()
|
||||||
image_collection.Initialize(self.lp)
|
|
||||||
self.current_context_count = opts.Context
|
self.current_context_count = opts.Context
|
||||||
if self.current_context_count < 0 {
|
if self.current_context_count < 0 {
|
||||||
self.current_context_count = int(conf.Num_context_lines)
|
self.current_context_count = int(conf.Num_context_lines)
|
||||||
@ -191,18 +191,23 @@ func (self *Handler) load_all_images() {
|
|||||||
self.collection.Apply(func(path, item_type, changed_path string) error {
|
self.collection.Apply(func(path, item_type, changed_path string) error {
|
||||||
if path != "" && is_image(path) {
|
if path != "" && is_image(path) {
|
||||||
image_collection.AddPaths(path)
|
image_collection.AddPaths(path)
|
||||||
|
self.image_count++
|
||||||
}
|
}
|
||||||
if changed_path != "" && is_image(changed_path) {
|
if changed_path != "" && is_image(changed_path) {
|
||||||
image_collection.AddPaths(changed_path)
|
image_collection.AddPaths(changed_path)
|
||||||
|
self.image_count++
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if self.image_count > 0 {
|
||||||
|
image_collection.Initialize(self.lp)
|
||||||
go func() {
|
go func() {
|
||||||
r := AsyncResult{rtype: IMAGE_LOAD}
|
r := AsyncResult{rtype: IMAGE_LOAD}
|
||||||
image_collection.LoadAll()
|
image_collection.LoadAll()
|
||||||
self.async_results <- r
|
self.async_results <- r
|
||||||
self.lp.WakeupMainThread()
|
self.lp.WakeupMainThread()
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Handler) resize_all_images_if_needed() {
|
func (self *Handler) resize_all_images_if_needed() {
|
||||||
@ -216,7 +221,7 @@ func (self *Handler) resize_all_images_if_needed() {
|
|||||||
Width: available_cols * self.screen_size.cell_width,
|
Width: available_cols * self.screen_size.cell_width,
|
||||||
Height: self.screen_size.num_lines * 2 * self.screen_size.cell_height,
|
Height: self.screen_size.num_lines * 2 * self.screen_size.cell_height,
|
||||||
}
|
}
|
||||||
if sz != self.images_resized_to {
|
if sz != self.images_resized_to && self.image_count > 0 {
|
||||||
go func() {
|
go func() {
|
||||||
image_collection.ResizeForPageSize(sz.Width, sz.Height)
|
image_collection.ResizeForPageSize(sz.Width, sz.Height)
|
||||||
r := AsyncResult{rtype: IMAGE_RESIZE, page_size: sz}
|
r := AsyncResult{rtype: IMAGE_RESIZE, page_size: sz}
|
||||||
@ -331,8 +336,10 @@ func (self *Handler) draw_image_pair(ll *LogicalLine, starting_row int) {
|
|||||||
func (self *Handler) draw_screen() {
|
func (self *Handler) draw_screen() {
|
||||||
self.lp.StartAtomicUpdate()
|
self.lp.StartAtomicUpdate()
|
||||||
defer self.lp.EndAtomicUpdate()
|
defer self.lp.EndAtomicUpdate()
|
||||||
|
if self.image_count > 0 {
|
||||||
self.resize_all_images_if_needed()
|
self.resize_all_images_if_needed()
|
||||||
image_collection.DeleteAllVisiblePlacements(self.lp)
|
image_collection.DeleteAllVisiblePlacements(self.lp)
|
||||||
|
}
|
||||||
lp.MoveCursorTo(1, 1)
|
lp.MoveCursorTo(1, 1)
|
||||||
lp.ClearToEndOfScreen()
|
lp.ClearToEndOfScreen()
|
||||||
if self.logical_lines == nil || self.diff_map == nil || self.collection == nil {
|
if self.logical_lines == nil || self.diff_map == nil || self.collection == nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user