feat(interactive): Add interactive console features and refactor spinner module by renaming source-ora to source-interactive and removing ora dependency

This commit is contained in:
2025-05-15 19:53:29 +00:00
parent 09da3a1e2d
commit 7e8a404fcf
13 changed files with 989 additions and 269 deletions

View File

@ -60,6 +60,78 @@ defaultLogger.log('warn', 'This is a warning message using the default logger');
This is particularly helpful for simple applications or for initial project setup.
### Interactive Console Features
Smartlog provides interactive console features through the `@push.rocks/smartlog/source-interactive` module:
#### Spinners
Use spinners to show progress for operations:
```typescript
import { SmartlogSourceInteractive } from '@push.rocks/smartlog/source-interactive';
const spinner = new SmartlogSourceInteractive();
spinner.text('Loading data...');
// Later, when the operation completes:
spinner.finishSuccess('Data loaded successfully!');
// Or if it fails:
spinner.finishFail('Failed to load data');
// You can chain operations:
spinner.text('Connecting to server');
spinner.successAndNext('Fetching records');
spinner.successAndNext('Processing data');
spinner.finishSuccess('All done!');
// Customize appearance:
spinner.setSpinnerStyle('line'); // 'dots', 'line', 'star', or 'simple'
spinner.setColor('green'); // 'red', 'green', 'yellow', 'blue', etc.
spinner.setSpeed(100); // Animation speed in milliseconds
```
#### Progress Bars
Create progress bars for tracking operation progress:
```typescript
import { SmartlogProgressBar } from '@push.rocks/smartlog/source-interactive';
const progressBar = new SmartlogProgressBar({
total: 100, // Total number of items
width: 40, // Width of the progress bar
complete: '█', // Character for completed section
incomplete: '░', // Character for incomplete section
showEta: true, // Show estimated time remaining
showPercent: true, // Show percentage
showCount: true // Show count (e.g., "50/100")
});
// Update progress
progressBar.update(50); // Set to 50% progress
// Or increment
progressBar.increment(10); // Increase by 10 units
// Change color
progressBar.setColor('blue');
// Complete the progress bar
progressBar.update(100); // or progressBar.complete();
```
#### Non-Interactive Environments
Both spinners and progress bars automatically detect non-interactive environments (CI/CD, piped output, non-TTY) and provide fallback text-based output:
```
[Loading] Loading data...
Progress: 50% (50/100)
Progress: 100% (100/100)
[Success] Data loaded successfully!
```
### Extending With Log Destinations
One of the core strengths of `@push.rocks/smartlog` is its ability to work with multiple log destinations, enabling you to log messages not just to the console but also to external logging services or custom destinations.
@ -121,4 +193,4 @@ Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.