Skip to content

Commit

Permalink
Html content
Browse files Browse the repository at this point in the history
  • Loading branch information
scout119 committed Apr 13, 2018
1 parent e642d4d commit fa0a12d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/beam/beamFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class BeamFile implements beamdasm.IBeamFile {
}

readBeamFile(filePath: string) {

let buffer: Buffer = fs.readFileSync(filePath);

let for1 = buffer.toString('utf8', 0, 4).toLowerCase();
Expand Down
53 changes: 45 additions & 8 deletions src/beam/beamdasmFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,53 @@ export class BeamdasmFormatter implements beamdasm.BeamBytecodeFormatter {
return str;
}

formatatu8(beamFile: beamdasm.IBeamFile): string {
let str = 'Atoms: ';
let offset = str.length;
// formatatu8(beamFile: beamdasm.IBeamFile): string {
// let str = 'Atoms: ';
// let offset = str.length;

// for (let i = 0; i < beamFile.atoms.length; i++) {
// str += (i !== 0) ? ' '.repeat(offset) : '';
// str += `${i}\t${beamFile.atoms[i]}\n`;
// }
// str += '\n';

// return str;
// }

formatatu8(beamFile: beamdasm.IBeamFile):string {
let str = `
<head>
<style>
table, td, th {
border: 1px solid white;
}
table {
margin-left: auto;
margin-right: auto;
border-collapse: collapse;
width: 50%;
}
th {
height: 50px;
}
td {
text-align: center;
}
</style>
</head>
<table style="margin-left:auto;margin-right:auto;width=50%">
<tr><th>Index</th><th>Atom</th></tr>
${this.insertAtoms(beamFile)}
</table>`;

for (let i = 0; i < beamFile.atoms.length; i++) {
str += (i !== 0) ? ' '.repeat(offset) : '';
str += `${i}\t${beamFile.atoms[i]}\n`;
}
str += '\n';
return str;
}

insertAtoms(beamFile: beamdasm.IBeamFile):string {
let str = '';
for(let i = 0; i< beamFile.atoms.length; i++){
str+=`<tr><td>${i}</td><td>${beamFile.atoms[i]}</td></tr>`;
}
return str;
}

Expand Down
2 changes: 1 addition & 1 deletion src/beam/opcodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const opcodes: any = {
2: {
ar: 3,
nm: 'func_info',
doc: '**func_info** *M* *F* *A*\nDefine a function M:F/A'
doc: '**func_info** *Module* *Function* *Arity*\nDefine a function *Module*:*Function*/*Arity*'
},
3: {
ar: 0,
Expand Down
12 changes: 6 additions & 6 deletions src/beam/terms/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@

export default class List {

_elements: any[] = [];
items: any[] = [];

add(obj: any) {
this._elements.push(obj);
this.items.push(obj);
}

toString(): string {
let str = '[';
for (let i = 0; i < this._elements.length; i++) {
for (let i = 0; i < this.items.length; i++) {
str += i !== 0 ? ', ' : '';
str += `${this._elements[i]}`;
str += `${this.items[i]}`;
}
str += ']';
return str;
}

get(index: number): any | undefined {
if (index >= 0 && index < this._elements.length) {
return this._elements[index];
if (index >= 0 && index < this.items.length) {
return this.items[index];
}
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/beam/terms/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
'use strict';

export default class Tuple {
_elements: any[] = [];
items: any[] = [];

add(obj: any) {
this._elements.push(obj);
this.items.push(obj);
}

toString(): string {
let str = '{';
for (let i = 0; i < this._elements.length; i++) {
for (let i = 0; i < this.items.length; i++) {

str += i !== 0 ? ', ' : '';
str += `${this._elements[i]}`;
str += `${this.items[i]}`;
}

str += '}';
Expand Down
1 change: 1 addition & 0 deletions src/beamTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class BeamChunkItem extends vscode.TreeItem {
let sectionDocument = vscode.Uri.file(filePath.replace(".beam", `.beam_${chunk}`));
this.command = {
command: chunk === 'code' ? 'vscode.open' : 'vscode.previewHtml',
//command: 'vscode.open',
arguments: [sectionDocument.with({ scheme: `beam${chunk.toLowerCase()}` })],
title: `View ${chunk}`
};
Expand Down

0 comments on commit fa0a12d

Please sign in to comment.