forked from kkga/nibar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace.jsx
104 lines (84 loc) · 2.02 KB
/
workspace.jsx
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
import styles from './lib/styles/styles.jsx';
const command = 'bash yabar/lib/scripts/get_displays_and_spaces.sh';
const refreshFrequency = false;
const renderClass = `
font-family: ${styles.fontFamily};
font-size: ${styles.fontSize};
background-color: #27313E;
line-height: 20px;
color: #FFF;
right: auto;
bottom: auto;
top: 8px;
left: 25px;
font-weight: bold;
.display-container {
display: flex;
}
ul {
padding: 0;
list-style-type: none;
display: flex;
align-items: center;
margin: 0;
}
ul:not(:first-of-type) {
margin-left: 12px;
padding-left: 12px;
border-left: 1px solid #D8DEE9;
}
li {
padding: 0 3px;
margin: 0 5px;
}
li.visible {
border-top: 2px solid transparent;
border-bottom: 2px solid ${styles.colors.dim};
}
li.focused {
border: 2px solid ${styles.colors.lightgray};
border-radius: 2px;
}
`;
const getClassName = space => {
let className = '';
if (space.visible) className += ' visible';
if (space.focused) className += ' focused';
return className;
};
const generateSpaceList = (displays, spaces) => {
return displays.map((display, i) => {
return (
<ul key={i} className="space-container">
{spaces.map((space, i) => {
if (display.index === space.display) {
return (
<li key={i} className={getClassName(space)}>
{space.index}
</li>
);
}
})}
</ul>
);
});
};
const parseJson = json => {
try {
return JSON.parse(json);
} catch (error) {
return;
}
};
const render = ({ output, error }) => {
if (!output) return;
let data = parseJson(output);
console.log(data);
if (error || !data) {
return <div className="display-container"></div>;
}
const { displays, spaces } = data;
const spaceList = generateSpaceList(displays, spaces);
return <div className="display-container">{spaceList}</div>;
};
export { command, refreshFrequency, renderClass as className, render };