diff --git a/tools/cmd/diff/patch.go b/tools/cmd/diff/patch.go index 5033f7a91..0c97dbb81 100644 --- a/tools/cmd/diff/patch.go +++ b/tools/cmd/diff/patch.go @@ -331,7 +331,7 @@ func diff(jobs []diff_job, context_count int) (ans map[string]*Patch, err error) err error patch *Patch } - results := make(chan result) + results := make(chan result, len(jobs)) ctx.Parallel(0, len(jobs), func(nums <-chan int) { for i := range nums { job := jobs[i] diff --git a/tools/cmd/diff/render.go b/tools/cmd/diff/render.go index b4036746d..4f30830de 100644 --- a/tools/cmd/diff/render.go +++ b/tools/cmd/diff/render.go @@ -19,6 +19,7 @@ const ( TITLE_LINE LineType = iota CHANGE_LINE IMAGE_LINE + EMPTY_LINE ) type Reference struct { @@ -27,10 +28,9 @@ type Reference struct { } type LogicalLine struct { - src Reference - line_type LineType - margin_size, columns int - screen_lines []string + src Reference + line_type LineType + screen_lines []string } func fit_in(text string, count int) string { @@ -71,7 +71,7 @@ func create_formatters() { added_margin_format = ctx.SprintFunc(fmt.Sprintf("fg=%s bg=%s", conf.Margin_fg.AsRGBSharp(), conf.Added_margin_bg.AsRGBSharp())) removed_format = ctx.SprintFunc(fmt.Sprintf("bg=%s", conf.Removed_bg.AsRGBSharp())) removed_margin_format = ctx.SprintFunc(fmt.Sprintf("fg=%s bg=%s", conf.Margin_fg.AsRGBSharp(), conf.Removed_margin_bg.AsRGBSharp())) - title_format = ctx.SprintFunc(fmt.Sprintf("fg=%s bg=%s", conf.Title_fg.AsRGBSharp(), conf.Title_bg.AsRGBSharp())) + title_format = ctx.SprintFunc(fmt.Sprintf("fg=%s bg=%s bold", conf.Title_fg.AsRGBSharp(), conf.Title_bg.AsRGBSharp())) margin_format = ctx.SprintFunc(fmt.Sprintf("fg=%s bg=%s", conf.Margin_fg.AsRGBSharp(), conf.Margin_bg.AsRGBSharp())) hunk_format = ctx.SprintFunc(fmt.Sprintf("fg=%s bg=%s", conf.Margin_fg.AsRGBSharp(), conf.Hunk_bg.AsRGBSharp())) hunk_margin_format = ctx.SprintFunc(fmt.Sprintf("fg=%s bg=%s", conf.Margin_fg.AsRGBSharp(), conf.Hunk_margin_bg.AsRGBSharp())) @@ -90,11 +90,11 @@ func title_lines(left_path, right_path string, columns, margin_size int, ans []* } else { name = place_in(m+sanitize(left_name), columns) } - ll := LogicalLine{columns: columns, margin_size: margin_size, line_type: TITLE_LINE, src: Reference{path: left_path, linenum: 0}} + ll := LogicalLine{line_type: TITLE_LINE, src: Reference{path: left_path, linenum: 0}} l1 := ll l1.screen_lines = []string{title_format(name)} l2 := ll - l2.screen_lines = []string{title_format(name)} + l2.screen_lines = []string{title_format(strings.Repeat("━", columns+1))} return append(ans, &l1, &l2) } @@ -116,8 +116,13 @@ func render(collection *Collection, diff_map map[string]*Patch, columns int) (*L }) margin_size := utils.Max(3, len(strconv.Itoa(largest_line_number))+1) ans := make([]*LogicalLine, 0, 1024) + empty_line := LogicalLine{line_type: EMPTY_LINE} err := collection.Apply(func(path, item_type, changed_path string) error { ans = title_lines(path, changed_path, columns, margin_size, ans) + defer func() { + el := empty_line + ans = append(ans, &el) + }() is_binary := !is_path_text(path) if !is_binary && item_type == `diff` && !is_path_text(changed_path) { diff --git a/tools/cmd/diff/ui.go b/tools/cmd/diff/ui.go index 2a3803fcb..ac3070702 100644 --- a/tools/cmd/diff/ui.go +++ b/tools/cmd/diff/ui.go @@ -170,9 +170,29 @@ func (self *Handler) draw_screen() { g := (&graphics.GraphicsCommand{}).SetAction(graphics.GRT_action_delete).SetDelete(graphics.GRT_delete_visible) g.WriteWithPayloadToLoop(self.lp, nil) lp.MoveCursorTo(1, 1) + lp.ClearToEndOfScreen() if self.logical_lines == nil || self.diff_map == nil || self.collection == nil { lp.Println(`Calculating diff, please wait...`) return } + num_written := 0 + for i, line := range self.logical_lines.lines[self.scroll_pos.logical_line:] { + if num_written >= self.screen_size.num_lines { + break + } + screen_lines := line.screen_lines + if i == 0 { + screen_lines = screen_lines[self.scroll_pos.screen_line:] + } + for _, sl := range screen_lines { + lp.QueueWriteString(sl) + lp.MoveCursorVertically(1) + lp.QueueWriteString("\r") + num_written++ + if num_written >= self.screen_size.num_lines { + break + } + } + } } diff --git a/tools/tui/loop/api.go b/tools/tui/loop/api.go index 7b575283d..642ef554b 100644 --- a/tools/tui/loop/api.go +++ b/tools/tui/loop/api.go @@ -389,7 +389,7 @@ const ( FOREGROUND = 10 CURSOR = 12 SELECTION_BG = 17 - SELECTION_FG = 18 + SELECTION_FG = 19 ) func (self *Loop) SetDefaultColor(which DefaultColor, val style.RGBA) {