|
| 1 | +# Console API Migration Guide |
| 2 | + |
| 3 | +Quick reference guide for migrating from old Console API to the new refactored API. |
| 4 | + |
| 5 | +## Quick Changes |
| 6 | + |
| 7 | +### 1. MVCConsoleStyle → ConsoleTheme |
| 8 | + |
| 9 | +```pascal |
| 10 | +// OLD (deprecated) |
| 11 | +MVCConsoleStyle.TextColor := Yellow; |
| 12 | +MVCConsoleStyle.DrawColor := White; |
| 13 | +MVCConsoleStyle.BoxStyle := bsRounded; |
| 14 | +
|
| 15 | +// NEW (recommended) |
| 16 | +ConsoleTheme.TextColor := Yellow; |
| 17 | +ConsoleTheme.DrawColor := White; |
| 18 | +ConsoleTheme.BoxStyle := bsRounded; |
| 19 | +``` |
| 20 | + |
| 21 | +### 2. WriteLineColored → WriteLine |
| 22 | + |
| 23 | +```pascal |
| 24 | +// OLD (deprecated) |
| 25 | +WriteLineColored('Message'); |
| 26 | +WriteLineColored('Warning', Yellow); |
| 27 | +WriteLineColored('Error', White, Red); |
| 28 | +
|
| 29 | +// NEW (recommended) |
| 30 | +WriteLine('Message'); |
| 31 | +WriteLine('Warning', Yellow); |
| 32 | +WriteLine('Error', White, Red); |
| 33 | +``` |
| 34 | + |
| 35 | +## Search & Replace Commands |
| 36 | + |
| 37 | +For quick migration in your codebase: |
| 38 | + |
| 39 | +### Visual Studio Code / VS |
| 40 | +1. Find: `MVCConsoleStyle` |
| 41 | +2. Replace: `ConsoleTheme` |
| 42 | +3. Find: `WriteLineColored` |
| 43 | +4. Replace: `WriteLine` |
| 44 | + |
| 45 | +### Command Line (ripgrep) |
| 46 | +```bash |
| 47 | +# Preview changes |
| 48 | +rg "MVCConsoleStyle" --files-with-matches |
| 49 | +rg "WriteLineColored" --files-with-matches |
| 50 | + |
| 51 | +# Replace (requires rg with --replace) |
| 52 | +rg "MVCConsoleStyle" --files-with-matches --replace "ConsoleTheme" |
| 53 | +rg "WriteLineColored" --files-with-matches --replace "WriteLine" |
| 54 | +``` |
| 55 | + |
| 56 | +## Compatibility |
| 57 | + |
| 58 | +- ✅ **Old code still works** - No breaking changes |
| 59 | +- ⚠️ **Deprecation warnings** - Compiler will warn but code compiles |
| 60 | +- ✅ **No runtime changes** - Behavior is identical |
| 61 | + |
| 62 | +## Examples |
| 63 | + |
| 64 | +### Before (Old API) |
| 65 | +```pascal |
| 66 | +procedure ShowStatus; |
| 67 | +begin |
| 68 | + ClrScr; |
| 69 | + MVCConsoleStyle.TextColor := Cyan; |
| 70 | + WriteLineColored('Server Status', White); |
| 71 | + WriteLineColored('Status: Running', Green); |
| 72 | + WriteLineColored('Port: 8080', Yellow); |
| 73 | +end; |
| 74 | +``` |
| 75 | + |
| 76 | +### After (New API) |
| 77 | +```pascal |
| 78 | +procedure ShowStatus; |
| 79 | +begin |
| 80 | + ClrScr; |
| 81 | + ConsoleTheme.TextColor := Cyan; |
| 82 | + WriteLine('Server Status', White); |
| 83 | + WriteLine('Status: Running', Green); |
| 84 | + WriteLine('Port: 8080', Yellow); |
| 85 | +end; |
| 86 | +``` |
| 87 | + |
| 88 | +### Side-by-Side Comparison |
| 89 | + |
| 90 | +| Old API | New API | Notes | |
| 91 | +|---------|---------|-------| |
| 92 | +| `MVCConsoleStyle.TextColor` | `ConsoleTheme.TextColor` | More semantic name | |
| 93 | +| `WriteLineColored(Text)` | `WriteLine(Text)` | Simpler, matches WriteLn | |
| 94 | +| `WriteLineColored(Text, Color)` | `WriteLine(Text, Color)` | Same functionality | |
| 95 | +| `WriteLineColored(Text, FG, BG)` | `WriteLine(Text, FG, BG)` | Same functionality | |
| 96 | + |
| 97 | +## Need Help? |
| 98 | + |
| 99 | +- See `REFACTORING_CONSOLE_API.md` for detailed technical changes |
| 100 | +- See `samples/console_sample/ConsoleDemo.dpr` for complete demo with all features |
| 101 | +- See `samples/console_sample/ConsoleSample.dpr` for basic tests including new API |
| 102 | + |
| 103 | +## Rollback |
| 104 | + |
| 105 | +If you need to rollback: |
| 106 | +```bash |
| 107 | +git checkout HEAD -- sources/MVCFramework.Console.pas |
| 108 | +git checkout HEAD -- samples/console_sample/ConsoleDemo.dpr |
| 109 | +``` |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +**Last Updated**: 2026-02-06 |
0 commit comments