Skip to content

Instantly share code, notes, and snippets.

@felixhageloh
Created May 25, 2016 07:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixhageloh/94d5dd41cc5ff8a633900ffb28bd195a to your computer and use it in GitHub Desktop.
Save felixhageloh/94d5dd41cc5ff8a633900ffb28bd195a to your computer and use it in GitHub Desktop.
Example widget using the new JS + virtual DOM syntax
export const refreshFrequency = 1000;
export const command = `ps axro \"%cpu,ucomm,pid\" \
| sed -e 's/^[ \\t]*//g' -e 's/\\([0-9][0-9]*\\.[0-9][0-9]*\\)\\ /\\1\\%\\,/g' -e 's/\\ \\ *\\([0-9][0-9]*$\\)/\\,\\1/g' -e's/\\ \\ */\\_/g' \
| awk 'FNR>1' \
| head -n 3 \
| awk -F',' '{ printf \"%s,%s,%d\\n\", $1, $2, $3}' \
| sed -e 's/\\_/\\ /g'`;
const style = {
top: '10px',
left: '10px',
position: 'absolute',
background: 'rgba(255, 255, 255, 0.2)',
WebkitBackdropFilter: 'blur(20px)'
};
const columnStyle = {
padding: '5px 20px',
fontSize: '18px'
};
export function updateProps(prev, action) {
const rows = action.output.split('\n').map((row) => {
return row.split(',');
});
return rows;
}
export function render(props) {
return <table style={style}>
{props.map((row) =>
<tr>
{row.map((col) => <td style={columnStyle}>{col}</td>)}
</tr>
)}
</table>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment