boxmux 0.240.3373

YAML-driven terminal UI framework for rich, interactive CLI applications and dashboards with PTY support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
---
title: User Guide
description: Complete guide for building terminal interfaces with BoxMux - from basic concepts to advanced techniques
---


## Table of Contents

- [Quick Start]#quick-start
- [Core Concepts]#core-concepts
- [Stream Architecture]#stream-architecture
- [Interactive UI Features]#interactive-ui-features
- [Building Interfaces]#building-interfaces
- [Common Patterns]#common-patterns
- [PTY Features]#pty-features
- [Data Visualization]#data-visualization
- [Plugin System]#plugin-system
- [Real-World Examples]#real-world-examples
- [Best Practices]#best-practices
- [Techniques]#techniques

## Quick Start

### Your First Interface

Create a simple "Hello World" interface:

```yaml
app:
  variables:
    WELCOME_MSG: "Welcome to BoxMux!"
  layouts:
    - id: 'hello'
      root: true
      title: 'My First BoxMux App'
      children:
        - id: 'greeting'
          title: 'Hello World'
          position:
            x1: 25%
            y1: 40%
            x2: 75%
            y2: 60%
          content: '${WELCOME_MSG}'
          border: true
          border_color: 'green'
```

Run it:

```bash
# If installed via cargo install
boxmux hello.yaml

# If built from source
./run_boxmux.sh hello.yaml
```

### Interactive Menu

Add interactivity with menus:

```yaml
app:
  layouts:
    - id: 'interactive'
      root: true
      title: 'Interactive Menu'
      children:
        - id: 'menu'
          title: 'Actions'
          position: {x1: 20%, y1: 20%, x2: 80%, y2: 80%}
          tab_order: '1'
          choices:
            - id: 'hello'
              content: 'Say Hello'
              script: ['echo "Hello, World!"']
            - id: 'date'
              content: 'Show Date'  
              script: ['date']
            - id: 'files'
              content: 'List Files'
              script: ['ls -la']
```

## Core Concepts

### 1. Layouts and Boxes

**Layouts** define the overall structure of your interface. **Boxes** are the building blocks within layouts.

```yaml
app:
  layouts:                    # List of layout definitions
    - id: 'main'             # Unique layout identifier
      root: true             # This is the main layout
      children:              # Boxes within this layout
        - id: 'box1'       # Unique box identifier
          title: 'Box'     # Box title
          position:          # Box position and size
            x1: 10%          # Left edge (percentage of parent)
            y1: 10%          # Top edge
            x2: 90%          # Right edge
            y2: 90%          # Bottom edge
```

### 2. Positioning System

BoxMux uses percentage-based positioning for responsive design:

- `x1, y1`: Top-left corner coordinates
- `x2, y2`: Bottom-right corner coordinates
- Values are percentages of the parent container

```yaml
# Common layout patterns
# Full screen
position: {x1: 0%, y1: 0%, x2: 100%, y2: 100%}

# Top half  
position: {x1: 0%, y1: 0%, x2: 100%, y2: 50%}

# Left sidebar
position: {x1: 0%, y1: 0%, x2: 25%, y2: 100%}

# Centered window
position: {x1: 25%, y1: 25%, x2: 75%, y2: 75%}
```

### 3. Interactive Elements

Create interactive menus with choices:

```yaml
- id: 'menu_box'
  tab_order: '1'           # Enable keyboard navigation
  choices:
    - id: 'action1'
      content: 'Menu Option 1'
      script: ['command to execute']
      redirect_output: 'output_box'  # Send results to another box
    - id: 'action2'
      content: 'Menu Option 2'
      script: ['another command']
```

### 4. Real-time Updates

Add live data with refresh intervals:

```yaml
- id: 'live_box'
  title: 'Live Data'
  refresh_interval: 2000   # Update every 2 seconds
  script:
    - date                 # Commands to run on each refresh
    - uptime
```

### 5. Variable System - Dynamic Configuration

BoxMux's variable system enables template-driven interfaces with environment-specific configuration:

#### Basic Variable Usage

```yaml
app:
  variables:
    SERVER_NAME: "production-db"
    DEFAULT_PORT: "5432"
  layouts:
    - id: 'database_monitor'
      title: 'Database Monitor - ${SERVER_NAME}'
      children:
        - id: 'connection_status'
          title: 'Connection Status'
          script:
            - 'pg_isready -h ${SERVER_NAME} -p ${DEFAULT_PORT}'
            - 'echo "Connected to ${SERVER_NAME}:${DEFAULT_PORT}"'
```

#### Environment Integration

Variables seamlessly integrate with environment variables:

```yaml
app:
  variables:
    ENVIRONMENT: "development"  # Overridden by $ENVIRONMENT if set
  layouts:
    - id: 'deployment_status'
      title: 'Status - ${ENVIRONMENT}'
      children:
        - id: 'api_check'
          script:
            - 'echo "Environment: ${ENVIRONMENT}"'
            - 'echo "User: ${USER:unknown}"'       # Uses $USER or "unknown"
            - 'echo "Log Level: ${LOG_LEVEL:info}"' # Uses $LOG_LEVEL or "info"
```

#### Hierarchical Variables

Child boxes inherit and can override parent variables:

```yaml
app:
  variables:
    REGION: "us-east-1"
  layouts:
    - id: 'infrastructure'
      children:
        - id: 'web_tier'
          variables:
            SERVICE_TYPE: "frontend"
            PORT: "80"
          children:
            - id: 'nginx_server'
              variables:
                SERVICE_NAME: "nginx"
                PORT: "443"  # Overrides parent PORT
              title: '${SERVICE_NAME} (${SERVICE_TYPE}) - ${REGION}'
              # Resolves to: "nginx (frontend) - us-east-1"
```

**Learn more**: See the complete [Variable System Guide](/docs/variables) for additional patterns and best practices.

## Stream Architecture

BoxMux uses a **stream-based architecture** where boxes can display content from multiple input streams, each appearing as a separate tab.

### Understanding Streams

Every box can have multiple content streams:

```yaml
- id: 'control_center'
  title: 'Control Center'
  content: 'System control panel ready'  # → Content tab
  choices:                               # → Control Center tab  
    - id: 'deploy'
      script: ['./deploy.sh']
      redirect_output: 'output_display'  # → Deploy tab in output_display
    - id: 'monitor'  
      script: ['./monitor.sh']
      redirect_output: 'output_display'  # → Monitor tab in output_display

- id: 'output_display'
  title: 'Output'
  content: 'Command output will appear here...'
  # Tabs: [Content] + [Deploy] + [Monitor] as commands run
```

### Tab System Usage

**Tab Navigation:**
- **Click tabs** to switch between streams within a box
- **Close buttons (×)** appear on closeable streams (redirected output, PTY sessions)  
- **Background streams** continue updating while inactive

**Example Workflow:**
1. Click "Deploy" choice in control_center → Deploy tab appears in output_display
2. Click "Monitor" choice → Monitor tab appears alongside Deploy tab
3. Click between Deploy/Monitor tabs to view different command outputs  
4. Click × on Deploy tab to terminate the deployment process

### Multi-Stream Development Setup

```yaml
- id: 'dev_commands'
  title: 'Development'
  choices:
    - id: 'build'
      script: ['cargo build --release']
      redirect_output: 'build_results'
      streaming: true               # Live output streaming
    - id: 'test'
      script: ['cargo test']  
      redirect_output: 'test_results'
      streaming: true
    - id: 'lint'
      script: ['cargo clippy']
      redirect_output: 'lint_results'

# Each command creates dedicated tabs in result boxes
- id: 'build_results'
  title: 'Build Output'
  auto_scroll: true
  content: 'Build results appear here...'

- id: 'test_results'  
  title: 'Test Output'
  auto_scroll: true
  content: 'Test results appear here...'

- id: 'lint_results'
  title: 'Lint Output' 
  auto_scroll: true
  content: 'Lint results appear here...'
```

**Result:** Each box shows Content tab initially, then gains Build/Test/Lint tabs as commands execute. Users can monitor multiple processes simultaneously and close completed operations.

### PTY Streams

Interactive terminal sessions create dedicated streams:

```yaml
- id: 'terminal'
  title: 'Terminal'
  pty: true
  script: ['bash']
  # → Creates Terminal tab with interactive shell

- id: 'monitor'
  title: 'System Monitor'  
  pty: true
  script: ['htop']
  # → Creates System Monitor tab with interactive htop
```

**Learn more**: See the complete [Stream Architecture Guide](/docs/stream-architecture) for advanced stream patterns.

## Interactive UI Features

BoxMux supports mouse-driven interface manipulation for dynamic layout editing:

### Box Resizing
- **Drag bottom-right corner** to resize boxes in real-time
- **Auto-save to YAML** preserves changes across restarts
- **Visual feedback** with cursor style changes

### Box Movement  
- **Drag title bar** to move boxes to new positions
- **Snap-to-grid** alignment for precise placement
- **Live persistence** to original configuration files

### Dynamic Interactions
```yaml
- id: 'resizable_demo'
  title: 'Drag Corner to Resize →'
  position: {x1: 10%, y1: 10%, x2: 60%, y2: 60%}
  content: |
    This box demonstrates interactive features:
    
    • Drag bottom-right corner to resize
    • Drag title bar to move  
    • Changes auto-save to YAML file
    • Try it now!
    
- id: 'movable_demo'
  title: '← Drag Title to Move'  
  position: {x1: 40%, y1: 40%, x2: 90%, y2: 90%}
  z_index: 2  # Appears on top for clear interaction
  content: |
    Interactive UI features:
    
    ✓ Real-time visual feedback
    ✓ Automatic YAML persistence  
    ✓ Boundary constraint enforcement
    ✓ Smooth 60 FPS performance optimization
```

**Learn more**: See the complete [Interactive UI Guide](/docs/interactive-ui) for advanced interaction patterns.

## Building Interfaces

### Step-by-Step Interface Creation

#### 1. Plan Your Layout

Before writing YAML, sketch your interface:

```
┌─────────────────────────────┐
│           Header            │
├─────────┬───────────────────┤
│ Sidebar │    Main Content   │
│         │                   │
│         │                   │
├─────────┴───────────────────┤
│           Footer            │
└─────────────────────────────┘
```

#### 2. Implement the Structure

```yaml
app:
  layouts:
    - id: 'dashboard'
      root: true
      title: 'My Dashboard'
      children:
        # Header
        - id: 'header'
          title: 'Dashboard Header'
          position: {x1: 0%, y1: 0%, x2: 100%, y2: 15%}
          content: 'Welcome to the Dashboard'
          
        # Sidebar
        - id: 'sidebar'
          title: 'Navigation'
          position: {x1: 0%, y1: 15%, x2: 25%, y2: 85%}
          tab_order: '1'
          choices:
            - id: 'system'
              content: 'System Info'
              script: ['uname -a']
              redirect_output: 'main'
            - id: 'processes'
              content: 'Processes'
              script: ['ps aux | head -10']
              redirect_output: 'main'
              
        # Main content
        - id: 'main'
          title: 'Main Content'
          position: {x1: 25%, y1: 15%, x2: 100%, y2: 85%}
          content: 'Select an option from the sidebar'
          scroll: true
          
        # Footer
        - id: 'footer'
          title: 'Status'
          position: {x1: 0%, y1: 85%, x2: 100%, y2: 100%}
          refresh_interval: 1000
          script: ['date']
```

#### 3. Add Styling

```yaml
# At layout level for consistent styling
- id: 'dashboard'
  root: true
  title: 'Styled Dashboard'
  bg_color: 'black'
  fg_color: 'white'
  title_fg_color: 'bright_yellow'
  title_bg_color: 'blue'
  selected_bg_color: 'bright_blue'
  border_color: 'green'
  # ... children boxes inherit these styles
```

## Common Patterns

### Header/Sidebar/Main Layout

```yaml
children:
  - id: 'header'
    position: {x1: 0%, y1: 0%, x2: 100%, y2: 10%}
  - id: 'sidebar'  
    position: {x1: 0%, y1: 10%, x2: 20%, y2: 100%}
  - id: 'main'
    position: {x1: 20%, y1: 10%, x2: 100%, y2: 100%}
```

### Two-Column Layout

```yaml
children:
  - id: 'left'
    position: {x1: 0%, y1: 0%, x2: 50%, y2: 100%}
  - id: 'right'
    position: {x1: 50%, y1: 0%, x2: 100%, y2: 100%}
```

### Grid Layout (2x2)

```yaml
children:
  - id: 'top_left'
    position: {x1: 0%, y1: 0%, x2: 50%, y2: 50%}
  - id: 'top_right'
    position: {x1: 50%, y1: 0%, x2: 100%, y2: 50%}
  - id: 'bottom_left'
    position: {x1: 0%, y1: 50%, x2: 50%, y2: 100%}
  - id: 'bottom_right'
    position: {x1: 50%, y1: 50%, x2: 100%, y2: 100%}
```

## PTY Features

PTY (pseudo-terminal) features enable running interactive terminal programs directly within BoxMux boxes.

### When to Use PTY

Use PTY for interactive programs that require:

- Keyboard input (vim, nano, htop)
- Terminal control sequences (colors, cursor movement)
- Process interaction (ssh sessions, database shells)

### PTY Box Example

```yaml
# Interactive system monitor
- id: 'system_monitor'
  title: 'System Monitor ⚡'
  pty: true
  script:
    - htop
  position: {x1: 0%, y1: 0%, x2: 50%, y2: 100%}

# Text editor
- id: 'editor'
  title: 'Configuration Editor ⚡'
  pty: true
  script:
    - vim /etc/app/config.yaml
  position: {x1: 50%, y1: 0%, x2: 100%, y2: 100%}
```

### PTY Choice Example

```yaml
# Interactive menu choices
- id: 'admin_box'
  title: 'Administration'
  choices:
    - id: 'edit_config'
      content: 'Edit Config File'
      pty: true
      script:
        - vim /etc/app/config.yaml
    
    - id: 'database_shell'
      content: 'Database Console'
      pty: true
      script:
        - psql -U postgres -d myapp
        
    - id: 'ssh_server'
      content: 'Connect to Server'
      pty: true
      script:
        - ssh admin@production-server
```

### PTY vs Regular Execution

| Feature | PTY | Regular |
|---------|-----|---------|
| Interactive input | ✅ Yes | ❌ No |
| ANSI colors/formatting | ✅ Yes | ❌ Limited |
| Real-time output | ✅ Yes | ❌ Buffered |
| Process control (Ctrl+C) | ✅ Yes | ❌ No |
| Terminal programs | ✅ Yes | ❌ No |
| Simple commands | ✅ Yes | ✅ Yes |

**Learn more**: See the [PTY Features Guide](/docs/pty-features) for detailed configuration and examples.

## Data Visualization

BoxMux provides data visualization through charts and tables.

### Chart System

BoxMux includes a Unicode-based charting system:

- **Chart Types**: Bar charts, line charts, histograms
- **Smart Layout**: Responsive chart sizing and alignment
- **Real-time Data**: Live data integration with configurable refresh

```yaml
# Live CPU usage chart with smart layout
- id: 'cpu_chart'
  title: 'CPU Usage Over Time'
  chart_config:
    chart_type: 'line'
    width: 50
    height: 15
    title: 'CPU Usage Trend'
  refresh_interval: 2000
  script:
    - top -l 1 | grep "CPU usage" | awk '{print $3}' | sed 's/%//'
```

### Table System

Table features for structured data:

- **Data Formats**: CSV and JSON parsing
- **Sorting**: Text and numeric sorting with direction control
- **Filtering**: Exact match and case-insensitive search
- **Pagination**: Configurable page sizes with navigation
- **Visual Enhancement**: Zebra striping, row numbers, multiple border styles

```yaml
# Advanced process table with all features
- id: 'process_table'
  title: 'Top Processes'
  table_config:
    headers: ['Process', 'CPU %', 'Memory', 'PID']
    sortable: true
    filterable: true
    page_size: 10
    zebra_striping: true
    show_row_numbers: true
    border_style: 'double'
  refresh_interval: 5000
  script:
    - ps aux --no-headers | awk '{printf "%s,%.1f,%.1f,%s\n", $11, $3, $4, $2}' | sort -rn -k2 -t, | head -15
```

**Learn more**: See the [Data Visualization Guide](/docs/data-visualization) for chart types, table features, and examples.

## Plugin System

BoxMux includes a plugin system for extending functionality with dynamic component loading and security validation.

### Plugin Overview

The plugin system supports:

- **Dynamic Component Loading**: Load custom components at runtime using `libloading`
- **Security Validation**: Permission-based access control with manifest validation
- **Fallback System**: Graceful fallback to mock implementations for development/testing

### Basic Plugin Usage

```yaml
# Custom data visualization plugin
- id: 'custom_viz'
  title: 'Custom Metrics'
  plugin_type: 'metrics_visualizer'
  plugin_config:
    metric_source: '/var/log/metrics.json'
    visualization_type: 'heatmap'
    refresh_rate: 1000
  security_permissions:
    - 'filesystem_read'
    - 'process_spawn'
```

**Learn more**: See the [Plugin System Guide](/docs/plugin-system) for development, security model, and examples.

## Real-World Examples

### System Monitor

```yaml
app:
  variables:
    REFRESH_FAST: "2000"
    REFRESH_SLOW: "5000"
  layouts:
    - id: 'sysmon'
      root: true
      title: 'System Monitor - ${USER:admin}'
      bg_color: 'black'
      fg_color: 'green'
      children:
        - id: 'cpu'
          title: 'CPU Usage'
          position: {x1: 5%, y1: 10%, x2: 48%, y2: 40%}
          refresh_interval: ${REFRESH_FAST}
          script:
            - top -l 1 | grep "CPU usage"
            
        - id: 'memory'
          title: 'Memory Usage'
          position: {x1: 52%, y1: 10%, x2: 95%, y2: 40%}
          refresh_interval: ${REFRESH_FAST}
          script:
            - top -l 1 | grep "PhysMem"
            
        - id: 'disk'
          title: 'Disk Usage'
          position: {x1: 5%, y1: 45%, x2: 95%, y2: 75%}
          refresh_interval: ${REFRESH_SLOW}
          script:
            - df -h | head -5
            
        - id: 'processes'
          title: 'Top Processes'
          position: {x1: 5%, y1: 80%, x2: 95%, y2: 95%}
          refresh_interval: 3000
          script:
            - ps aux | head -8
```

### Development Dashboard

```yaml
app:
  layouts:
    - id: 'dev_dash'
      root: true
      title: 'Development Dashboard'
      children:
        - id: 'git_status'
          title: 'Git Status'
          position: {x1: 5%, y1: 10%, x2: 95%, y2: 30%}
          refresh_interval: 10000
          script:
            - git status --short
            - echo "---"
            - git log --oneline -3
            
        - id: 'actions'
          title: 'Actions'
          position: {x1: 5%, y1: 35%, x2: 45%, y2: 85%}
          tab_order: '1'
          choices:
            - id: 'build'
              content: 'Build Project'
              script: ['cargo build']
              redirect_output: 'output'
            - id: 'test'
              content: 'Run Tests'
              script: ['cargo test']
              redirect_output: 'output'
            - id: 'lint'
              content: 'Run Linter'
              script: ['cargo clippy']
              redirect_output: 'output'
              
        - id: 'output'
          title: 'Output'
          position: {x1: 50%, y1: 35%, x2: 95%, y2: 85%}
          content: 'Select an action'
          scroll: true
```

### Log Monitor

```yaml
app:
  layouts:
    - id: 'logmon'
      root: true
      title: 'Log Monitor'
      children:
        - id: 'log_selector'
          title: 'Select Log'
          position: {x1: 5%, y1: 10%, x2: 25%, y2: 90%}
          tab_order: '1'
          choices:
            - id: 'syslog'
              content: 'System Log'
              script: ['tail -20 /var/log/system.log']
              redirect_output: 'log_viewer'
            - id: 'error_log'
              content: 'Error Log'
              script: ['tail -20 /var/log/error.log']
              redirect_output: 'log_viewer'
              
        - id: 'log_viewer'
          title: 'Log Contents'
          position: {x1: 30%, y1: 10%, x2: 95%, y2: 90%}
          content: 'Select a log file'
          scroll: true
```

## Best Practices

### 1. Planning and Design

- **Sketch first**: Plan your layout before writing YAML
- **Start simple**: Begin with basic boxes and add complexity
- **Consider screen sizes**: Test on different terminal sizes
- **Group related content**: Keep related functions in nearby boxes

### 2. Configuration Organization

```yaml
# Use meaningful IDs
- id: 'cpu_monitor'        # Good: descriptive
- id: 'box1'             # Bad: generic

# Consistent styling
app:
  layouts:
    - id: 'main'
      # Define colors once at layout level
      bg_color: 'black'
      fg_color: 'white'
      # Boxes inherit these styles
```

### 3. Performance Optimization

```yaml
# Optimize refresh intervals
- id: 'fast_updates'
  refresh_interval: 1000   # 1 second for critical data

- id: 'slow_updates'  
  refresh_interval: 30000  # 30 seconds for less critical data

# Efficient scripts
script:
  - ps aux | head -10      # Limit output
  - df -h | head -5        # Don't show all filesystems
```

### 4. Error Handling

```yaml
# Robust scripts with fallbacks
script:
  - |
    if command -v docker >/dev/null 2>&1; then
      docker ps
    else
      echo "Docker not available"
    fi
```

### 5. User Experience

```yaml
# Clear navigation with tab_order
- id: 'menu1'
  tab_order: '1'    # First tab stop
- id: 'menu2'  
  tab_order: '2'    # Second tab stop

# Helpful content and titles
- id: 'output'
  title: 'Command Output'
  content: 'Select a command from the menu to see output here'
```

## Techniques

### Dynamic Content with Scripts

```yaml
# Conditional content
script:
  - |
    if systemctl is-active nginx >/dev/null 2>&1; then
      echo "✓ Nginx: Running"
    else
      echo "✗ Nginx: Stopped"
    fi
```

### Multi-line Scripts

```yaml
script:
  - |
    echo "System Information:"
    echo "=================="
    echo "Hostname: $(hostname)"
    echo "Uptime: $(uptime)"
    echo "Load: $(uptime | awk -F'load average:' '{print $2}')"
```

### Output Redirection Patterns

```yaml
# Menu with shared output box
- id: 'actions'
  choices:
    - id: 'action1'
      script: ['command1']
      redirect_output: 'shared_output'
    - id: 'action2'
      script: ['command2']
      redirect_output: 'shared_output'
      
- id: 'shared_output'
  title: 'Results'
  content: 'Select an action'
```

### Nested Box Hierarchies

```yaml
# Complex nested structure
- id: 'main_container'
  position: {x1: 10%, y1: 10%, x2: 90%, y2: 90%}
  children:
    - id: 'left_section'
      position: {x1: 0%, y1: 0%, x2: 50%, y2: 100%}
      children:
        - id: 'top_left'
          position: {x1: 5%, y1: 5%, x2: 95%, y2: 45%}
        - id: 'bottom_left'
          position: {x1: 5%, y1: 55%, x2: 95%, y2: 95%}
    - id: 'right_section'
      position: {x1: 50%, y1: 0%, x2: 100%, y2: 100%}
      # ... right side content
```

### Custom Key Bindings

```yaml
# Custom keyboard shortcuts
on_keypress:
  r:                    # Press 'r' to refresh
    - echo 'Refreshing...'
    - date
  q:                    # Press 'q' to quit
    - exit
  'ctrl+c':            # Ctrl+C handling
    - echo 'Interrupted'
```

### Integration with External APIs

```yaml
# API integration example
script:
  - |
    # Fetch weather data
    curl -s "https://api.openweathermap.org/data/2.5/weather?q=London&appid=YOUR_KEY" | 
    jq '.main.temp, .weather[0].description'
```

---

## Advanced Features

BoxMux includes additional features:

- **Clipboard Integration**: Ctrl+C copies box content with visual feedback
- **Enhanced Scrolling**: Position preservation, page navigation, visual indicators
- **Performance Monitoring**: Built-in benchmarking and performance tracking
- **Schema Validation**: JSON Schema validation with detailed error reporting

**Learn more**: See the [Advanced Features Guide](/docs/advanced-features) for clipboard, scrolling, and performance features.

---

For configuration reference, see [Configuration Guide](/docs/configuration).  
For data visualization details, see [Data Visualization Guide](/docs/data-visualization).  
For plugin development, see [Plugin System Guide](/docs/plugin-system).  
For advanced features, see [Advanced Features Guide](/docs/advanced-features).  
For programmatic control, see [API Reference](/docs/api).  
For troubleshooting, see [Troubleshooting Guide](/docs/troubleshooting).