Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- // Filename: batstats.go
- // Version: 1.0.0
- // Author: Jeoi Reqi
- // Tested on [GO v1.22] @ URL: https://go.dev/play/
- // This script retrieves battery information.
- // It presents battery details like status and charge level clearly.
- // Users can quickly gauge battery health and make informed decisions about power usage.
- // Requirements:
- // - No external dependencies required.
- // Usage:
- // - Navigate to the directory containing this script in the terminal.
- // - Run the script using the following command:
- // './batstats'
- // Example Output:
- // --------------------------------------------------
- // :: BATTERY STATS ::
- // --------------------------------------------------
- //
- // Internal Battery: [AP18E8M] Status: OK
- // Battery Status: Connected to AC (2)
- // Charge Remaining: 95%
- //
- // --------------------------------------------------
- func main() {
- // Battery information
- battery := map[string]interface{}{
- "Caption": "Internal Battery",
- "Name": "AP18E8M",
- "Status": "OK",
- "BatteryStatus": 2,
- "EstimatedChargeRemaining": 95,
- }
- // Dictionary to map battery status codes to their descriptions
- batteryStatus := map[int]string{
- 1: "Discharging",
- 2: "Connected to AC",
- 3: "Fully charged",
- 4: "Low",
- 5: "Critical",
- 6: "Charging",
- 7: "Charging/High",
- 8: "Charging/Low",
- 9: "Charging/Critical",
- 10: "Undefined",
- 11: "Partially Charged",
- }
- // Get battery status description based on the status code
- batteryStatusDescription := batteryStatus[battery["BatteryStatus"].(int)]
- // Print battery information header
- fmt.Println(strings.Repeat("-", 50))
- fmt.Println("\t\t:: BATTERY STATS ::")
- fmt.Println(strings.Repeat("-", 50))
- // Print battery information
- fmt.Printf("\n%s: [%s]\tStatus: %s\n", battery["Caption"], battery["Name"], battery["Status"])
- fmt.Printf("Battery Status: %s (%d)\n", batteryStatusDescription, battery["BatteryStatus"])
- fmt.Printf("Charge Remaining: %d%%\n", battery["EstimatedChargeRemaining"])
- fmt.Println(strings.Repeat("-", 50))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement