Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/liii/pi/app/interactive/app-diff.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

(define-library (liii pi app interactive app-diff)
(export %pi-app-handle-diff-event! %pi-app-apply-diff! %pi-app-settle-diff!
%pi-app-reset-diff!
%pi-app-reset-diff! %pi-app-current-diff-id
) ;export
(import (scheme base)
(liii string)
Expand All @@ -12,6 +12,7 @@
(liii pi app interactive state)
(liii pi app interactive renderers)
(liii pi app interactive tool-diff)
(liii pi app interactive views theme)
(liii pi app interactive views tool-card)
(liii pi app interactive status-card)
) ;import
Expand All @@ -25,6 +26,12 @@
(summary %app-diff-run-summary %app-diff-run-summary-set!)
) ;define-record-type

(define (%pi-app-current-diff-id app)
(let ((run (%pi-app-diff-run app)))
(and run (%app-diff-run-id run))
) ;let
) ;define

(define (%pi-app-reset-diff! app)
;; Dispatch retires the old live index even if the optional run marker
;; is dropped by a saturated event channel.
Expand Down Expand Up @@ -59,12 +66,16 @@
(%app-diff-run-summary-set! run 'shown)
(unless (null? entries)
(let ((box (make-container)))
(container-add! box (make-status-card "Turn changes"))
(container-add! box
(make-status-card (string-append %fg-title "Turn changes" %bold-reset))
) ;container-add!
(for-each
(lambda (entry)
(let ((path (%clean-tool-display-text (car entry))))
(container-add! box
(make-status-card (string-append (string-replace path "\n" " ")
(make-status-card (string-append %fg-accent
(string-replace path "\n" " ")
%fg-reset
" "
(%tool-diff-counts (cadr entry) (caddr entry))
) ;string-append
Expand Down
3 changes: 3 additions & 0 deletions app/liii/pi/app/interactive/app-events.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
(liii pi app interactive working)
(liii pi app interactive app-bash)
(liii pi app interactive app-diff)
(liii pi app interactive app-highlight)
(liii pi app interactive bash)
(liii pi app interactive app-name)
(liii pi app interactive app-queue)
Expand Down Expand Up @@ -316,6 +317,7 @@
;; Kimi Code OAuth 设备码登录:device_code 上屏、done 落盘/报错
((kimi_oauth_device_code) (pi-app-handle-oauth-device-code! app ev))
((kimi_oauth_done) (pi-app-handle-oauth-done! app ev))
((diff_highlight_result) (%pi-app-handle-highlight! app ev))
((run_started diff_result turn_diff_summary)
(%pi-app-handle-diff-event! app ev)
) ;
Expand Down Expand Up @@ -427,6 +429,7 @@
(when has-event
(pi-app-render! app)
) ;when
(%pi-app-pump-highlight! app)
) ;let
) ;define

Expand Down
74 changes: 74 additions & 0 deletions app/liii/pi/app/interactive/app-highlight.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
;; Copyright (C) 2026 The Goldfish Scheme Authors. MIT License.
(define-library (liii pi app interactive app-highlight)
(export %pi-app-pump-highlight! %pi-app-handle-highlight!)
(import (scheme base)
(liii go)
(liii tui)
(liii pi app interactive state)
(liii pi app interactive app-diff)
(liii pi app interactive views highlight-view)
(liii pi app interactive views tool-card)
(liii pi app interactive views ansi-lines)
) ;import
(begin
(define (%pi-app-pump-highlight! app)
(let ((id (%pi-app-current-diff-id app)) (jobs (%pi-app-display-jobs app)))
(when (and id (not (chan-closed? jobs)))
(let loop
((cards (%pi-app-tool-cards app)))
(unless (null? cards)
(let* ((entry (car cards)) (card (cdr entry)) (view (%tool-card-live-view card)))
(cond
((or (not view)
(not (eq? (%highlight-status view) 'pending))
(equal? (%highlight-requested view) (%highlight-revision view))
) ;or
(loop (cdr cards))
) ;
((chan-try-send! jobs
(list 'diff_highlight_job
id
(car entry)
(%highlight-revision view)
(%tool-card-raw-diff card)
) ;list
) ;chan-try-send!
(%highlight-requested-set! view (%highlight-revision view))
(loop (cdr cards))
) ;
) ;cond
) ;let*
) ;unless
) ;let
) ;when
) ;let
) ;define
(define (%pi-app-handle-highlight! app event)
(when
(and (list? event)
(= (length event) 5)
(exact-integer? (cadr event))
(equal? (%pi-app-current-diff-id app) (cadr event))
(string? (caddr event))
(not (chan-closed? (%pi-app-display-jobs app)))
) ;and
(let* ((entry (assoc (caddr event) (%pi-app-tool-cards app)))
(view (and entry (%tool-card-live-view (cdr entry))))
(rev (cadddr event))
(lines (list-ref event 4))
) ;
(when (and view
(eq? (%highlight-status view) 'pending)
(exact-integer? rev)
(equal? rev (%highlight-requested view))
(= rev (%highlight-revision view))
(or (not lines) (%diff-rows? lines))
) ;and
(%highlight-finish! view lines)
(scroll-view-invalidate! (pi-app-scroll-view app))
) ;when
) ;let*
) ;when
) ;define
) ;begin
) ;define-library
22 changes: 18 additions & 4 deletions app/liii/pi/app/interactive/diff-worker.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

(define-library (liii pi app interactive diff-worker)
;; All procedures reached by go must be visible in its separate session.
(export %pi-display-worker %diff-record-file! %diff-job! %diff-compute
%diff-summary %make-diff-turn %diff-turn-id %diff-turn-done %diff-turn-files
%diff-turn-control %diff-turn-control-set! %diff-turn-count
(export %pi-display-worker %display-loop %diff-record-file! %diff-job!
%diff-compute %diff-summary %make-diff-turn %diff-turn-id %diff-turn-done
%diff-turn-files %diff-turn-control %diff-turn-control-set! %diff-turn-count
%diff-turn-count-set! %diff-finish-turn %make-diff-file %diff-file-key
%diff-file-path %diff-file-before %diff-file-after %diff-file-after-set!
%diff-publish!
) ;export
(import (scheme base)
(liii go)
(liii pi app interactive views syntax)
(liii pi app interactive tool-diff)
(only (liii unicode) utf8-replace-invalid)
) ;import
Expand Down Expand Up @@ -147,6 +148,10 @@
) ;define

(define (%pi-display-worker jobs events)
(%display-loop jobs events (%worker-parser))
) ;define

(define (%display-loop jobs events parse)
(let loop
((turn #f))
(unless (chan-closed? jobs)
Expand Down Expand Up @@ -184,7 +189,16 @@
(loop active)
) ;let
) ;
;; Reserved for additional display work types.
((and (eq? (car job) 'diff_highlight_job) (= (length job) 5))
(let ((lines (parse (list-ref job 4))))
(unless (chan-closed? jobs)
(%diff-publish! events
(list 'diff_highlight_result (cadr job) (caddr job) (cadddr job) lines)
) ;%diff-publish!
) ;unless
) ;let
(loop current)
) ;
(else (loop current))
) ;cond
) ;let*
Expand Down
122 changes: 122 additions & 0 deletions app/liii/pi/app/interactive/views/ansi-lines.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
;; Copyright (C) 2026 The Goldfish Scheme Authors. MIT License.
(define-library (liii pi app interactive views ansi-lines)
(export %diff-theme-revision %diff-rows? %diff-visual-lines %diff-card-rows)
(import (scheme base)
(liii list)
(liii string)
(liii tui text-width)
(liii pi code utils shell)
(liii pi app interactive views theme)
(liii pi app interactive views highlight-view)
) ;import
(begin
(define %diff-theme-revision 1)
(define palette
(list (cons "Added" %fg-added)
(cons "Removed" %fg-removed)
(cons "Header" "\x1b;[38;2;140;210;220m")
(cons "File" %fg-accent)
(cons "Normal" %fg-output)
) ;list
) ;define
;; Require full, consecutive coverage; a continuation byte cannot begin a span.
(define (safe-row? row)
(let* ((text (car row)) (n (string-length text)))
(and (string=? text (sanitize-display-text text))
(not (any (lambda (c) (string-contains? text c)) '("\n" "\r" "\t")))
(let loop
((ss (cdr row)) (at 0))
(if (null? ss)
(= at n)
(and (pair? ss)
(let ((s (car ss)))
(and (list? s)
(= (length s) 3)
(exact-integer? (car s))
(= (car s) at)
(exact-integer? (cadr s))
(< 0 (cadr s))
(<= (+ at (cadr s)) n)
(not (<= 128 (char->integer (string-ref text at)) 191))
(assoc (caddr s) palette)
(loop (cdr ss) (+ at (cadr s)))
) ;and
) ;let
) ;and
) ;if
) ;let
) ;and
) ;let*
) ;define
(define (%diff-rows? rows)
(and (pair? rows)
(let loop
((rs rows) (bytes 0) (count 0))
(or (null? rs)
(and (pair? rs)
(< count 8192)
(pair? (car rs))
(string? (caar rs))
(let* ((n (string-length (caar rs))) (total (+ bytes n (if (zero? count) 0 1))))
(and (<= n 65536)
(<= total 524288)
(safe-row? (car rs))
(loop (cdr rs) total (+ count 1))
) ;and
) ;let*
) ;and
) ;or
) ;let
) ;and
) ;define
(define (%diff-card-rows view expanded? width bg)
(and (%highlight-lines view)
(catch #t
(lambda ()
(cons (apply-card-bg "" width bg %fg-output)
(map (lambda (line) (apply-card-bg (string-append " " line) width bg %fg-output))
(%diff-visual-lines (%highlight-lines view) expanded? (max 1 (- width 2)))
) ;map
) ;cons
) ;lambda
(lambda args (%highlight-finish! view #f) #f)
) ;catch
) ;and
) ;define

(define (ansi-row row)
(apply string-append
(map
(lambda (s)
(string-append (cdr (assoc (caddr s) palette))
(substring (car row) (car s) (+ (car s) (cadr s)))
%fg-reset
) ;string-append
) ;lambda
(cdr row)
) ;map
) ;apply
) ;define
(define (%diff-visual-lines rows expanded? width)
(let* ((hidden
(if expanded? 0 (max 0 (- (length rows) 10)))
) ;hidden
(shown (map ansi-row (if (> hidden 0) (take rows 10) rows)))
) ;
(wrap-text
(string-join
(if (zero? hidden)
shown
(append shown
(list (string-append "... (" (number->string hidden) " more lines, ctrl+o to expand)")
) ;list
) ;append
) ;if
"\n"
) ;string-join
width
) ;wrap-text
) ;let*
) ;define
) ;begin
) ;define-library
31 changes: 31 additions & 0 deletions app/liii/pi/app/interactive/views/highlight-view.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
;; Copyright (C) 2026 The Goldfish Scheme Authors. MIT License.
(define-library (liii pi app interactive views highlight-view)
(export %new-highlight-view %highlight-revision %highlight-status
%highlight-requested %highlight-requested-set! %highlight-lines
%highlight-reset! %highlight-finish!
) ;export
(import (scheme base))
(begin
(define-record-type <highlight-view>
(make-view revision status requested lines)
view?
(revision %highlight-revision set-revision!)
(status %highlight-status set-status!)
(requested %highlight-requested %highlight-requested-set!)
(lines %highlight-lines set-lines!)
) ;define-record-type
(define (%new-highlight-view)
(make-view 0 #f #f #f)
) ;define
(define (%highlight-reset! view)
(set-revision! view (+ 1 (%highlight-revision view)))
(%highlight-requested-set! view #f)
(set-lines! view #f)
(set-status! view 'pending)
) ;define
(define (%highlight-finish! view lines)
(set-lines! view lines)
(set-status! view (if lines 'ready 'skipped))
) ;define
) ;begin
) ;define-library
Loading
Loading