/ scripts / demo-text.sh
demo-text.sh
 1  #!/bin/bash
 2  # Generate a simple text-based demo that can be run anywhere
 3  # Shows the indicator output in terminal
 4  
 5  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 6  PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
 7  
 8  echo "=== code-action-quick Demo ==="
 9  echo ""
10  
11  # Run Emacs batch to simulate the indicator
12  emacs -Q --batch \
13    -l "$PROJECT_DIR/code-action-quick.el" \
14    --eval "
15  (progn
16    ;; Create a buffer with Rust-like content
17    (with-temp-buffer
18      (insert \"// Demo: Missing import\\n\")
19      (insert \"fn main() {\\n\")
20      (insert \"    let map: HashMap<String, i32> = HashMap::new();\\n\")
21      (insert \"    println!(\\\"{:?}\\\", map);\\n\")
22      (insert \"}\\n\")
23      
24      ;; Simulate what the indicator would show
25      (princ \"\\nπŸ“„ Buffer content:\\n\")
26      (princ \"─────────────────────────────────────────\\n\")
27      (princ (buffer-string))
28      (princ \"─────────────────────────────────────────\\n\\n\")
29      
30      ;; Simulate mock actions
31      (let ((mock-actions
32             '((:title \"Import \\\`std::collections::HashMap\\\`\" :kind \"quickfix\" :isPreferred t)
33               (:title \"Import \\\`hashbrown::HashMap\\\`\" :kind \"quickfix\"))))
34        
35        ;; Show what indicator would display
36        (princ \"πŸ’‘ Modeline indicator would show:\\n\")
37        (princ \"─────────────────────────────────────────\\n\")
38        (let* ((action (car mock-actions))
39               (title (plist-get action :title))
40               (truncated (if (> (length title) 30)
41                             (concat (substring title 0 27) \"...\")
42                           title)))
43          (princ (format \"   πŸ’‘%s\\n\" truncated)))
44        (princ \"─────────────────────────────────────────\\n\\n\")
45        
46        ;; Show available actions
47        (princ \"πŸ“‹ Available code actions (M-x code-action-quick-show):\\n\")
48        (princ \"─────────────────────────────────────────\\n\")
49        (let ((idx 1))
50          (dolist (action mock-actions)
51            (let ((title (plist-get action :title))
52                  (kind (plist-get action :kind))
53                  (pref (if (plist-get action :isPreferred) \"β˜…\" \" \")))
54              (princ (format \"   %s %d. [%s] %s\\n\" pref idx kind title))
55              (setq idx (1+ idx)))))
56        (princ \"─────────────────────────────────────────\\n\\n\")
57        
58        ;; Explain the workflow
59        (princ \"πŸ”§ Workflow:\\n\")
60        (princ \"   1. Move cursor to line with HashMap\\n\")
61        (princ \"   2. Indicator appears: πŸ’‘Import \\\`std::collections::HashMap\\\`\\n\")
62        (princ \"   3. Press keybinding (C-c a) to execute\\n\")
63        (princ \"   4. Import statement is added automatically!\\n\"))))
64  " 2>&1
65  
66  echo ""
67  echo "=== End Demo ==="