A project that integrates smartlog logging capabilities with the ora spinner for visually appealing CLI output.
Go to file
2024-05-29 14:14:30 +02:00
.vscode fix(core): update 2020-06-07 13:03:13 +00:00
test fix(core): update 2019-05-09 19:19:49 +02:00
ts fix(core): update 2019-05-19 16:30:01 +02:00
.gitignore fix(core): update 2020-06-07 13:03:13 +00:00
.gitlab-ci.yml fix(core): update 2020-06-07 13:03:13 +00:00
license fix(core): update 2019-05-09 19:17:03 +02:00
npmextra.json update tsconfig 2024-04-14 17:54:59 +02:00
package-lock.json 1.0.9 2020-06-07 13:03:15 +00:00
package.json update description 2024-05-29 14:14:30 +02:00
pnpm-lock.yaml switch to new org scheme 2023-07-11 01:06:49 +02:00
readme.hints.md update tsconfig 2024-04-14 17:54:59 +02:00
readme.md update tsconfig 2024-04-14 17:54:59 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:36:21 +02:00

@push.rocks/smartlog-source-ora

a smartlog source wrapping ora for local display

Install

To use @push.rocks/smartlog-source-ora in your project, you need to include it via npm. Run the following command to install it:

npm install @push.rocks/smartlog-source-ora --save

This will add @push.rocks/smartlog-source-ora to your project's dependencies.

Usage

This library provides a convenient way to use the ora spinner in combination with the smartlog logging solution. It is great for CLI applications or any other Node.js project where you need to indicate progress or loading states in a visually appealing way. Below are examples demonstrating how to integrate and use @push.rocks/smartlog-source-ora in your projects.

Importing and Initialization

To start using @push.rocks/smartlog-source-ora, you first need to import the library and initialize an instance of SmartlogSourceOra.

import { SmartlogSourceOra } from '@push.rocks/smartlog-source-ora';

const smartlogOra = new SmartlogSourceOra();

Displaying Text with the Spinner

Once you have your SmartlogSourceOra instance, you can start displaying messages with an accompanying spinner. This is particularly useful when you want to inform the user about the current status of operations.

smartlogOra.text('Loading resources...');

Manipulating the Spinner State

@push.rocks/smartlog-source-ora allows you to control the spinner state by stopping it, marking it as successful, or indicating failure. Each method allows for an optional text message to be displayed.

Stopping the Spinner

smartlogOra.stop();

Indicating Success

To indicate that the operation was successful, you can use the finishSuccess() method. Optionally, you can pass a message to be displayed alongside the success indication.

smartlogOra.finishSuccess('Resources loaded successfully.');

Indicating Failure

Similarly, if an operation fails, you can use the finishFail() method to display a failure message.

smartlogOra.finishFail('Failed to load resources.');

Success/Failure and Moving to the Next Operation

@push.rocks/smartlog-source-ora also provides convenient methods to indicate the success or failure of an operation and immediately moves on to the text of the next operation.

// Indicating success and moving on
smartlogOra.successAndNext('Resources loaded. Initializing...');

// Indicating failure and moving on
smartlogOra.failAndNext('Failed to load resources. Retrying...');

Integrating with smartlogInterfaces

This module is designed to integrate seamlessly with smartlogInterfaces, allowing for a unified logging solution across your project.

To achieve comprehensive logging and progress indication, consider extending SmartlogSourceOra with functionality to integrate logging levels and message types according to smartlogInterfaces. This ensures a coherent user experience where log messages and progress indicators work hand in hand.

Complete Example

Below is a concise example that brings together all the above elements, demonstrating how @push.rocks/smartlog-source-ora can be used in a real-world scenario:

import { SmartlogSourceOra } from '@push.rocks/smartlog-source-ora';

async function performOperations() {
  const smartlogOra = new SmartlogSourceOra();

  try {
    smartlogOra.text('Starting operation 1...');
    // simulate operation
    await new Promise(resolve => setTimeout(resolve, 2000));
    smartlogOra.finishSuccess('Operation 1 completed.');

    smartlogOra.text('Starting operation 2...');
    // simulate operation
    await new Promise((resolve, reject) => setTimeout(reject, 2000));
  } catch (error) {
    smartlogOra.finishFail('Operation 2 failed. Check logs for details.');
  }
}

performOperations();

In this example, performOperations() makes use of the @push.rocks/smartlog-source-ora module to provide real-time feedback to the user about the operations being performed. It demonstrates how to indicate the beginning of an operation, success completion, and handling failures, offering a comprehensive user experience.

Conclusion

The integration of @push.rocks/smartlog-source-ora into your application not only improves the visual feedback during operations but also contributes to a better user experience by clearly communicating the state of operations in real time. Whether you're building CLI tools or applications that require status updates, @push.rocks/smartlog-source-ora provides a straightforward and elegant solution.

For any further assistance or more advanced use cases, you may delve into the source code and explore additional features that may suit your specific needs. Happy coding!

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
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.