mirror of
https://github.com/mempool/mempool.git
synced 2025-09-21 17:09:43 +02:00
Improve cropping in asm component
This commit is contained in:
@@ -36,14 +36,35 @@ export class AsmComponent {
|
||||
parseASM(): void {
|
||||
let instructions = this.asm.split('OP_');
|
||||
// trim instructions to a whole number of instructions with at most `crop` characters total
|
||||
if (this.crop) {
|
||||
if (this.crop && this.asm.length > this.crop) {
|
||||
let chars = 0;
|
||||
for (let i = 0; i < instructions.length; i++) {
|
||||
chars += instructions[i].length + 3;
|
||||
if (chars > this.crop) {
|
||||
if (chars + instructions[i].length + 3 > this.crop) {
|
||||
let croppedInstruction = instructions[i];
|
||||
instructions = instructions.slice(0, i);
|
||||
// add cropped instruction
|
||||
let remainingChars = this.crop - chars;
|
||||
let parts = croppedInstruction.split(' ');
|
||||
// only render this instruction if there is space for the instruction name and a few args
|
||||
if (remainingChars > parts[0].length + 10) {
|
||||
remainingChars -= parts[0].length + 1;
|
||||
for (let j = 1; j < parts.length; j++) {
|
||||
const arg = parts[j];
|
||||
if (remainingChars >= arg.length) {
|
||||
remainingChars -= arg.length + 1;
|
||||
} else {
|
||||
// crop this argument
|
||||
parts[j] = arg.slice(0, remainingChars);
|
||||
// and remove all following arguments
|
||||
parts = parts.slice(0, j + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
instructions.push(`${parts.join(' ')}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
chars += instructions[i].length + 3;
|
||||
}
|
||||
}
|
||||
this.instructions = instructions.filter(instruction => instruction.trim() !== '').map(instruction => {
|
||||
|
Reference in New Issue
Block a user