forked from splintersuidman/nerdbar.widget
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo.coffee
163 lines (139 loc) · 6.1 KB
/
info.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#
# ──────────────────────────────────────────────── II ──────
# :::::: I N F O : : : : : : : :
# ──────────────────────────────────────────────────────────
#
#
# ─── ALL COMMANDS ───────────────────────────────────────────────────────────
#
commands =
battery: "pmset -g batt | egrep '([0-9]+\%).*' -o --colour=auto " +
"| cut -f1 -d';'"
time : "date +\"%H:%M\""
wifi : "/System/Library/PrivateFrameworks/Apple80211.framework/" +
"Versions/Current/Resources/airport -I | " +
"sed -e \"s/^ *SSID: //p\" -e d"
volume : "osascript -e 'output volume of (get volume settings)'"
ext : "curl -s https://i.r4r3.me/ip"
en0 : "ipconfig getifaddr en0"
en1 : "ipconfig getifaddr en1"
#
# ─── COLORS ─────────────────────────────────────────────────────────────────
#
colors =
black: "#3B4252"
red: "#BF616A"
green: "#A3BE8C"
yellow: "#EBCB8B"
blue: "#81A1C1"
magenta: "#B48EAD"
cyan: "#88C0D0"
white: "#D8DEE9"
#
# ─── COMMAND ────────────────────────────────────────────────────────────────
#
command: "echo " +
"$(cat ~/.cache/wal/colors.json):::" +
"$(#{ commands.battery }):::" +
"$(#{ commands.time }):::" +
"$(#{ commands.wifi }):::" +
"$(#{ commands.volume }):::" +
"$(#{ commands.ext }) - $(#{ commands.en0 }) $(#{ commands.en1})"
#
# ─── REFRESH ────────────────────────────────────────────────────────────────
#
refreshFrequency: 2000
#
# ─── RENDER ─────────────────────────────────────────────────────────────────
#
render: ( ) ->
"""
<link rel="stylesheet" href="nerdbar.widget/font-awesome/font-awesome.min.css" />
<div class="ips">
<i class="fa fa-address-card-o"></i>
<spann class="ips-output"></span>
</div>
<div class="wifi">
<i class="fa fa-wifi"></i>
<span class="wifi-output"></span>
</div>
<div class="volume">
<span class="volume-icon"></span>
<span class="volume-output"></span>
</div>
<div class="battery">
<span class="battery-icon"></span>
<span class="battery-output"></span>
</div>
<div class="time">
<i class="fa fa-clock-o"></i>
<span class="time-output"></span>
</div>
"""
#
# ─── RENDER ─────────────────────────────────────────────────────────────────
#
update: ( output ) ->
output = output.split( /:::/g )
wal = JSON.parse output[ 0 ]
battery = output[ 1 ]
time = output[ 2 ]
wifi = output[ 3 ]
volume = output[ 4 ]
ips = output[ 5 ]
$( ".battery-output" ) .text( "#{ battery }" )
$( ".battery" ).css({ color: wal.colors.color5 })
$( ".time-output" ) .text( "#{ time }" )
$( ".time" ).css({ color: wal.colors.color15 })
$( ".wifi-output" ) .text( "#{ wifi }" )
$( ".wifi" ).css({ color: wal.colors.color3 })
$( ".volume-output" ) .text( "#{ volume }%" )
$( ".volume" ).css({ color: wal.colors.color15 })
$( ".ips-output" ).text( "#{ ips }")
$( ".ips" ).css({ color: wal.colors.color3 })
@handleBattery( Number( battery.replace( /%/g, "" ) ) )
@handleVolume( Number( volume ) )
#
# ─── HANDLE BATTERY ─────────────────────────────────────────────────────────
#
handleBattery: ( percentage ) ->
batteryIcon = switch
when percentage <= 12 then "fa-battery-0"
when percentage <= 25 then "fa-battery-1"
when percentage <= 50 then "fa-battery-2"
when percentage <= 75 then "fa-battery-3"
when percentage <= 100 then "fa-battery-4"
$( ".battery-icon" ).html( "<i class=\"fa #{ batteryIcon }\"></i>" )
#
# ─── HANDLE VOLUME ──────────────────────────────────────────────────────────
#
handleVolume: ( volume ) ->
volumeIcon = switch
when volume == 0 then "fa-volume-off"
when volume <= 50 then "fa-volume-down"
when volume <= 100 then "fa-volume-up"
$( ".volume-icon" ).html( "<i class=\"fa #{ volumeIcon }\"></i>" )
#
# ─── STYLE ──────────────────────────────────────────────────────────────────
#
style: """
.battery
color: #{ colors.green }
.time
color: #{ colors.magenta }
.wifi
color: #{ colors.white }
.volume
color: #{ colors.cyan }
display: flex
div
margin-right: 15px
bottom: 2px
right: 0px
font-family: 'SF Compact Text'
font-size: 13px
font-smoothing: antialiasing
z-index: 0
opacity: 1
"""
# ──────────────────────────────────────────────────────────────────────────────