Skip to content

Commit

Permalink
feat: add CPU/MEM high usage warning
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacTay committed Jan 20, 2025
1 parent 56c6d98 commit e2351b3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
bun-version: latest
- run: bun install
- run: bun run build
- run: zip -r text-zebar.zip build/
- run: mv build text-zebar
- run: zip -r text-zebar.zip text-zebar/

- name: Create Release
id: create_release
Expand Down
2 changes: 1 addition & 1 deletion src/components/Group.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Snippet } from 'svelte';
type Props = {
children: Snippet;
group: string;
group: string;
class: string;
};
let { children, group, ...rest }: Props = $props();
Expand Down
29 changes: 21 additions & 8 deletions src/components/RightGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
NetworkOutput,
BatteryOutput,
WeatherOutput,
DateOutput
DateOutput,
CpuOutput,
MemoryOutput
} from 'zebar';
type RightGroupProps = {
Expand All @@ -13,12 +15,14 @@
battery: BatteryOutput;
weather: WeatherOutput;
date: DateOutput;
cpu: CpuOutput;
memory: MemoryOutput;
};
let { glazewm, network, weather, battery, date }: RightGroupProps = $props();
let { glazewm, network, weather, battery, date, cpu, memory }: RightGroupProps = $props();
let battery_symbols = '󰂎󰁺󰁻󰁼󰁽󰁾󰁿󰂀󰂁󰂂󰁹';
let weather_symbols: { [id: string]: string }= {
let weather_symbols: { [id: string]: string } = {
clear: '',
cloudy: '',
light_rain: '󰸊',
Expand All @@ -34,7 +38,15 @@
}
</script>

<div class="flex flex-row items-center gap-3 select-none *:flex *:flex-row *:whitespace-pre *:select-none">
<div
class="flex select-none flex-row items-center gap-3 *:flex *:select-none *:flex-row *:whitespace-pre"
>
{#if cpu && cpu.usage > 90}
<div class="text-zb-cpu-high">CPU</div>
{/if}
{#if memory && memory.usage > 90}
<div class="text-zb-memory-high">MEM</div>
{/if}
{#if network}
<div>
{#if network.defaultInterface?.type === 'ethernet'}
Expand All @@ -57,12 +69,13 @@
{#if battery}
{@const index = Math.round(battery.chargePercent / 10) * 2}
<div>
{#if battery.isCharging}󰚥&nbsp;{/if}{battery_symbols.slice(index, index + 2)} <div class="select-text">{Math.round(battery.chargePercent)}%</div>
{#if battery.isCharging}󰚥&nbsp;{/if}{battery_symbols.slice(index, index + 2)}
<div class="select-text">{Math.round(battery.chargePercent)}%</div>
</div>
{/if}
{#if date}
<div>
󱦟 <div class="select-text">{date?.formatted}</div>
</div>
<div>
󱦟 <div class="select-text">{date?.formatted}</div>
</div>
{/if}
</div>
14 changes: 12 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
DateOutput,
NetworkOutput,
WeatherOutput,
BatteryOutput
BatteryOutput,
CpuOutput,
MemoryOutput
} from 'zebar';
import '../app.css';
Expand All @@ -19,14 +21,18 @@
let battery = $state<BatteryOutput | null>();
let weather = $state<WeatherOutput | null>();
let date = $state<DateOutput | null>();
let cpu = $state<CpuOutput | null>();
let memory = $state<MemoryOutput | null>();
onMount(() => {
const providers = zebar.createProviderGroup({
glazewm: { type: 'glazewm' },
network: { type: 'network' },
weather: { type: 'weather' },
battery: { type: 'battery' },
date: { type: 'date', formatting: 'yyyy.MM.dd EEE HH:mm:ss' }
date: { type: 'date', formatting: 'yyyy.MM.dd EEE HH:mm:ss' },
cpu: { type: 'cpu' },
memory: { type: 'memory' }
});
providers.onOutput(() => {
Expand All @@ -35,6 +41,8 @@
weather = providers.outputMap.weather;
battery = providers.outputMap.battery;
date = providers.outputMap.date;
cpu = providers.outputMap.cpu;
memory = providers.outputMap.memory;
});
});
</script>
Expand All @@ -61,6 +69,8 @@
weather={weather!}
battery={battery!}
date={date!}
cpu={cpu!}
memory={memory!}
/>
</Group>
</div>
24 changes: 6 additions & 18 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ export default {
border: 'hsl(var(--border) / <alpha-value> )',
border_focused: 'hsl(var(--border_focused) / <alpha-value> )',
icon: 'hsl(var(--icon) / <alpha-value> )',
memory: 'hsl(var(--memory) / <alpha-value> )',
cpu: 'hsl(var(--cpu) / <alpha-value> )',
'cpu-high-usage': 'hsl(var(--cpu-high-usage) / <alpha-value> )',
battery: {
good: 'hsl(var(--battery-good) / <alpha-value> )',
mid: 'hsl(var(--battery-mid) / <alpha-value> )',
low: 'hsl(var(--battery-low) / <alpha-value> )'
cpu: {
high: 'hsl(var(--cpu-high-usage) / <alpha-value> )'
},
memory: {
high: 'hsl(var(--memory-high-usage) / <alpha-value> )'
},
'focused-process': 'hsl(var(--focused-process) / <alpha-value> )',
process: 'hsl(var(--process) / <alpha-value> )',
displayed: 'hsl(var(--displayed) / <alpha-value> )',
ws: {
base: 'hsl(var(--ws-base) / <alpha-value>)',
'base-text': 'hsl(var(--ws-base-text) / <alpha-value>)',
Expand All @@ -32,14 +27,7 @@ export default {
'focused-text': 'hsl(var(--ws-focused-text) / <alpha-value>)',
displayed: 'hsl(var(--ws-displayed) / <alpha-value>)',
'displayed-text': 'hsl(var(--ws-displayed-text) / <alpha-value>)'
},
'tiling-direction': 'hsl(var(--tiling-direction) / <alpha-value> )',
spotify: {
playing: 'hsl(var(--now-playing) / <alpha-value> )',
paused: 'hsl(var(--not-playing) / <alpha-value> )'
},
network: 'hsl(var(--network) / <alpha-value> )',
weather: 'hsl(var(--weather) / <alpha-value> )'
}
},
blend: generateBlends()
},
Expand Down

0 comments on commit e2351b3

Please sign in to comment.