#!/usr/bin/env python3

import subprocess
from htmlificate import HTML

h = HTML()

h.start_tag('html')
h.start_tag('head')

h.title('BSHS Usage')
h.link(attr={'rel':'stylesheet','href':'/style.css'})

h.end_tag() # head

h.start_tag('body')

h.h1('USAGE')
h.a('Back',attr={'href':'..'})
h.single_tag('br')

version = subprocess.run( # get the current version
	['bshs','--version'],
	capture_output=True,
	text=True
)

usage = subprocess.run( # get the current usage message
	['bshs','--help-all'],
	capture_output=True,
	text=True
)
usage.stdout = usage.stdout.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
h.start_tag('div',attr={'class':'container'})

h.tag_pair('h2','Version')
h.start_tag('div',attr={'class':'text-container'})
h.start_tag('p',attr={'style':'white-space: pre-wrap;'})
h.file.append(
	'<span style="color: #00ff00;">'
	'user@machine'
	'</span>'
	':'
	'<span style="color: #0000ff;">'
	'~ $ '
	'</span>'
	'bshs --version'
)
for line in version.stdout.split('\n'):
	h.file.append(line)
h.end_tag() # p
h.end_tag() # div
h.hr()
h.tag_pair('h2','Usage')
h.start_tag('div',attr={'class':'text-container'})
h.start_tag('p',attr={'style':'white-space: pre-wrap;'})
h.file.append(
	'<span style="color: #00ff00;">'
	'user@machine'
	'</span>'
	':'
	'<span style="color: #0000ff;">'
	'~ $ '
	'</span>'
	'bshs --help-all'
)
for line in usage.stdout.split('\n'):
	h.file.append(line)
h.end_tag() # p
h.end_tag() # div
h.end_tag() # div

h.end_tag() # body
h.end_tag() # html
print(h.get())
