Skip to content

Commit

Permalink
chore: consider only all lines are one height
Browse files Browse the repository at this point in the history
  • Loading branch information
a1mersnow committed Nov 27, 2023
1 parent 3b07ef2 commit 3e42e0b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,22 @@ export function colorizeVersionDiff(from: string, to: string, hightlightRange =

interface SliceRenderLine {
content: string
rows: number
fixed: boolean
}

export function createSliceRender() {
const { columns } = process.stdout
const all: SliceRenderLine[] = []
return {
push(...lines: { content: string; fixed?: boolean }[]) {
for (const line of lines) {
all.push({
...line,
rows: Math.ceil(visualLength(line.content) / columns) || 1,
fixed: line.fixed ?? false,
})
}
},
render(selectedDepIndex: number) {
let { rows: remainHeight } = process.stdout
let { rows: remainHeight, columns: availableWidth } = process.stdout
// spare space for cursor
remainHeight -= 1
let i = 0
Expand All @@ -141,7 +138,7 @@ export function createSliceRender() {
if (curr.fixed) {
/* eslint-disable-next-line no-console */
console.log(curr.content)
remainHeight -= curr.rows
remainHeight -= 1
i++
}
else {
Expand All @@ -155,16 +152,21 @@ export function createSliceRender() {
let depIndex = 0
for (const line of remainLines) {
if (line.content.includes(FIG_CHECK))
depIndex++
depIndex += 1

if (depIndex === selectedDepIndex)
break
else
focusedLineIndex += line.rows
focusedLineIndex += 1
}

let slice: SliceRenderLine[]
if (remainHeight < 1 || remainLines.length === 0 || remainLines.length <= remainHeight) {
if (
remainHeight < 1
|| remainLines.length === 0
|| remainLines.length <= remainHeight
|| all.some(x => Math.ceil(visualLength(x.content) / availableWidth) > 1)
) {
slice = remainLines
}
else {
Expand Down

0 comments on commit 3e42e0b

Please sign in to comment.