aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSan Jacobs2025-12-19 22:10:00 +0100
committerSan Jacobs2025-12-19 22:10:00 +0100
commita1a60d2bafac9ac34e9126a8b48f502c27c3a0c4 (patch)
tree2f856db51d2b5743ec14498eec0e7729a6f4a0c6 /src
parent8a16b93457514da0f55b1fba82be5c9155621f6a (diff)
downloadbetter-report-a1a60d2bafac9ac34e9126a8b48f502c27c3a0c4.tar.gz
better-report-a1a60d2bafac9ac34e9126a8b48f502c27c3a0c4.tar.bz2
better-report-a1a60d2bafac9ac34e9126a8b48f502c27c3a0c4.zip
Major comfy restructure
Diffstat (limited to 'src')
-rw-r--r--src/main.odin110
-rw-r--r--src/parts/end.html1
-rw-r--r--src/parts/footer.html3
-rw-r--r--src/parts/knekt.html (renamed from src/parts/start2.html)94
-rw-r--r--src/parts/start.html96
5 files changed, 189 insertions, 115 deletions
diff --git a/src/main.odin b/src/main.odin
index ec9d70e..e1b72ac 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -15,15 +15,26 @@ TODO: Simplify pre-allocation. Just allocate a bunch. It's probably fine.
TODO: Drag-n-drop window if no files are specified
*/
+when ODIN_OS == .Windows {
+ SEPARATOR :: "\\"
+} else {
+ SEPARATOR :: "/"
+}
+
+VERSION :: "1.6"
+
+KNEKT := false
+
VERBOSE :: false
INCLUDE_DATE :: false // By default I delete the retarded date field that says what day the report was generated.
-PART_ONE :: #load("parts/start.html", string)
-PART_TWO :: #load("parts/start2.html", string)
+PART_START :: #load("parts/start.html", string)
+PART_KNEKT :: #load("parts/knekt.html", string)
PART_END :: #load("parts/end.html", string)
+PART_FOOTER :: #load("parts/footer.html", string)
HEADER_TEMPLATE :: #load("header_template.txt", string)
-HEADER_FIELDS_PATH :: "info.txt"
+HEADER_FIELDS_FILENAME :: "info.txt"
header_fields_file : string
Device :: enum {
@@ -57,7 +68,8 @@ Report :: struct {
tc_column_index : int,
// Meta
- path : string,
+ dir : string,
+ based_on_csv : bool,
}
CSV :: string
@@ -74,20 +86,30 @@ main :: proc() {
input_file_name : string
if len(os.args) < 2 {
fmt.println("No paths submitted.")
- if os.is_file(HEADER_FIELDS_PATH) {
- fmt.printfln("\"%v\" already exists.", HEADER_FIELDS_PATH)
+ if os.is_file(HEADER_FIELDS_FILENAME) {
+ fmt.printfln("\"%v\" already exists.", HEADER_FIELDS_FILENAME)
} else {
- os.write_entire_file(HEADER_FIELDS_PATH, transmute([]u8)HEADER_TEMPLATE)
- fmt.printfln("Created \"%v\".", HEADER_FIELDS_PATH)
+ os.write_entire_file(HEADER_FIELDS_FILENAME, transmute([]u8)HEADER_TEMPLATE)
+ fmt.printfln("Created \"%v\".", HEADER_FIELDS_FILENAME)
}
return
+ } else if len(os.args) > 2 {
+ for arg in os.args[2:] {
+ if arg=="-knekt" {
+ KNEKT = true
+ }
+ }
+ }
+
+ exe_path, _ := os2.get_executable_directory(context.allocator)
+ exe_local_fields_file := fmt.aprint(exe_path, HEADER_FIELDS_FILENAME, sep=SEPARATOR)
+ fmt.println(exe_local_fields_file)
+ if os.is_file(exe_local_fields_file) {
+ header_fields_file = exe_local_fields_file
}
fmt.printf("Input path: {}\n", os.args[1])
input_file_name = os.args[1]
-
-
-
path_info, error := os.stat(input_file_name)
file_count := 1
@@ -95,6 +117,12 @@ main :: proc() {
if error == os.ERROR_NONE {
if(path_info.is_dir) {
+
+ input_local_fields_file := fmt.aprint(path_info.fullpath, HEADER_FIELDS_FILENAME, sep="")
+ if os.is_file(input_local_fields_file) {
+ header_fields_file = input_local_fields_file
+ }
+
fmt.printf("Directory submitted! Walking directory...\n\n")
fmt.printf("📁 {}\n", path_info.name)
try_os2 := walk_directory(path_info.fullpath, &file_count, 1)
@@ -155,6 +183,7 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) {
// Y8P "Y8888888P" "Y888888 Y88P
output : Report = {}
+ output.dir = filepath.dir(paths[0])
wavs : [dynamic]wav.Wav
@@ -201,7 +230,18 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) {
output.info_lines = make([]Info_Line, 64, context.temp_allocator)
- info_txt, info_txt_ok := os.read_entire_file(HEADER_FIELDS_PATH, context.temp_allocator)
+
+
+ // Header fields
+
+ header_file := header_fields_file
+ local_header_file_path := fmt.tprint(output.dir, HEADER_FIELDS_FILENAME, sep=SEPARATOR)
+ if os.is_file(local_header_file_path) {
+ header_file = local_header_file_path
+ }
+
+ info_txt, info_txt_ok := os.read_entire_file(header_file, context.temp_allocator)
+
if info_txt_ok {
it := string(info_txt)
line_index := 0
@@ -391,7 +431,7 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) {
when VERBOSE do fmt.printf("Struct before output:\n%#v\n", output)
- output.path = fmt.tprintf("{}/{}_Knekt_Lydrapport.html", filepath.dir(paths[0]), output.title)
+ output.dir = filepath.dir(paths[0])
return output, true
}
@@ -408,7 +448,7 @@ parse_file :: proc(path : CSV, device : Device = .UNSET) -> (Report, bool) {
return {}, false
}
file_info, _ := os.lstat(path, context.temp_allocator)
-
+ output.based_on_csv = true
lines := strings.split_lines(string(data), allocator=context.temp_allocator)
@@ -900,7 +940,7 @@ parse_file :: proc(path : CSV, device : Device = .UNSET) -> (Report, bool) {
when VERBOSE do fmt.printf("Struct before output:\n%#v\n", output)
- output.path = fmt.tprintf("{}/{}_Knekt_Lydrapport.html", filepath.dir(path), output.title)
+ output.dir = filepath.dir(path)
return output, true
}
@@ -911,11 +951,19 @@ render :: proc(report : Report) {
builder := strings.builder_make(context.temp_allocator)
- strings.write_string(&builder, PART_ONE)
- strings.write_string(&builder, report.title)
- strings.write_string(&builder, " - Lydrapport")
- strings.write_string(&builder, PART_TWO)
+ strings.write_string(&builder, PART_START)
+
+ title := fmt.tprint(report.title, "- Sound Report")
+ logo := ""
+ if KNEKT {
+ title = fmt.tprint(report.title, "- Lydrapport")
+ logo = PART_KNEKT
+ }
+ strings.builder_replace_all(&builder, "¤¤¤TITLE¤¤¤", title)
+ strings.builder_replace_all(&builder, "¤¤¤LOGO¤¤¤", logo)
+ title_section := fmt.tprintf("<h1 class=\"day-title\">{}</h1>", report.title)
+ strings.write_string(&builder, title_section)
for line, l in report.info_lines[:report.info_line_count] {
strings.write_string(&builder, " <p><b>")
@@ -951,10 +999,30 @@ render :: proc(report : Report) {
strings.write_string(&builder, PART_END)
+ footer := PART_FOOTER
+ if KNEKT {
+ footer = ""
+ }
+ strings.builder_replace_all(&builder, "¤¤¤FOOTER¤¤¤", footer)
+
+ strings.builder_replace_all(&builder, "¤¤¤VERSION¤¤¤", VERSION)
+ if report.based_on_csv {
+ strings.builder_replace_all(&builder, "¤¤¤PROCESS¤¤¤", "Converted from CSV")
+ } else {
+ strings.builder_replace_all(&builder, "¤¤¤PROCESS¤¤¤", "Generated")
+ }
+
+ output_path := ""
+ if KNEKT {
+ output_path = fmt.tprintf("{}{}{}_Knekt_Lydrapport.html", report.dir, SEPARATOR, report.title)
+ } else {
+ output_path = fmt.tprintf("{}{}{}_Sound_Report.html", report.dir, SEPARATOR, report.title)
+ }
+
output_text := strings.to_string(builder)
- os.write_entire_file(report.path, transmute([]u8)output_text)
+ os.write_entire_file(output_path, transmute([]u8)output_text)
- fmt.printf("Output: {}\n", report.path)
+ fmt.printf("Output: {}\n", output_path)
}
indent_by :: proc(i : int) {
diff --git a/src/parts/end.html b/src/parts/end.html
index fb5a632..5c2fba1 100644
--- a/src/parts/end.html
+++ b/src/parts/end.html
@@ -1,6 +1,7 @@
</tbody>
</table>
</div>
+¤¤¤FOOTER¤¤¤
</body>
<script type="text/javascript">
diff --git a/src/parts/footer.html b/src/parts/footer.html
new file mode 100644
index 0000000..d725a55
--- /dev/null
+++ b/src/parts/footer.html
@@ -0,0 +1,3 @@
+ <center>
+ <p style="font-size:10px;opacity:70%">¤¤¤PROCESS¤¤¤ with 💜 using <a target="_blank" rel="noopener noreferrer" href="https://sparkburst.net/software/#Report">Report</a> by SJS of <a target="_blank" rel="noopener noreferrer" href="https://knektlyd.no/">Knekt Lyd</a><br>v¤¤¤VERSION¤¤¤</p>
+ </center> \ No newline at end of file
diff --git a/src/parts/start2.html b/src/parts/knekt.html
index 0923a78..565ab1f 100644
--- a/src/parts/start2.html
+++ b/src/parts/knekt.html
@@ -1,94 +1,3 @@
-</title>
-
- <link rel="icon" href="/favicon.ico">
- <link rel="icon" href="/favicon.svg" type="image/svg+xml">
-
-
- <style>
- html {
- color: white;
- background: #141414;
- font-family: sans-serif;
- }
- td {
- padding: 3px 6px;
- background: #181818;
- border-radius: 3px;
- border: #ffffff0d solid 1px;
- }
- th {
- border-radius: 3px;
- padding: 5px 3px;
- cursor: pointer;
- font-weight: bold;
- }
- td.highlight-col,
- tr.highlight-row td {
- background: #202020;
- }
- thead {
- top: 0;
- position: sticky;
- background: #141414;
- outline: #fff1 solid 1px 1px 1px 3px;
- }
- .main-container {
- width: max-content;
- display: block;
- margin: auto;
- }
- .header-tr {
- border-bottom: solid 1px #fff3;
- }
- .current-sort {
- background: #424;
- }
- .prelude {
- background: #ffffff0c;
- padding: 20px;
- margin-bottom: 5px;
- border-radius: 4px;
- display: flex;
- }
- .prelude p {
- margin: 2px 0px;
- }
- .prelude b {
-
- }
- svg {
- filter: invert();
- display: block;
- margin: auto;
- }
- h1 {
- font-size: 16px;
- margin-top: 3px;
- margin-bottom: 10px;
- }
- h6 {
- font-family: monospace;
- font-size: 10px;
- }
- a {
- color: #c0f;
- text-underline: 0px;
- }
- .logo-section {
- width: min-content;
- margin-right: 15px;
- }
- </style>
-
-
-</head>
-
-
-
-<body>
-
- <div class="main-container">
- <div class="prelude">
<div class="logo-section">
<a href="https://knektlyd.no/">
<svg width="110px" viewBox="0 0 123 35" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
@@ -102,6 +11,5 @@
</svg>
</a>
<h1 style="width:max-content;margin:auto;">Lydrapport</h1>
- <h6 style="width:max-content;margin:auto;">Version 1.4</h6>
+ <h6 style="width:max-content;margin:auto;">Versjon ¤¤¤VERSION¤¤¤</h6>
</div>
- <div class="info-section">
diff --git a/src/parts/start.html b/src/parts/start.html
index d374a68..7cd1d00 100644
--- a/src/parts/start.html
+++ b/src/parts/start.html
@@ -6,4 +6,98 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <title> \ No newline at end of file
+ <title>¤¤¤TITLE¤¤¤</title>
+ <style>
+ html {
+ color: white;
+ background: #141414;
+ font-family: sans-serif;
+ }
+ td {
+ padding: 3px 6px;
+ background: #181818;
+ border-radius: 3px;
+ border: #ffffff0d solid 1px;
+ }
+ th {
+ border-radius: 3px;
+ padding: 5px 3px;
+ cursor: pointer;
+ font-weight: bold;
+ }
+ td.highlight-col,
+ tr.highlight-row td {
+ background: #202020;
+ }
+ thead {
+ top: 0;
+ position: sticky;
+ background: #141414;
+ outline: #fff1 solid 1px 1px 1px 3px;
+ }
+ .main-container {
+ width: max-content;
+ display: block;
+ margin: auto;
+ }
+ .header-tr {
+ border-bottom: solid 1px #fff3;
+ }
+ .current-sort {
+ background: #424;
+ }
+ .prelude {
+ background: #ffffff0c;
+ padding: 20px;
+ margin-bottom: 5px;
+ border-radius: 4px;
+ display: flex;
+ }
+ .prelude p {
+ margin: 2px 0px;
+ }
+ .prelude b {
+
+ }
+ .day-title {
+ margin-top:0;
+ font-size: 24px;
+ border-bottom: #fff4 solid 1px;
+ }
+ svg {
+ filter: invert();
+ display: block;
+ margin: auto;
+ }
+ h1 {
+ font-size: 16px;
+ margin-top: 3px;
+ margin-bottom: 10px;
+ }
+ h6 {
+ font-family: monospace;
+ font-size: 10px;
+ }
+ a {
+ color: #c0f;
+ text-underline: 0px;
+ }
+ .info-section {
+ width: 100%;
+ }
+ .logo-section {
+ width: min-content;
+ margin-right: 15px;
+ }
+ </style>
+
+
+</head>
+
+
+
+<body>
+ <div class="main-container">
+ <div class="prelude">
+¤¤¤LOGO¤¤¤
+ <div class="info-section">