Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
TwIStOy committed Dec 11, 2023
1 parent 634757a commit b035f8f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/core/format/rendered-node/codeblock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { info } from "@core/utils/logger";
import { debug_, info } from "@core/utils/logger";
import { PangoMarkupGenerator } from ".";
import { isNil } from "@core/vim";
import { escapeMarkup } from "./util";
Expand Down Expand Up @@ -69,7 +69,7 @@ export function highlightContent(
return 1;
});
let m = 0;
info("markers: %s", markers);
debug_("markers: %s", markers);
pango.pushTag("<span><tt>", "</tt></span>");
for (let i = 0; i < content.length; i++) {
while (m < markers.length && markers[m].offset <= i) {
Expand Down
28 changes: 19 additions & 9 deletions src/core/format/rendered-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ export class PangoMarkupGenerator {
currentLineDirty: boolean = false;

newLine() {
info("@@@@ newline: %s, parts: [%s]", this.currentLineDirty, this.currentLine)
if (this.currentLineDirty) {
// close all tags
for (let i = 0; i < this.openTags.length; i++) {
for (let i = this.openTags.length - 1; i >= 0; i--) {
this.currentLine.push(this.openTags[i].close);
}
this.currentParagraph.push({
Expand All @@ -67,7 +68,7 @@ export class PangoMarkupGenerator {
});
this.currentLine = [];
for (let i = 0; i < this.openTags.length; i++) {
this.currentLine.push(`<span ${this.openTags[i]}>`);
this.currentLine.push(this.openTags[i].open);
}
this.currentLineDirty = false;
}
Expand All @@ -86,24 +87,33 @@ export class PangoMarkupGenerator {
}

addSpe() {
this.newParagraph();
this.currentParagraph.push({
kind: "sep",
width: 2,
});
this.newParagraph();
}

appendLine(s: string) {
this.currentLine.push(s);
this.currentLineDirty = true;
if (s.length > 0) {
this.currentLine.push(s);
this.currentLineDirty = true;
}
}

appendStr(s: string) {
let parts = s.split("\n");
for (let i = 0; i < parts.length; i++) {
if (i > 0) {
this.newLine();
if (s.length > 0) {
let parts = s.split("\n");
for (let i = 0; i < parts.length; i++) {
if (i > 0) {
this.newLine();
}
if (parts[i].length > 0) {
this.currentLine.push(parts[i]);
this.currentLineDirty = true;
}
}
this.currentLine.push(parts[i]);
}
}

Expand Down
46 changes: 25 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,28 @@ export function onRightClick(opts: any) {
mountRightClickMenu(buffer, opts);
}

function intoWidget(m: RenderedElement, fg: number): Widget {
function intoWidget(m: RenderedElement, fg: number): Widget[] {
if (m.kind === "line") {
return Markup({
markup: m.markup,
margin: Padding.from({
top: 4,
info("line: %s", vim.inspect(m.markup));
return [
Markup({
markup: m.markup,
margin: Padding.from({
// top: 4,
}),
}),
});
];
} else if (m.kind === "lines") {
return Column({
children: m.lines.map((p) => intoWidget(p, fg)),
});
return m.lines.map((p) => intoWidget(p, fg)).flat();
} else {
return Container({
margin: Padding.vertical(4),
height: m.width,
width: "expand",
color: fg,
});
return [
Container({
margin: Padding.vertical(4),
height: m.width,
width: "expand",
color: fg,
}),
];
}
}

Expand Down Expand Up @@ -91,7 +94,7 @@ export function test() {
// }

let hl_normal = vim.api.nvim_get_hl(0, {
name: "Normal",
name: "NormalFloat",
});
let background = ifNil(hl_normal.get("guibg"), hl_normal.get("bg"));
let foreground = ifNil(hl_normal.get("guifg"), hl_normal.get("fg"));
Expand All @@ -104,10 +107,11 @@ export function test() {
padding: Padding.all(10),
child: Column({
children: [
Spacing(),
...paragraphs.map((m) => {
return intoWidget(m, foreground);
}),
...paragraphs
.map((m) => {
return intoWidget(m, foreground);
})
.flat(),
Spacing(),
],
}),
Expand All @@ -123,7 +127,7 @@ export function test() {
vim.schedule(() => {
KittyBackend.getInstance().deleteAll();
let image = Image.fromBuffer(data);
image.render(100, 100);
image.render(0, 0);
info("=====================================================");
});
return toUtfChars("abcdd我");
Expand Down

0 comments on commit b035f8f

Please sign in to comment.