aviortui/essential/visible/service/helper/status/status.go
2026-08-28 12:59:03 +08:00

114 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
|--------------------------------------------------------------------------
| Description
|--------------------------------------------------------------------------
|
| Name:
| - Status
|
| Purpose:
| - Provide a framework-level CLI status utility that standardizes
| terminal message presentation using semantic labels and visual
| indicators to ensure consistent output across all softwares.
|
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| Instruction
|--------------------------------------------------------------------------
|
| Guideline:
| - Accept a semantic status category and human-readable message.
| - Use INFO, WARNING, SUCCESS, and ERROR as supported status labels.
| - Treat unsupported, empty, or invalid labels as INFO.
| - Emit exactly one standardized terminal message per invocation.
|
| Example:
| - ObrimStatus(
| "INFO",
| "Application started successfully.",
| )
|
| - ObrimStatus(
| "WARNING",
| "Configuration file not found.",
| )
|
| - ObrimStatus(
| "SUCCESS",
| "Installation completed.",
| )
|
| - ObrimStatus(
| "ERROR",
| "Unable to connect to the server.",
| )
|
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| Credit
|--------------------------------------------------------------------------
|
| Contributor:
| - Rajon Ahmed
| - Blockonite
|
|--------------------------------------------------------------------------
*/
package status
import (
"fmt"
"strings"
)
// ObrimStatus emits a standardized terminal message.
func ObrimStatus(label, message string) {
normalizedLabel, normalizedMessage := obrimStatusValidateInput(label, message)
output := obrimStatusBuildOutput(obrimStatusFormatMessage(normalizedLabel, normalizedMessage))
fmt.Print(output)
}
// obrimStatusValidateInput normalizes and validates the status label and message.
func obrimStatusValidateInput(label, message string) (string, string) {
normalizedLabel := strings.ToUpper(strings.TrimSpace(label))
normalizedMessage := strings.TrimSpace(message)
switch normalizedLabel {
case "INFO", "WARNING", "SUCCESS", "ERROR":
default:
normalizedLabel = "INFO"
}
return normalizedLabel, normalizedMessage
}
// obrimStatusFormatMessage formats the status label and message with its visual indicator.
func obrimStatusFormatMessage(label, message string) string {
var indicator string
switch label {
case "WARNING":
indicator = "!"
case "SUCCESS":
indicator = "✓"
case "ERROR":
indicator = "✗"
default:
indicator = ""
}
return fmt.Sprintf("[%s %s] %s\n", indicator, label, message)
}
// obrimStatusBuildOutput builds the final terminal message.
func obrimStatusBuildOutput(message string) string {
return message
}