mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
40 lines
823 B
Swift
Executable File
40 lines
823 B
Swift
Executable File
//
|
|
// Extensions.swift
|
|
// Mini Stats
|
|
//
|
|
// Created by Serhiy Mytrovtsiy on 29/05/2019.
|
|
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Cocoa
|
|
|
|
extension Float {
|
|
func roundTo(decimalPlaces: Int) -> String {
|
|
return NSString(format: "%.\(decimalPlaces)f" as NSString, self) as String
|
|
}
|
|
|
|
func usageColor() -> NSColor {
|
|
if !colors.value {
|
|
return NSColor.textColor
|
|
}
|
|
|
|
switch self {
|
|
case 0.6...0.8:
|
|
return NSColor.systemOrange
|
|
case 0.8...1:
|
|
return NSColor.systemRed
|
|
default:
|
|
return NSColor.systemGreen
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum Unit : Float {
|
|
case byte = 1
|
|
case kilobyte = 1024
|
|
case megabyte = 1048576
|
|
case gigabyte = 1073741824
|
|
}
|
|
|