#!/usr/bin/env python3
"""WizardKit: Hardware Sensors"""
# vim: sts=2 sw=2 ts=2

import platform

import wk


def main() -> None:
  """Show sensor data on screen."""
  sensors = wk.hw.sensors.Sensors()
  if platform.system() == 'Darwin':
    wk.ui.cli.clear_screen()
    while True:
      print('\033[100A', end='')
      sensors.update_sensor_data()
      wk.ui.cli.print_report(sensors.generate_report('Current', 'Max'))
      wk.std.sleep(1)
  elif platform.system() == 'Linux':
    proc = wk.exe.run_program(cmd=['mktemp'])
    sensors.start_background_monitor(
      out_path=proc.stdout.strip(),
      exit_on_thermal_limit=False,
      temp_labels=('Current', 'Max'),
      )
    watch_cmd = [
      'watch',
      '--color',
      '--exec',
      '--no-title',
      '--interval', '1',
      'cat',
      proc.stdout.strip(),
      ]
    wk.exe.run_program(watch_cmd, check=False, pipe=False)

if __name__ == '__main__':
  try:
    main()
  except KeyboardInterrupt:
    pass
  except SystemExit:
    raise
  except: # noqa: E722
    wk.ui.cli.major_exception()
