diff --git a/src/components/cpuBlock.tsx b/src/components/cpuBlock.tsx
index 2831488..45d6e04 100644
--- a/src/components/cpuBlock.tsx
+++ b/src/components/cpuBlock.tsx
@@ -185,26 +185,26 @@ export const CpuBlock: FC = () => {
onChange={onFpplChange}
/>
+
+
+
+
+
+
>
}
-
-
-
-
-
-
);
};
\ No newline at end of file
diff --git a/src/settings/profiles.ts b/src/settings/profiles.ts
index ba14f44..634a0d9 100644
--- a/src/settings/profiles.ts
+++ b/src/settings/profiles.ts
@@ -6,6 +6,7 @@ import { State } from "../utils/state"
import { debounce } from "lodash"
import { BackendUtils } from "../utils/backend"
import { Profile } from "../utils/models"
+import { SpreadSheet, SpreadSheetCell } from "../utils/spreadsheet"
export class Profiles {
@@ -13,18 +14,12 @@ export class Profiles {
const profiles = Settings.getConfigurationStructured()["profiles"]
- let maxNameLen = 0
- let maxProfLen = 0
let profCount = 0;
let sortedAppIds: Array<{ appId: string, name: string }> = []
Object.keys(profiles).forEach((appId) => {
- const len = (profiles[appId].name as String).length + appId.length + 3
- maxNameLen = Math.max(len, maxNameLen)
sortedAppIds.push({ appId, name: profiles[appId].name })
-
Object.keys(profiles[appId]).forEach((pwr) => {
if (pwr != "name") {
- maxProfLen = Math.max(Mode[Number(profiles[appId][pwr].mode)].length, maxProfLen)
profCount++
}
})
@@ -42,36 +37,49 @@ export class Profiles {
return 0;
});
+ Logger.info("")
Logger.info("Loaded profiles " + profCount + " for " + Object.keys(profiles).length + " games: ")
- const header1 = " --------------------------------------------------" + ("".padStart(maxProfLen, "-"));
- const header2 = " | POWER | " + ("MODE".padStart(((maxProfLen + 4) / 2) + (maxProfLen % 2))).padEnd(maxProfLen) + " | SPL | SPPL | FPPL | SMT | BOOST |";
- const separator = "-----------------------------------------------------" + ("".padStart(maxProfLen, "-"))
-
- Logger.info((header1.padStart(header1.length + maxNameLen + 2)))
- Logger.info((header2.padStart(header2.length + maxNameLen + 2)))
+ const headers: Array = []
+ headers.push({ data: "NAME", align: "center" })
+ headers.push({ data: "APPID", align: "center" })
+ headers.push({ data: "POWER", align: "center" })
+ headers.push({ data: "MODE", align: "center" })
+ headers.push({ data: "SPL*", align: "center" })
+ headers.push({ data: "SPPL*", align: "center" })
+ headers.push({ data: "FPPL*", align: "center" })
+ headers.push({ data: "SMT*", align: "center" })
+ headers.push({ data: "BOOST*", align: "center" })
+
+ const body: Array> = []
sortedAppIds.forEach((entry) => {
- Logger.info(separator.padStart(separator.length + maxNameLen, "-"))
let isFirst = true
Object.keys(profiles[entry.appId]).forEach((pwr) => {
if (pwr != "name") {
const profile = profiles[entry.appId][pwr]
- let line = "| "
- line += (isFirst ? ((profiles[entry.appId].name + " (" + entry.appId + ")").padStart(maxNameLen)) : "".padStart(maxNameLen)) + " | ";
- line += pwr.toUpperCase() + " | "
- line += Mode[Number(profile.mode)].padStart(maxProfLen) + " | "
- line += (profile.cpu.tdp.spl as String).padStart(3) + " | "
- line += (profile.cpu.tdp.sppl as String).padStart(3) + " | "
- line += (profile.cpu.tdp.fppl as String).padStart(3) + " | "
- line += (profile.cpu.smt as String).padStart(5) + " | "
- line += (profile.cpu.boost as String).padStart(5) + " | "
- Logger.info(line)
+
+ let line: Array = []
+ line.push({ data: (isFirst ? profiles[entry.appId].name : ""), align: "right", rowspan: !isFirst })
+ line.push({ data: (isFirst ? entry.appId : ""), align: "right", rowspan: !isFirst })
+ line.push({ data: pwr.toUpperCase(), align: "right" })
+ line.push({ data: Mode[Number(profile.mode)], align: "right" })
+ line.push({ data: profile.cpu.tdp.spl, align: "right" })
+ line.push({ data: profile.cpu.tdp.sppl, align: "right" })
+ line.push({ data: profile.cpu.tdp.fppl, align: "right" })
+ line.push({ data: profile.cpu.smt, align: "right" })
+ line.push({ data: profile.cpu.boost, align: "right" })
+
+ body.push(line)
+
isFirst = false
}
})
})
- Logger.info(separator.padStart(separator.length + maxNameLen, "-"))
+ SpreadSheet.printSpreadSheet(headers, body)
+ Logger.info("")
+ Logger.info("* Only is used on CUSTOM mode")
+ Logger.info("")
}
public static getAppId(id: string): string {
diff --git a/src/utils/spreadsheet.ts b/src/utils/spreadsheet.ts
new file mode 100644
index 0000000..558d47e
--- /dev/null
+++ b/src/utils/spreadsheet.ts
@@ -0,0 +1,75 @@
+import { Logger } from "decky-plugin-framework"
+
+export type SpreadSheetAlignment = "left" | "center" | "right"
+
+export interface SpreadSheetCell {
+ data: any
+ align: SpreadSheetAlignment
+ padding?: string
+ rowspan?: boolean
+ colspan?: boolean
+}
+
+export class SpreadSheet {
+ public static printSpreadSheet(headers: Array, body: Array>) {
+ const lengths = SpreadSheet.calcLengths(headers, body)
+ const totalLineLength = lengths.reduce((sum, current) => sum + current + 3, 0) + 1
+ let head = ""
+ let line = ""
+ for (let i = 0; i < headers.length; i++) {
+ if (headers[i].rowspan) {
+ head += "|" + SpreadSheet.padCell("", "left", lengths[i] + 2, " ")
+ } else {
+ head += SpreadSheet.padCell("", "left", lengths[i] + 3, "-")
+ }
+ line += (headers[i].colspan ? " " : "| ") + SpreadSheet.padCell(String(headers[i].data), headers[i].align, lengths[i], headers[i].padding) + " "
+ }
+ Logger.info(head + "-")
+ Logger.info(line + "|")
+ for (let i = 0; i < body.length; i++) {
+ let head = ""
+ let line = ""
+ for (let j = 0; j < body[i].length; j++) {
+ if (body[i][j].rowspan) {
+ head += "|" + SpreadSheet.padCell("", "left", lengths[j] + 2, " ")
+ } else {
+ head += SpreadSheet.padCell("", "left", lengths[j] + 3, "-")
+ }
+ line += (body[i][j].colspan ? " " : "| ") + SpreadSheet.padCell(String(body[i][j].data), body[i][j].align, lengths[j], body[i][j].padding) + " "
+ }
+ Logger.info(head + "-")
+ Logger.info(line + "|")
+ }
+ Logger.info(SpreadSheet.padCell("", "left", totalLineLength, "-"))
+ }
+
+ private static calcLengths(headers: Array, body: Array>) {
+ const lengths: Array = []
+
+ for (let i = 0; i < headers.length; i++) {
+ let maxLength = String(headers[i].data).length
+ for (let j = 0; j < body.length; j++) {
+ maxLength = Math.max(maxLength, String(body[j][i].data).length)
+ }
+ lengths.push(maxLength)
+ }
+
+ return lengths
+ }
+
+ private static padCell(data: string, align: SpreadSheetAlignment, size: number, padding?: string) {
+ if (align == "left") {
+ return data.padEnd(size, padding)
+ }
+
+ if (align == "right") {
+ return data.padStart(size, padding)
+ }
+
+ let leftPad = Math.ceil((size - data.length) / 2)
+ return data.padStart(leftPad + data.length).padEnd(size)
+ }
+}
+
+
+